10 classic examples: use useradd to create users on Linux systems

Reference text:
10 classic examples: Linux system useradd creates users

The "useradd" command is used to create new user accounts on Linux or Unix-like systems. It's a command that requires superuser privileges, so you'll need to run it as root or a user with sudo privileges. Following is the basic syntax for creating a new user using the "useradd" command:

useradd [options] username

Here are some common options:

  • -m: Create the user's home directory while creating the user.
  • -d: Specifies the path to the user's home directory.
  • -s: Specifies the user's default login shell.
  • -g: Specifies the initial primary group to which the user belongs.
  • -G: Specifies additional additional groups to which the user belongs.
  • -c: Add a comment or description for the user.

useraddHere are 10 commonly used examples when using commands to create users:

  1. Create a new user named "john":

    useradd john
    
  2. Create a new user and specify a custom user ID (UID):

    useradd -u 1001 john
    
  3. Create a new user and specify a custom primary group ID (GID):

    useradd -g 1001 john
    
  4. Create a new user and specify custom primary and additional groups:

    useradd -g group1 -G group2 john
    
  5. Create a new user and specify a custom login shell:

    useradd -s /bin/bash john
    
  6. Create a new user and create a home directory for it:

    useradd -m john
    
  7. Create a new user without creating a home directory for it:

    useradd -M john
    
  8. Create a new user and set its password (requires interactive password entry):

    useradd -p <encrypted_password> john
    
  9. Create a new user and set its password expiration:

    useradd -e 2023-12-31 john
    
  10. Create a new user and show details on creation:

    useradd -c "John Doe" john
    

Please note that the parameters such as user name, UID, GID, group name, password, and date in the above examples are illustrative, and corresponding changes and adaptations should be made as needed in actual use.

Supongo que te gusta

Origin blog.csdn.net/linux_tcpdump/article/details/131604676
Recomendado
Clasificación