User Management — Managing users and groups
groups
User Management
Show group memberships for a user
Syntax
groups [USER]
Examples
groups groups alice
last
User Management
Show listing of last logged-in users
Syntax
last [OPTIONS] [USER]
Examples
last last alice last reboot
Common Flags
-n N show last N entries
passwd
User Management
Change a user password
Syntax
passwd [USERNAME]
Examples
passwd sudo passwd alice
Notes
Running passwd without a username changes your own password.
useradd
User Management
Create a new user
Syntax
useradd [OPTIONS] USERNAME
Examples
sudo useradd -m -s /bin/bash newuser sudo useradd -m -G sudo newuser
Common Flags
-m create home directory
-s SHELL set login shell
-G GROUP add to supplementary groups
-d DIR set home directory
Notes
After creating a user, set a password with: sudo passwd USERNAME
userdel
User Management
Delete a user account
Syntax
userdel [OPTIONS] USERNAME
Examples
sudo userdel alice sudo userdel -r alice
Common Flags
-r remove home directory and mail spool
usermod
User Management
Modify a user account
Syntax
usermod [OPTIONS] USERNAME
Examples
sudo usermod -aG sudo alice sudo usermod -aG www-data alice sudo usermod -s /bin/bash alice
Common Flags
-aG GROUP append to group (always use -a with -G)
-s SHELL change login shell
-d DIR change home directory
-l NAME change username
Notes
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
Syntax
w [USER]
Examples
w w alice
Notes
More detailed than who — shows CPU usage and current command.
who
User Management
Show who is logged in
Syntax
who [OPTIONS]
Examples
who who -b
Common Flags
-b show time of last system boot