Tutorial

How To Add and Delete Users on an Ubuntu 14.04 VPS

How To Add and Delete Users on an Ubuntu 14.04 VPS

Introduction

One of the most basic tasks to that you should know how to do on a fresh Linux server is add and remove users. When you create a new server, you are only given the root account by default.

While this gives you a lot of power and flexibility, it is also dangerous and can be destructive. It is almost always a better idea to add an additional, unprivileged user to do common tasks. You also should create additional accounts for any other users you may have on your system. Each user should have a different account.

You can still acquire administrator privileges when you need them through a mechanism called sudo. In this guide we will cover how to create user accounts, assign sudo privileges, and delete users.

How To Add a User

If you are signed in as the root user, you can create a new user at any time by typing:

  1. adduser newuser

If you are signed in as a non-root user who has been given sudo privileges, as demonstrated in the initial server setup guide, you can add a new user by typing:

  1. sudo adduser newuser

Either way, you will be asked a series of questions. The procedure will be:

  • Assign and confirm a password for the new user
  • Enter any additional information about the new user. This is entirely optional and can be skipped by hitting “ENTER” if you don’t wish to utilize these fields.
  • Finally, you’ll be asked to confirm that the information you provided was correct. Type “Y” to continue.

Your new user is now ready for use! You can now log in using the password you set up.

Note: Continue on if you need your new user to have access to administrative functionality.

How To Grant a User Sudo Privileges

If your new user should have the ability to execute commands with root (administrative) privileges, you will need to give the new user access to sudo.

We can do this by using the visudo command, which opens the appropriate configuration file in your editor. This is the safest way to make these changes.

If you are currently signed in as the root user, type:

visudo

If you are signed in using a non-root user with sudo privileges, type:

sudo visudo

Search for the line that looks like this:

root    ALL=(ALL:ALL) ALL

Below this line, copy the format you see here, changing only the word “root” to reference the new user that you would like to give sudo privileges to:

  1. root ALL=(ALL:ALL) ALL
  2. newuser ALL=(ALL:ALL) ALL

You should add a new line like this for each user that should be given full sudo privileges. When you are finished, you can save and close the file by hitting CTRL-X, followed by “Y”, and then hit “ENTER” to confirm.

Now, your new user is able to execute commands with administrative privileges.

When signed in as the new user, you can execute commands as your regular user by typing commands as normal:

  1. some_command

You can execute the same command with administrative privileges by typing sudo ahead of the command:

sudo some_command

You will be prompted to enter the password of the regular user account you are signed in as.

How To Delete a User

In the event that you no longer need a user, it is best to delete the old account.

You can delete the user itself, without deleting any of his or her files by typing this as root:

  1. deluser newuser

If you are signed in as another non-root user with sudo privileges, you could instead type:

  1. sudo deluser newuser

If, instead, you want to delete the user’s home directory when the user is deleted, you can issue the following command as root:

  1. deluser --remove-home newuser

If you’re running this as a non-root user with sudo privileges, you would instead type:

  1. sudo deluser --remove-home newuser

If you had previously configured sudo privileges for the user you deleted, you may want to remove the relevant line again by typing:

  1. visudo

Or use this if you are a non-root user with sudo privileges:

  1. sudo visudo
root    ALL=(ALL:ALL) ALL
newuser ALL=(ALL:ALL) ALL   # DELETE THIS LINE

This will prevent a new user created with the same name from being accidentally given sudo privileges.

Conclusion

You should now have a fairly good handle on how to add and remove users from your Ubuntu 14.04 system. Effective user management will allow you to separate users and give them only the access that they are required to do their job.

For more information about how to configure sudo, check out our guide on how to edit the sudoers file here.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
6 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

You could save some steps by adding the new user to the sudo group after you create them. When you delete the user, it will automatically remove them from the group:

adduser username sudo

I am not sure this is the best way to give somebody sudo priviledge on Ubuntu.

I prefer add user to “sudo” group by:

usermod -a -G sudo {{username}} 

Default Ubuntu configs says everyone in group “sudo” have “sudo” rights.

i made this like this

(Adding a user and creating the group)
groupadd people
useradd -G people someguy

(Removing all the files including programs, users and groups)
rm -rf /Tests
rm -rf /Storage/Tests
rm -rf /example
userdel someguy
groupdel people
apt-get purge programs dat you will uninstall -y


the best tutorial for linux user management on the web!!

Is it normal that after doing all of this when I run “sudo nano” I get prompted for that user password? is there a way to disable that behavior?

Thanks.

When adding a new user, how can I apply/copy the existing .rvmrc, .zshrc and other configuration of root?

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.