Introduction
When starting with a new Linux server, one of the fundamental tasks you'll need to master is managing users—adding and removing them as necessary. Upon receiving your server, you'll be provided with a "root" user account. While this account grants you full control over the server, it’s recommended to create a new user with root privileges instead. If others will also be accessing the server, you'll need to create additional user accounts for them as well. This guide will walk you through creating a new user, assigning them root privileges, and deleting users.
Adding Users
To create a new user in Ubuntu, use the adduser command, replacing "username" with your desired username:
adduser username
After running this command, Ubuntu will initiate the setup process:
Enter and confirm the password.
Provide the user’s information (optional). You can press Enter to skip and use the default values.
Confirm the information by pressing "y" or Enter when prompted.
Your new user is now set up and ready for use. You can log in using the username and password you just created.
Granting Sudo Privileges
As noted earlier, it's more secure to operate using a user with root privileges rather than the root account itself.
To grant sudo privileges, open the sudoers file with the following command:
/usr/sbin/visudo
Add the new user's name alongside the root permissions under the user privilege specification section to give them sudo access:
Press CTRL + X to exit, then press "y" to save the changes.
Deleting Users
If you have a user account that is no longer needed, it's advisable to remove it. You can delete the account with the following command:
userdel username
To fully remove the user, delete their home directory as well:
rm -rf /home/username
Summary
You should now have a solid understanding of how to add and remove users on your Ubuntu/Debian server. Effective user management allows you to grant specific access to users based on their needs, enhancing the security and efficiency of your server.