How to create new user from linux terminal
- User
How to create new user from linux terminal
- Assistant
In Linux, you can create a new user from the terminal using the
useraddcommand. You will typically need superuser privileges to do this, so you may need to usesudo. 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 + Ton Ubuntu).Step 2: Use the
useraddCommandTo create a new user, use the following syntax:
sudo useradd -m usernameReplace
usernamewith the desired username for the new user. Here, the-moption 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 usernameYou 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
usermodcommand. For example, to add the user to thesudogroup, 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 usernameIn this command:
-s /bin/bashsets the user’s default shell to bash.-G sudoadds the user to thesudogroup.
Step 5: Verify the User Creation
You can verify that the user has been created by checking the list of users in the
/etc/passwdfile:cat /etc/passwd | grep usernameOr you can check if the home directory has been created:
ls /home/You should see the new user's home directory listed.
Summary
- Open the terminal.
- Create the user with
sudo useradd -m username. - Set a password with
sudo passwd username. - Optionally add the user to groups or set other options.
That's it! You've successfully created a new user from the Linux terminal.
-