$ Linux Commands

User Management — Managing users and groups

groups User Management

Show group memberships for a user

groups [USER]
groups
groups alice
last User Management

Show listing of last logged-in users

last [OPTIONS] [USER]
last
last alice
last reboot
-n N show last N entries
passwd User Management

Change a user password

passwd [USERNAME]
passwd
sudo passwd alice

Running passwd without a username changes your own password.

useradd User Management

Create a new user

useradd [OPTIONS] USERNAME
sudo useradd -m -s /bin/bash newuser
sudo useradd -m -G sudo newuser
-m create home directory
-s SHELL set login shell
-G GROUP add to supplementary groups
-d DIR set home directory

After creating a user, set a password with: sudo passwd USERNAME

userdel User Management

Delete a user account

userdel [OPTIONS] USERNAME
sudo userdel alice
sudo userdel -r alice
-r remove home directory and mail spool
usermod User Management

Modify a user account

usermod [OPTIONS] USERNAME
sudo usermod -aG sudo alice
sudo usermod -aG www-data alice
sudo usermod -s /bin/bash alice
-aG GROUP append to group (always use -a with -G)
-s SHELL change login shell
-d DIR change home directory
-l NAME change username

Always use -a with -G to append — without -a it replaces all groups.

w User Management

Show who is logged in and what they are doing

w [USER]
w
w alice

More detailed than who — shows CPU usage and current command.

who User Management

Show who is logged in

who [OPTIONS]
who
who -b
-b show time of last system boot