Users and GroupsLinux is a multi-user operating system.

This means not only that multiple user ids can be created (common across all mainstream OS’s today), but that they can all access the same Linux machine simultaneously.

You are, of course, limited to roughly 4,294,967,296 user names, but as long as you’re only creating a single user name for 59.65% of the world’s 7.2 billion population, you shouldn’t run into any problems.

User names are unique on each computer and/or service. This explains why you can use whatever user name you want on your own machine, but why you might have trouble even finding an available user name at your chosen email service provider — chances are somebody else already got the one you wanted.

The ability to manage users — even on your personal computer — is useful for many reasons (especially on your personal computer). You can create multiple user ids for yourself, to be able to separate your work life/files/settings from your personal life/files/settings, or have a backup user name available in case a friend or relative needs to use your computer.

Whatever the reason, a good background in user management — from the command line! — is useful to have.

Just to clarify the obvious, your user name is the means that your computer uses to identify you so that it can help you out, but it also determines what you are and are not allowed to do/access/etc.

Groups run hand-in-hand with users and permissions. They help to control who has access to what. Permissions, on the other hand, are a large enough topic to warrant their own discussion at a later date.

So let’s jump right into some of the most common user and group management commands and see what’s what.

User Management

useradd

The useradd command will add a new user to the system. Example: useradd gwen

userdel

The userdel command will delete an existing user from the system. Example: userdel gwen

adduser

This command is a symbolic link to the useradd command.

deluser

This command is a symbolic link to the userdel command.

passwd

The passwd command will assign or change the password of an existing user. Execute the command and user name together and you will be prompted for the password (twice). Example: passwd gwen

usermod

The usermod command will modify an existing user account. There are options such as the ability to lock/unlock an account, change the home directory, etc.

users

The users command will print a list of users currently logged into the system.

Group Management

groups

…prints the groups a user is in.

groupadd

…creates a new group on the system.

groupdel

…removes an existing group from the system.

groupmod

…modifies a group definition on the system.

chgrp

…changes group ownership of files/directories.

newgrp

…logs into a new group.

User Details

whoami

…prints effective userid.

id

…prints real and effective user and group IDs.

w

…shows who is logged on and what they are doing.

who

…displays who is logged onto the system.

last

…shows a listing of last logged in users.

finger

…user information lookup program.

chfn

…change your finger information.

logname

…prints user’s login name.

ac

…prints statistics about users’ connect time.

vipw

…edits the password, group, shadow-password or shadow-group file.

User Interaction

talk

Talks with another logged-in user (if their settings allow it).

write

Sends a message to another user (if their settings allow it).

wall

Sends a message to all other logged-in users (if their settings allow it).

mesg

The mesg command controls whether or not other users can send messages to you. Type in mesg to check if it “is n” (off) or “is y” (on). Type mesg y to turn it on, and mesg n to turn it off.

Switching Users & Super Users

The su command might refer to either “switch user” or “super user”, based on its context. Both terms are applicable, as the command allows you to switch to another user name within the command line, including the super user “root”.

su

Use the su command to switch user names. Examples: su altusername or su - (shorthand for “su root”)

sudo

The sudo “superuser do” command allows commands to be executed as another user, or by default as the super user.

visudo

The visudo command can be used to safely edit the sudoers file and give super user privileges to users other than the root user.

exit

The exit command will log you out of another user name if you had switched to it; otherwise it will exit the terminal.

Conclusion

This is just an overview of the commands available to manage users and groups.

For additional details, always remember to man command.