Linux User Management (Tips & Tricks)

Knowing how to manage users is a vital part of responsible system administration. This article will help you get up to speed on working with users and groups.

Adding & Removing Users

With sufficient privileges, you can add a user to the system. This will also give that user a home directory.

Debian/Ubuntu & Centos/Rhel

adduser alex

Arch

useradd -m alex

To remove a user, use the following commands. Removal of the user’s home directory can either be done manually or with the addition of a command option in most distributions.

Debian/Ubuntu

# Delete user without deleting their home directory.
deluser alex

# Delete a user along with their home directory
deluser --remove-home alex

Centos/Rhel & Arch

# Delete user without deleting their home directory.
userdel alex

# Delete a user along with their home directory
userdel -r alex

Set Passwords

Setting user passwords requires both sufficient privileges and and the previous (if any) password.

Debian/Ubuntu, Centos/Rhel & Arch

passwd alex

Creating and Populating Groups

Creating groups helps organize users by association, function and ownership as well as organization by privilege level.

You can view the groups a user belongs to with the groups command.

groups alex

Create a Group

To create a new group, use the groupadd command

Debian/Ubuntu, Centos/Rhel & Arch

groupadd sudoadmins

Add Users to a Group

Adding users to the group is just as straightforward. Keep in mind here that the group comes after the user in the Arch syntax.

Debian/Ubuntu & Centos/Rhel

usermod -aG sudoadmins alex

Arch

gpasswd -a alex sudoadmins

Remove a Group

Removing a group, like adding, takes another common command.

groupdel sudoadmins