[Beginners] How To Create, Grant sudo Or Delete Users

LawrenceLawrence Moderator
edited May 12 in Various Tutorials


Introduction

When you first start using a fresh Linux server, adding and removing users is one of the most basic tasks that you should know how to do. When you order the server we provide your with "root" user. Although this gives you the power to make any changes you need on the server, you are much better off creating another new user with root privileges on the virtual private server. Additionally, if other people will be accessing the virtual server, you will need to make new users for them as well. This tutorial will go over 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 the “username” with your preferred username.

adduser username

As soon as you type this command, Ubuntu will automatically start the process:

- Type in and confirm your password.
- Enter in the user’s information. This is not required, pressing enter will automatically fill in the field with the default information.
- Press "y" or Enter when Ubuntu asks you if the information is correct.

Now your new user is set up and ready for use! You can now log in as that user, using the password that you set up.


Granting Sudo Privileges

As mentioned earlier, you are much better off using a user with root privileges.

You can create the sudo user by opening the sudoers file with this command:

/usr/sbin/visudo

Adding the user’s name and the same permissions as root under the the user privilege specification will grant them the sudo privileges.
# User privilege specification
root ALL=(ALL:ALL) ALL
uername ALL=(ALL:ALL) ALL
Press CTRL + x to exit the file and then "y" to save it.


Deleting Users

If you have a user account that you no longer need, it's best to delete the old account. You can delete them with a single command:

userdel username

Finish up by the deleting the user’s home directory:

rm -rf /home/username


Summery

You should now have a good grasp on how to add and remove users from your Ubuntu/Debian server. Effective user management will allow you to separate users and give them only the access that is needed for them to do their job.
Sign In or Register to comment.