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
adduseroveruseradd-adduserwill prompt for information such as password, will add to the users group, and create a home directory - but know how to useuseraddin a pinch. - Server Fault - useradd vs adduser
Create new user
adduser bob
cat /etc/passwd | grep bob
cat /etc/shadow | grep bobCreate new group
groupadd bobs
usermod -aG bobs bob
groups bobCreate 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 robertList existing groups on the system
cat /etc/group | less
grep bob /etc/groupDeleting users and groups
userdel bob
userdel robert
groupdel bobsbtw
useradd -m user
passwd user
usermod -aG wheel -s /bin/zsh userChanging 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 bobmoving up and down wrapped lines in vi/vim
EOF