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.
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:
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:
or:
See also: What is the difference between adduser and useradd?
To remove/delete
To remove/delete a user, first you can use:
Then you may want to delete the home directory for the deleted user account :
Please use with caution the above command!
To modify
To modify the username of a user:
To change the password for a user:
To change the shell for a user:
To change the details for a user (for example real name):
To add a user to the
sudo
group:or
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:
OR
You can also use awk:awk
The easiest way to get this kind of information is
getent
- see manpage for thegetent
command . While that command gives the same output ascat /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
)To add a user newuser to the system you would type
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
You delete a user (for instance obsolete) with
If you want to delete his home directory/mails as well you type
And
will remove the user and all files owned by this user on the whole system.
You can use
compgen
GNU bash built-in too:Will lists all users.
This should get, under most normal situations, all normal (non-system, not weird, etc) users:
This works by:
/etc/passwd
:
as a delimiterThis is because on many linux systems, usernames above 1000 are reserved for unprivileged (you could say normal) users. Some info on this here:
list of all users who can login (no system users like: bin,deamon,mail,sys, etc.)
add new user
or
delete/remove username
If you want to delete the home directory (default the directory /home/username)
or
If you want to delete all files from the system from this user (not only is the home diretory)
Ok here is a trick that will help you sort this. The terminal has auto completion if you type user and hit Tab key twice it will list all the commands that exist with user as the first 4 chars.
gives me as possible options useradd userdel usermod users users-admin
if you want to know more about a command google it or type man man useradd gives useradd - create a new user or update default new user information ... ...
to list users you should go with what Mitch said.
Hope that helps I love tab completion in bash saves me from remembering things.
To find out the users which have home-directories in the /home-folder on the machine, run the following commands
You can then see the users who have authorization to log into the server. If we want to look into the files of any users, you must be the root user.
The first answer recommends:
But using this and counting number of users you get:
46 users for a laptop computer are a lot!. So use this instead:
To remove guest accounts (who don't have saved files anyway) use:
Some sample users removed from the listing are:
It turns out most of the users on a single user system are actually programs that have set themselves up as users.