Creating user accounts
Creating a new user account in a Linux operating system involves several steps, including user creation, specifying user details, setting a password, and configuring user permissions.
Note: The following instructions are for systems using the useradd and passwd commands, which are common in many Linux distributions. Some distributions may use different tools or have graphical user interfaces for user management.
-
Open a Terminal:
- To create a new user account, open a terminal on your Linux system. You will need superuser (root) privileges to create a new user.
-
Create the User:
- Use the
useraddcommand to create a new user. Replacenew_usernamewith the desired username.
sudo useradd new_usernameThis command creates a new user account with default settings. The user's home directory will typically be created in
/home/new_username. - Use the
-
Set User Details:
- You can specify additional user details, such as the user's full name and contact information, using the
useraddcommand with the-coption.
sudo useradd -c "Full Name" new_usernameReplace
"Full Name"with the user's actual full name. - You can specify additional user details, such as the user's full name and contact information, using the
-
Set Password:
- To set a password for the new user, use the
passwdcommand.
sudo passwd new_usernameYou will be prompted to enter and confirm the user's password. Make sure to choose a strong password.
- To set a password for the new user, use the
-
Assign User to Groups (Optional):
- By default, a new user is placed in a group with the same name as the username. You can add the user to additional groups using the
usermodcommand.
sudo usermod -aG groupname new_usernameReplace
groupnamewith the name of the group you want to add the user to. - By default, a new user is placed in a group with the same name as the username. You can add the user to additional groups using the
-
Verify User Creation:
- You can use the
idcommand to verify that the user has been created and to check their group memberships.
id new_username - You can use the
-
Set Home Directory Permissions (Optional):
- By default, the user's home directory is created with appropriate permissions. However, if you need to modify permissions or ownership, you can use the
chownandchmodcommands.
sudo chown new_username:new_username /home/new_usernameThis command changes the owner and group of the user's home directory to match the username.
sudo chmod 700 /home/new_usernameThis command sets strict permissions on the user's home directory, allowing only the user to read, write, and execute files within it.
- By default, the user's home directory is created with appropriate permissions. However, if you need to modify permissions or ownership, you can use the
-
Log In as the New User:
- To test the new user account, you can switch to the user's session using the
su(substitute user) command.
su - new_usernameYou will be prompted to enter the user's password.
- To test the new user account, you can switch to the user's session using the
-
(Optional) Grant Administrative Privileges (sudo):
- If you want the new user to have administrative privileges, you can add them to the
sudogroup. This allows the user to execute commands with superuser privileges usingsudo.
sudo usermod -aG sudo new_usernameThis step is optional and should be done with caution. Only grant sudo access to trusted users who need it.
- If you want the new user to have administrative privileges, you can add them to the
-
Logout and Log In:
- After creating the user account and configuring permissions, it's a good practice to log out and log in as the new user to ensure everything is working as expected.