Ubuntu allows you to easily manage users, groups and their access permissions. Depending on the application, you may need to add & remove users in Ubuntu, and also change their permissions. In this article, we will look at how to add/delete user in Ubuntu.
How to Add & Remove User in Ubuntu
Here are the steps to add & remove user in Ubuntu.
Ubuntu provides two commands to add users – adduser and useradd. useradd is a low-level utility to add users while adduser is an interactive command to add users in Ubuntu/Debian system. It is recommended to use adduser.
Here is the syntax to use adduser command
$ sudo adduser username
On running the above command, you will see the following output
Adding user `username' ... Adding new group `username' (1001) ... Adding new user `username' (1001) with group `username' ... Creating home directory `/home/username' ... Copying files from `/etc/skel' ...
Also read : Reading & Writing To Same File in Python
adduser command will ask you a set of questions such as password, full name, phone number, etc. Out of these fields, only password is mandatory, others are optional.
Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully Changing the user information for username Enter the new value, or press ENTER for the default Full Name : Room Number : Work Phone : Home Phone : Other : Is the information correct? [Y/n]
After you have entered all the information, enter Y to confirm.
It will create a new folder /home/username for the new user and copy prerequisite files from /etc/skel to this directory. The new user can write, edit, delete files & folders within this directory.
Please note, the new user will not have administrative rights. For that, you will need to add this user to sudo user group, which is the default group for users with sudo privileges.
$ sudo usermod -aG sudo username
Also read : How to Find Largest Files & Directories in Linux
How to Delete User
You can easily delete the above user with two commands – userdel and deluser. deluser is recommended as it is user friendly. Here is the command to delete above user.
$ sudo deluser username
The above command will only delete the user but leave behind the user directories. If you also want to remove the user’s home directory & files then use the –remove-home option.
$ sudo deluser --remove-home username
As you can see, it is very easy to add/remove users in Ubuntu. User management is frequently required while installing applications and tools in Ubuntu. The above commands will help you quickly add/delete users in Debian systems.
Also read : How to Run Linux Commands in Background