Adding and deleting ubuntu user accounts is one of the first steps when configuring a new Ubuntu system. Each user may have unique permission levels and settings for command-line and graphical user interface apps.
This article describes how to create and delete Ubuntu user accounts.
Before You Begin
Make sure you’ve installed Ubuntu correctly, follow this guide if you need to do it still!
Only root or users with sudo permissions may create or delete users..
There are two methods to create new users:
- Using the terminal.
- Using the GUI.
Adding a User from the Command Line
You may create a new user account in Ubuntu using one of two command-line tools called useradd or adduser. Both of these tools are available to you.
useradd is a fundamental tool.
adduser is a Perl script that was designed to serve as a user-friendly and interactive interface for the useradd command.
Invoking the adduser command followed by the username is all that is required to create a new user in a flash and with no effort. For instance, if you wanted to establish a new ubuntu user account and give it the name username, you would run:
sudo adduser username
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' ...
There will be a number of questions directed at you. Please enter the new user password and confirm it. It is not required that you provide a response to any of the other questions.
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]
You will be asked to verify the accuracy of the information that you supplied before the process is complete.
The command will establish a home directory for the new ubuntu user and then transfer files from the /etc/skel directory into it. The user has the ability to create, modify, and remove files and folders while working inside their home directory.
You need to add the new user to the sudo group in order for the user to have the ability to carry out administrative responsibilities:
sudo usermod -aG sudo username
Add a User Via the Graphical User Interface (GUI)
You may create a new user account using the GUI if you are uncomfortable working with the command line. To do this, please proceed as outlined below:
- Launch the window that controls the settings, then go to the “Users” tab.
- To unlock your account, click the option labelled “Unlock,” and then enter your user password when required to do so.
- When you have successfully entered the correct password, the “Unlock” button will transform into a green “Add User” button.
- When you choose the “Add User” option from the drop-down menu, the Add user dialogue box will display.
- Enter details about the new user after selecting whether they should be a normal user or an administrative user. After you have finished, click the “Add” button.
Deletion of a User from the Command Line
In Ubuntu, you can use two commands to delete a user account: userdel and its interactive frontend deluser.
To delete the user, invoke the deluser command and pass the username as the argument:
sudo deluser username
The command above will not remove the user files.
If you want to delete the user and its home directory and mail spool, use the --remove-home
flag:
sudo deluser --remove-home username
Removing a User through the GUI
- Open the settings window and click on the “Users” tab.
- Click on the “Unlock” button, and enter your user password when prompted.
- Click on the username you want to delete, and you will see a red “Remove User..” button in the bottom right corner.
- Click the “Remove User..” button, and you will be prompted whether to keep or delete the user home directory. Clicking on one of those buttons removes the user.
Conclusion
Managing user accounts in Ubuntu is a fundamental skill for system administrators and power users alike. Whether you prefer the command-line interface or the graphical user interface, Ubuntu provides straightforward methods for adding and removing user accounts.
By following the steps outlined in this guide, you can efficiently create new user accounts, granting them appropriate permissions and access levels. Remember to use strong passwords and consider adding users to the sudo group only when necessary for administrative tasks.
When it comes to removing user accounts, exercise caution and always double-check before proceeding, especially when deleting home directories. This ensures that important data isn’t accidentally lost during the process.
FAQ
Q: Can I change a user’s password after creating their account?
A: Yes, you can change a user’s password using the passwd command followed by the username. For example: sudo passwd username
Q: How can I view a list of all users on my Ubuntu system?
A: You can view a list of all users by examining the /etc/passwd file. Use the command: cat /etc/passwd
Q: Is it possible to create a user without a home directory?
A: Yes, when using the useradd command, you can add the -M flag to create a user without a home directory. For example: sudo useradd -M username
Q: Can I delete a user account without deleting their home directory?
A: Yes, using the deluser command without the –remove-home flag will delete the user account but leave their home directory intact.
Q: How do I change a user’s default shell?
A: You can change a user’s default shell using the chsh command. For example: sudo chsh -s /bin/bash username
Q: Is it possible to create a user with a specific user ID (UID)?
A: Yes, you can specify a UID when creating a user with the useradd command by using the -u flag. For example: sudo useradd -u 1500 username