Unix: Managing users and groups

Published:

Just a note to self on how to administer users and groups on Unix systems, and some related tasks.

# Add group (replace 42 with desired GID)
groupadd -g 42 foobar

# Add user
useradd -G foobar -d /path/to/home -m -s /usr/bin/bash alice

# Add user to group
user -G foobar -a alice

# Change user home
usermod -d /path/to/new/home -m alice

# Change default group of user
usermod -g foobar alice

# Change password of user
passwd alice

# Change ownership
chown -R alice:foobar /path/to/target