Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-mini-2024-07-18· OpenAIAi2 WildChat-4.8M (AI2)

How to create new user from linux terminal

  1. User

    How to create new user from linux terminal

  2. Assistant

    In Linux, you can create a new user from the terminal using the useradd command. You will typically need superuser privileges to do this, so you may need to use sudo. Here’s a step-by-step guide on how to create a new user:

    Step 1: Open the Terminal

    You can open the terminal from your desktop environment or by using a keyboard shortcut (e.g., Ctrl + Alt + T on Ubuntu).

    Step 2: Use the useradd Command

    To create a new user, use the following syntax:

    sudo useradd -m username
    

    Replace username with the desired username for the new user. Here, the -m option tells the system to create a home directory for the new user in /home/username.

    Step 3: Set a Password for the New User

    After creating the user, you’ll need to set a password:

    sudo passwd username
    

    You will be prompted to enter a new password for the user. Type the password and press Enter. You will be asked to confirm the password by typing it again.

    Step 4: Additional Options (Optional)

    • Add the new user to specific groups: You can add the user to specific groups using the usermod command. For example, to add the user to the sudo group, use:

      sudo usermod -aG sudo username
      
    • Set user details: You can add additional options when using useradd, such as specifying a home directory, shell, and user ID. Here’s an example:

      sudo useradd -m -s /bin/bash -G sudo username
      

      In this command:

      • -s /bin/bash sets the user’s default shell to bash.
      • -G sudo adds the user to the sudo group.

    Step 5: Verify the User Creation

    You can verify that the user has been created by checking the list of users in the /etc/passwd file:

    cat /etc/passwd | grep username
    

    Or you can check if the home directory has been created:

    ls /home/
    

    You should see the new user's home directory listed.

    Summary

    1. Open the terminal.
    2. Create the user with sudo useradd -m username.
    3. Set a password with sudo passwd username.
    4. Optionally add the user to groups or set other options.

    That's it! You've successfully created a new user from the Linux terminal.