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

add_remove_users by command-line ubuntu

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.

add_remove_users by command-line ubuntu

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 on 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!

Hi there! I’m Kiran Kumar, founder of FOSSLinux.com. I’m an avid Linux lover, and enjoys hands-on with new promising distros. Currently, I’m using Linux Mint as a daily driver and run several other distros such as Fedora, Solus, Ubuntu, 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 my love for Linux. If you find time, drop me an email or feedback from ‘Contact’ page. Or simply leave a comment below if you found this article useful. Have a good day!

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz