How to add, remove, and rename Users by command-line in Ubuntu, Linux Mint

In this session of our Terminal Tuts series, let’s learn how to add, remove, and modify user accounts from the terminal using commands in Ubuntu, Linux Mint, and derivatives.

View list all the users of your PC

Before heading to add, remove, and modifying the users, let’s first know how to view the list of user accounts in your PC.

System user accounts is stored in the file etc/passwd. We will use cut command in combination with a delimiter and a fetch field function. Launch ‘Terminal’ and run the following command.

cut -d: -f1 /etc/passwd

In the above command, we are using cut to remove a part from each line of the file etc/passwd and using a delimiter d for field. Also the f1 selects the first part from the mentioned file in the path provided. So the actual file content can be seen just by using the following command. You will lot of information. The above command filters only the name which we want.

cat /etc/passwd

cat /etc/passwd Output
cat /etc/passwd Output

Add New User Accounts

To add new user accounts in Ubuntu, you can use adduser or useradd command. Both gives same result. Replace ‘username’ with the name you want in the below command.

sudo adduser username

This will add the new user with all default settings applied. If you want the new user to be a part of a group you can add the group at last. Replace ‘user name’ and ‘usergroup’ with name and group you want respectively. For example:

sudo adduser username usergroup

Remove User Account and Data

To delete a user account in Ubuntu, use the deluser command. Replace ‘username’ with name you user account name you want to delete on your PC.

sudo deluser username

You may want to delete that user’s home directory as well. Use ‘Remove’ (rm) command:

sudo rm -r /home/username

If you want to remove all the files, use this command too:

sudo deluser --remove-all-files username

To Rename a User Account

If you want to modify an existing user account, use the following command format. Replace new_username and old_username accordingly with what you want.

usermod -l new_username old_username

Change Password of an User Account

You can change he password for a user account using passwd command:

sudo passwd username

Hope these commands are useful to you. Good luck!

Kiran Kumar
Hi there! I'm Kiran Kumar, founder of FOSSLinux.com. I'm an avid Linux lover and enjoy hands-on with new promising distros. Currently, I'm using Ubuntu as a daily driver and run several other distros such as Fedora, Solus, Manjaro, Debian, and some new ones on my test PC and virtual machines. I have a day job as an Engineer, and this website is one of my favorite past time activities especially during Winter ;). When I'm not writing for FOSSLinux, I'm seen biking and hiking on scenic trails. Hope you enjoy using this website as much as I do writing for it. Feedback from readers is something that inspires me to do more, and spread Linux love!. If you find a time, drop me an email or feedback from the 'Contact' page. Or simply leave a comment below if you found this article useful. Have a good day!

LEAVE A REPLY

Please enter your comment!
Please enter your name here

STAY CONNECTED

24,261FansLike
192FollowersFollow

LATEST ARTICLES

manjaro complete usb drive
In this tutorial, we will show step by step how to install a Manjaro on a USB flash. For those new to this distro, it is a light-weight distro that is based on Arch Linux. Arch Linux is known for its simplistic approach and is typically made for Linux pros, but Manjaro bridges the gap between user-friendliness and rock-solid performance.
Ubuntu 19.10 beta overview
It may be early, but I've been looking forward to the release of Ubuntu 19.10 for some time now. As an impatient person, and promised readers in the FOSSLinux article announcing the release of Eoan Ermine that we would provide you a review of Ubuntu 19.10 Eoan Ermine - Beta.  So, here it goes.
Test drive linux online
Enter DistroTest.net, a website that allows Linux users to test various distros online, without downloading the ISO or installing the distro. With DistroTest.net, you can check a distro with no muss, no fuss.