User Management

Linux provides command-line tools for creating, modifying, and removing user and group accounts.

Creating and Deleting Users

To create a new local user:

useradd bob

One can add options such as -m to create a home directory or -s /bin/bash to set the default shell.

Interactive user creation

When creating the user in person (not from a script) a much better alternative is adduser. This is an interactive script that creates the user and also directly sets a password

Set the password with:

passwd bob

To delete a user:

userdel bob

By default, this keeps the user’s home directory; add -r to remove it.

User Management

See current user:

whoami

See which users are logged in:

who

Display current (or other) user and group identity:

id
id bob

View the last logged in users

last

Group Management

Create a new group:

groupadd -g 1050 developers
Note

-g can also be skipped to use a generated ID

Delete a group:

groupdel developers

Modifying Users

Change password expiration settings:

chage bob

Check which groups a user belongs to:

groups bob

Add a user to a supplementary group:

usermod -aG sudo bob # Attach to group