I need a command to list all users as well as commands to add, delete and modify users from terminal – any commands that could help in administrating user accounts easily by terminal.
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 <em>new_username</em>
or:
sudo useradd <em>new_username</em>
See also: What is the difference between adduser and useradd?
To remove/delete
To remove/delete a user, first you can use:
sudo userdel <em>username</em>
Then you may want to delete the home directory for the deleted user account :
sudo rm -r /home/<em>username</em>
Please use with caution the above command!
To modify
To modify the username of a user:
usermod -l <em>new_username</em> <em>old_username</em>
To change the password for a user:
sudo passwd <em>username</em>
To change the shell for a user:
sudo chsh <em>username</em>
To change the details for a user (for example real name):
sudo chfn <em>username</em>
To add a user to the sudo
group:
adduser <em>username</em> sudo
or
usermod -aG sudo <em>username</em>
And, of course, see also: man adduser
, man useradd
, man userdel
… and so on.