Home » Is there a command to list all users? Also to add, delete, modify users, in the terminal?

Is there a command to list all users? Also to add, delete, modify users, in the terminal?

Solutons:


To list

To list all local users you can use:

cut -d: -f1 /etc/passwd

To list all users capable of authenticating (in some way), including non-local, see this reply.

Some more useful user-management commands (also limited to local users):

To add

To add a new user you can use:

sudo adduser new_username

or:

sudo useradd new_username

See also: What is the difference between adduser and useradd?

To remove/delete

To remove/delete a user, first you can use:

sudo userdel username

Then you may want to delete the home directory for the deleted user account :

sudo rm -r /home/username

Please use with caution the above command!

To modify

To modify the username of a user:

usermod -l new_username old_username

To change the password for a user:

sudo passwd username

To change the shell for a user:

sudo chsh username

To change the details for a user (for example real name):

sudo chfn username

To add a user to the sudo group:

adduser username sudo

or

usermod -aG sudo username

And, of course, see also: man adduser, man useradd, man userdel… and so on.

Just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command(s) below:

cat /etc/passwd

OR

less /etc/passwd
more /etc/passwd

You can also use awk:awk

awk -F':' '{ print $1}' /etc/passwd

The easiest way to get this kind of information is getent – see manpage for the getent command Manpage icon. While that command gives the same output as cat /etc/passwd it is useful to remember because it will give you lists of several elements in the OS.

To get a list of all users you type (as users are listed in /etc/passwd)

getent passwd

To add a user newuser to the system you would type

sudo adduser newuser

to create a user that has all default settings applied.

Bonus: To add any user (for instance anyuser) to a group (for instance cdrom) type

sudo adduser anyuser cdrom

You delete a user (for instance obsolete) with

sudo deluser obsolete

If you want to delete his home directory/mails as well you type

sudo deluser --remove-home obsolete

And

sudo deluser --remove-all-files obsolete

will remove the user and all files owned by this user on the whole system.

Related Solutions

Java and switch case

As said here, switch works with the byte, short, char, and int primitive data types. It also works with enumerated types and a few special classes that "wrap" certain primitive types: Character, Byte, Short, and Integer. The Java switch statement is compiled...

How to “force” users to upgrade their browser?

Updated Answer - March 2013 Since this answer was posted on November 2012, Google has discontinued this plugin. While it might still work as of today (March, 2014) there is no guarantee of it working in the future. As of January 2014, support for Chrome Frame...

Splitting credit card number fields into four different inputs

I would generally always opt for the simplest solution. In this case, one single field for the user to type into. With split fields, such as the 4-box one you propose it adds in an extra cognitive load to the user. "Do I need to manually jump to each field?"...

Is coffee a good excuse for a slow application start-up time?

To me, the basic logic is this: It's better to have a fast app than a slow app. While there are many studies that show that faster applications provide better UX, it seems pretty axiomatic to me. I mean, generally in life if we want something done, then we...

Why are terminal consoles still used?

From a UX perspective, terminal consoles have a few key advantages over GUI's. These advantages are rarely relevant to end-users, which is why CLI's are used almost exclusively by technical users and "power users" these days. Things done in a terminal are...

Should you always minimize cognitive load?

No. It is not always appropriate to minimize cognitive load. Minimizing cognitive load is not the goal of usability, human factors, UX, or the user centered design process in general. It is about "good design", and good design is not always the simple design....

How do you give your user options without overloading them?

While Charles's Answer shows some great UIs, I wanted to add the UX that Directory Opus uses for the same action, which I find very good as well. Simple on the surface with advanced options tucked away after a click. . Clicking on the Dropdowns results in these...

Why is it important to focus on user needs as opposed to requests?

Users are bad at asking for what they need and great at asking for what they want. Anecdotal evidence from my own recent experience: We have a department that asked for a button that would generate a PDF report about some data. A few months later they asked for...

Is Markdown Friendly Enough for Non-Technical Users?

I know I'm coming to this thread rather late, but I actually have run usability tests comparing a WYSIWYG editor (iWeb) to a non-WYSIWYG editor based mostly on markdown. Here's what I've found that users struggle with when using markdown: Tags that require...

Why do numpads on keyboards and phones have reversed layouts?

There's this humongous article called Keyboard Trivia that has collected many of the theories and stories. The summary of facts: Touch-tone key pad was designed to mimic the rotary dial with the "1" on top and the 7-8-9 on the bottom, and AT&T conducted...

Why are radio buttons circles?

Square was easy The earliest appearance of circular radio buttons that I can find is in Apple Macintosh System 4 (1987). Prior to that Mac OS used squares with beveled corners, which was probably just computationally easier to draw and better-looking on...

Why might right aligned field labels be better?

Luke Wroblewski wrote about this in Top, Right or Left Aligned Form Labels (April, 2007). In it, he references eyetracking data from an article by Matteo Penzo called Label Placement in Forms (July, 2006). Matteo drew several conclusions from this study,...

Which way should be “on” for a switch?

It appears to be dependent on country or region, as Wikpedia states in the article Light Switch: Up or down The direction which represents "on" also varies by country. In the USA and Canada and Mexico and the rest of North America, it is usual for the "on"...

Who needs an external on/off Wi-Fi button?

Security A hardware radio switch has security benefits to it in that when it is off, you know for a fact that nothing is connected to your laptop wirelessly. The radio switch usually turns off all wireless communication, including Bluetooth and 3G. I have heard...

How big a deal is blocking copy-pasting on a website?

Ask your client what he's actually trying to accomplish. Copy-paste restrictions are about as effective as a toddler gate preventing access to an unmonitored garden in a remote area. Perhaps you could ask the client where he saw copy-paste restrictions being...

What’s the point of a delayed popup on a webpage?

It is about increasing the chance of the user having a look at the popup. Task-completion mode Users in task-completion mode are eager to fulfil their goal (eg, "Is the product/information/answer I'm after on this page?"). As such, they simply ignore anything...