Human users have UIDs starting at 1000, so you can use that fact to filter out the non-humans:
cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1
This cuts the first (username) and third (UID) colon-delimited fields from /etc/passwd
, then filters for the resulting lines which end with a colon and four digits, then cuts the first (username) field from that, leaving you with a list of users with UIDs between 1000 and 9999.
If you have more than nine thousand users on your system, this will fail - but it's necessary to restrict the result to 4-digit UIDs in order not to catch nobody
(UID 65534).
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.
Best Answer
List all users with a
/home
folder:or all users with a
UID >= 1000
:a combination
or for all entries
More information here