Introduction
When you first start using a fresh Linux server, knowing how to add and remove users is essential. Initially, you'll have access to the server with the "root" user, which has full privileges. However, for better security and management, it's advisable to create a new user with root privileges. Additionally, if others will be accessing the server, you will need to create users for them as well. This tutorial covers creating a new user, granting them root privileges, and deleting users.
Adding Users
To add a new user in Ubuntu, use the adduser
command, replacing "username" with your preferred username:
adduser username
When you run this command, Ubuntu will guide you through the process:
- Type in and confirm your password.
- Enter the user’s information (optional). Pressing Enter will automatically fill in the field with default information.
- Press "y" or Enter when prompted to confirm the information.
Your new user is now set up and ready for use! You can log in as this user using the password you set up.
Granting Sudo Privileges
Using a user with root privileges is more secure than using the root user directly. To grant sudo privileges to a user, edit the sudoers file:
/usr/sbin/visudo
Add the user's name with the same permissions as root under the user privilege specification:
#User privilege specification
root ALL=(ALL:ALL) ALL
username ALL=(ALL:ALL) ALL
Press CTRL + X
to exit the file, then press Y
to save the changes.
Deleting Users
If you no longer need a user account, you can delete it with a single command:
userdel username
To remove the user’s home directory as well, use:
rm -rf /home/username
Summary
You should now have a good understanding of how to add, grant sudo privileges, and remove users from your Ubuntu/Debian server. Effective user management allows you to separate users and provide them only the access needed for their tasks.