In part 1 of this little series we did some updating via CLI. Now, we will once again take a look at how to manage things via the terminal; like how to create and delete users, as well as set/change user passwords.
With that said, I'm focusing this article on users who are running a distribution that is based on Debian, such as Ubuntu, Linux Mint (Based on Ubuntu, but still applicable), etc. The reason for this, is that most users who are brand new to the GNU/Linux world will likely be running one of these systems.
Generally speaking, most people I know tend to only have one user on their computer, and if the computer is shared, people just don't save anything sensitive. However, having multiple users is handy for organization and privacy (kids accounts, business account / home account, etc.)
It's rather easy with most modern distros to add a new user via graphical tools; but I'd say it takes longer to do it that way than with the command line. One command, enter the password, enter the password again, bam, done.
If you’re running a distribution based off Debian (Ubuntu/Mint etc) you’re in luck when it comes to user management. Thankfully, there are two scripts that make this task exceptionally quick and painless, and require little more know-how than how to use sudo.
sudo adduser USERNAME
This command is basically a one-and-done command for adding someone new to your GNU/Linux system, creating the user, their home directory tree (/home/mike/Documents/ etc), as well as a new system group, and password. Running the script in this basic way, will also ask for a bunch of other info such as full name etc, you can just leave it all blank if you so choose.
However, there is an option that is poorly explained in the man page for adduser, that allows us to skip all of the information like address, phone number etc. Personally, I recommend leaving 'Full name' out of the line below, because some login screens show the users full name, and if no information is given it can show 'Full Name' instead of the name. Even if you don't want to put your own name in, I highly recommend using the name of your favourite TV / Movie character. However, the command to remove all the extra questions, save password, is:
sudo adduser --gecos "Full name,Room number,Work phone,Home phone" USERNAME
Deleting a user is just as simple,
sudo deluser USERNAME
However, doing this does not actually delete the files left behind by that user. The man pages, say,
"By default, deluser will remove the user without removing the home directory, the mail spool or any other files on the system owned by the user. Removing the home directory and mail spool can be achieved using the --remove-home option.
The --remove-all-files option removes all files on the system owned by the user. Note that if you activate both options --remove-home will have no effect because all files including the home directory and mail spool are already covered by the --remove-all-files option."
So, with that said, if you want to actually clear off the user and the things left behind, you'll need to change your options used slightly to whichever end you desire.
It's rather nice, the inclusion of adduser into Debian based systems, as it really simplifies the process. Granted, using useradd, the command used on most other systems, isn't complicated by any stretch of the imagination, but at least new users can dip their feet into the command line a little more with the ease of scripts like adduser.
Now you: Do you use adduser, or do you prefer useradd? Does the idea of adding new users to your computer from the command line sound quick and easy compared to a GUI, or daunting? Let me know in the comments!
Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.
We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.
If you like our content, and would like to help, please consider making a contribution:
Ghacks is a technology news blog that was founded in 2005 by Martin Brinkmann. It has since then become one of the most popular tech news sites on the Internet with five authors and regular contributions from freelance writers.