• About Us
  • Privacy & Policy
HowTo's
  • Home
  • Commands
  • Linux
  • SCM
  • Git
  • Database
  • MySQL
  • Kubernetes
  • Docker
No Result
View All Result
  • Home
  • Commands
  • Linux
  • SCM
  • Git
  • Database
  • MySQL
  • Kubernetes
  • Docker
No Result
View All Result
HowTo's
No Result
View All Result
Home Commands

Creating System Accounts with Useradd Command

June 21, 2024
in Commands, Linux, Linux Command Tutorial, Linux Commands
A A
0
11
SHARES
102
VIEWS
Share on FacebookShare on Twitter

The useradd command in Unix-like operating systems is used to create new user accounts. When used with the -r or --system option, it specifically creates system accounts which are intended for services or daemons rather than regular users.

Here are several examples demonstrating the usage of useradd with the -r option:

Example 1: Creating a system account for a web server:

    $ sudo useradd -r nginx
    

This command creates a system account named nginx. To verify its creation, you can check the existence of nginx in the /etc/passwd file.

Example 2: Creating a system account with a specific UID and GID:

    $ sudo useradd -r -u 1001 -g 1001 myservice
    

Here, -u 1001 specifies the UID (User ID) and -g 1001 specifies the GID (Group ID) for the system account myservice.

Example 3: Creating a system account with a custom home directory:

    $ sudo useradd -r -d /var/lib/myapp -s /sbin/nologin myappuser
    

This command creates a system account myappuser with a home directory /var/lib/myapp and a login shell set to /sbin/nologin, which restricts interactive logins.

Example 4: Creating a system account with an expired password:

    $ sudo useradd -r -e 2024-12-31 mydaemon
    

The -e 2024-12-31 option sets an expiration date for the account mydaemon. To verify, check the account details in /etc/shadow.

Example 5: Creating a system account with a comment:

    $ sudo useradd -r -c "Backup Service Account" backup
    

This command creates a system account backup with the comment “Backup Service Account”, visible in the /etc/passwd file.

Example 6: Creating a system account with a specific login shell:

    $ sudo useradd -r -s /bin/false daemonuser
    

The -s /bin/false option sets /bin/false as the login shell for the system account daemonuser, preventing interactive login.

Example 7: Creating a system account without creating a home directory:

    $ sudo useradd -r -M sysuser
    

The -M option ensures that no home directory is created for the system account sysuser.

Example 8: Creating a system account with a specific expiration warning period:

    $ sudo useradd -r -f 30 -e 2025-06-30 serviceuser
    

This command creates a system account serviceuser with an expiration warning 30 days before the password expires (-f 30), expiring on June 30, 2025.

Example 9: Creating a system account with a specific default group:

    $ sudo useradd -r -g mygroup serviceaccount
    

The -g mygroup option assigns mygroup as the primary group for the system account serviceaccount.

Example 10: Creating a system account with additional supplementary groups:

    $ sudo useradd -r -G group1,group2,group3 adminuser
    

The -G option adds group1, group2, and group3 as supplementary groups for the system account adminuser.

To verify whether a system account has been successfully created, check the /etc/passwd file for the username entry. Additionally, inspect /etc/shadow for account-specific settings like expiration dates or password statuses if applicable.

Tags: CommandsLinuxLinux Command TutorialLinux Commands
Previous Post

Setting Passwords for User Accounts in Linux

Next Post

Using Chroot Directories with Useradd Command

Related You may like!

howto

How to Use -iname for Case-Insensitive Filename Searches in find

August 21, 2024
howto

Search for Files with Case-Insensitive Pattern Matching Using -ilname in find

August 21, 2024

Find Files by Group Name with -group in find Command

August 21, 2024

Locate Files by Group ID Using -gid in find Command

August 21, 2024

How to Search for Filesystems with -fstype in find Command

August 21, 2024

Use -false to Test Conditional Expressions in find Command

August 21, 2024
Next Post
howto

Using Chroot Directories with Useradd Command

howto

Setting Prefix Directories for Useradd Command

howto

Specifying Login Shells for User Accounts Command

Discussion about this post

Latest Updated

howto

How to Use -iname for Case-Insensitive Filename Searches in find

August 21, 2024
howto

Search for Files with Case-Insensitive Pattern Matching Using -ilname in find

August 21, 2024
howto

Find Files by Group Name with -group in find Command

August 21, 2024
howto

Locate Files by Group ID Using -gid in find Command

August 21, 2024
howto

How to Search for Filesystems with -fstype in find Command

August 21, 2024

Trending in Week

  • howto

    Using BTRFS Subvolume for User Home Directory in Linux

    22 shares
    Share 9 Tweet 6
  • Downloading Docker Images from a Registry

    13 shares
    Share 5 Tweet 3
  • Configuring SSL Connection Mode in mysqldump

    17 shares
    Share 7 Tweet 4
  • Omit Tablespace Information in mysqldump Output

    13 shares
    Share 5 Tweet 3
  • Setting MySQL Dump Compatibility Mode

    18 shares
    Share 7 Tweet 5
  • Setting Network Buffer Length in mysqldump

    13 shares
    Share 5 Tweet 3
  • Logging out from Docker Registries

    13 shares
    Share 5 Tweet 3
  • Scheduling Nodes in Kubernetes with kubectl uncordon

    12 shares
    Share 5 Tweet 3
  • Managing Default User Creation Settings in Linux

    15 shares
    Share 6 Tweet 4
  • Using Extended INSERT Syntax in mysqldump

    12 shares
    Share 5 Tweet 3
  • About Us
  • Privacy & Policy

© 2024 All Rights Reserved. Howto.swebtools.com.

No Result
View All Result

© 2024 All Rights Reserved. Howto.swebtools.com.