Users
Tasks
User management
-
Lock user
usermod -L $USER # --lock passwd -l $USER # --lockUnlock userusermod -U $USER # --unlock passwd -u $USER # --unlock
Groups
- Display groups of effective user
id -Gn getent group | grep $(whoami) -
Commands
chage
- Expire password in 30 days
chage -E $(date -d +30days +%Y-%m-%d) $USER
getent
-
Get entries from the passwd file
getent passwd bobgetent group dba_admins
lastb
- Display failed logins for user
lastb $USER
sudo
-
The /etc/sudoers file (or files placed under /etc/sudoers.d/) contains user specifications that define commands that users may execute.
$USER $HOST = ($RUNAS) $CMD- $USER: usernames, UIDs, group names when prefixed with % i.e. %wheel, or GIDs when prefixed with %#
- $HOST: hostnames, IP addresses, or a CIDR range (i.e. 192.0.2.0/24)
- $RUNAS: optional clause that controls the user or group sudo will run the command as. If a username is specified, sudo will not accept a -g argument when runing sudo.
- $CMD: full path to an executable, or a comma-delimited list of commands.
Any of these elements can be replaced with the keyword ALL.
Ansible service accountansible ALL=(ALL) NOPASSWD: ALLAllow user to run only the mkdir commanduser ALL=/bin/mkdirAllow user to run all commands without authenticatinguser ALL=(ALL) NOPASSWD: ALLChange timeout to 10 minutes
Defaults timestamp_timeout=10Change timeout to 10 minutes only for user
linuxizeDefaults:linuxize timestamp_timeout=10
gpasswd
-
Administer /etc/group and /etc/gshadow
Add user to groupgpasswd -a $USER $GROUPAdd user as admin of groupgpasswd -A $USER $GROUPRemove user from groupgpasswd -d $USER $GROUP
groupadd
groupdel
groupmod
useradd
-
Add user
useradd $USER \ -m \ # Create home directory -d $PATH \ # Specify home directory -s /bin/bash \ # Default shell -c $FULLNAME \ # Note full name in comment -G $GROUP1 $GROUP2 \ # Add groups -u $UID \ # Specify user ID -e $DATE \ # Specify expiration date (YYYY-MM-DD) -r \ # System userUseradd's config is at /etc/default/useradd but it also inherits settings from /etc/login.defs.
Example config# useradd defaults file for ArchLinux # original changes by TomK GROUP=users HOME=/home INACTIVE=-1 EXPIRE= SHELL=/bin/bash SKEL=/etc/skel CREATE_MAIL_SPOOL=noThese settings can be displayed with:
useradd -D
userdel
- Delete an existing user account as well as the user's home directory
userdel -r $USER