Source

tl;dr

For when I inevitably forget this because I’m only ever on a single-user system.
The following nested find command searches all /bin directories within 3 levels from the root for commands containing group or user.
(This was probably way simpler to do by correctly using apropos or man -k or just looking through the linked manpages, but hey, I’m on a find kick.)

find / -maxdepth 3 -type d -name *bin -exec find {} -name *group* -o -name *user* \;
  • Prefer adduser over useradd - adduser will prompt for information such as password, will add to the users group, and create a home directory - but know how to use useradd in a pinch.
  • Server Fault - useradd vs adduser

Create new user

adduser bob
cat /etc/passwd | grep bob
cat /etc/shadow | grep bob

Create new group

groupadd bobs
usermod -aG bobs bob
groups bob

Create a new user with useradd

# by default only a single user group is created, no home directory added
useradd robert
usermod -aG bobs robert
mkdir /home/robert
chown robert:robert /home/robert
 
su robert
echo $HOME # returns /home/robert
 
# or you could just not be a dunce and remember the -m option
# ...to automatically create home directory
useradd -m robert

List existing groups on the system

cat /etc/group | less
grep bob /etc/group

Deleting users and groups

userdel bob
userdel robert
groupdel bobs

btw

useradd -m user
passwd user
usermod -aG wheel -s /bin/zsh user

Changing to root user

An interesting tidbit: my default of sudo su preserves the working directory, while sudo -i takes you to the root user’s home directory of /root.

nologin

# list any users who have login enabled
cat /etc/password | grep -v nologin
 
# change user's shell to nologin
usermod -s /usr/sbin/nologin bob

moving up and down wrapped lines in vi/vim

EOF