Creating a new user in Linux can be done using the useradd or adduser command. Here's how you can do it step-by-step:
1. Using useradd
The useradd command is a low-level utility to add users.
Steps:
1. Open a terminal.
2. Run the following command with root privileges:
3. sudo useradd -m -s /bin/bash username
Replace username with the desired username.
o -m: Creates the user's home directory.
o -s /bin/bash: Sets the default shell to /bin/bash.
4. Set the user's password:
5. sudo passwd username
You'll be prompted to enter and confirm the password.
6. Optional: Add the user to a specific group (e.g., sudo for administrative privileges):
7. sudo usermod -aG groupname username
Replace groupname with the desired group, such as sudo.
2. Using adduser
The adduser command is more interactive and user-friendly, often available on Debian-based systems.
Steps:
1. Open a terminal.
2. Run the following command:
3. sudo adduser username
Replace username with the desired username.
4. Follow the prompts to:
o Set a password.
o Provide optional information (full name, room number, etc.). You can press Enter to skip these fields.
5. Optional: Add the user to a specific group:
6. sudo usermod -aG groupname username
3. Verify the User
You can verify that the user was created by listing all users:
cat /etc/passwd | grep username
Or by checking the home directory:
ls /home
The new user's home directory should appear there.
No comments:
Post a Comment