Thursday, August 18, 2016

How to show list of user on Ubuntu

After creating new user, you might want to show list of user on ubuntu, to confirm the new user is really exist (although this is not necessary). Or perhaps you just want to take a look at list of user on your machine.

Unfortunately, on ubuntu there is no command dedicated for showing list of users, but there is other command that can be use to show list of users on ubuntu.

The trick is by showing the content of /etc/passwd file, with this file we can get list of user on ubuntu, simply run it with cat to show the output.
cat /etc/passwd
The result of command above is quite informative, but still little bit hard to read especially for beginner like myself. We need a better command, like this:

cut -d: -f1 /etc/passwd
awk -F':' '{ print $1}' /etc/passwd
Noticed that it will display all kind of users on your computer, including users that actually system user or user that can't login, to show only users that can login, you can use this command:

sudo awk -F':' '$2 ~ "\$" {print $1}' /etc/shadow
or this:
awk -F'[/:]' '{if ($3 >= 1000 && $3 != 65534) print $1}' /etc/passwd

No comments:

Post a Comment