Users and permissions
Users, groups, file permissions, ACLs, sudoers, PAM.
Create / modify users
New user with home + bash + wheel group:
sudo useradd -m -G wheel -s /bin/bash newuserSpecific UID and home:
sudo useradd -m -u 1500 -d /home/custom -s /bin/zsh newuserSystem user (no login):
sudo useradd -r -s /usr/bin/nologin serviceuserSet password:
sudo passwd newuserChange own password:
passwdAdd to extra groups (always
-aG):sudo usermod -aG wheel,docker newuserChange shell:
sudo usermod -s /bin/zsh newuserRename:
sudo usermod -l newname oldnameMove home (creates + moves contents):
sudo usermod -d /new/home -m newuserLock / unlock account:
sudo usermod -L newuser/-UDelete (keep home):
sudo userdel newuserDelete + remove home + mail spool:
sudo userdel -r newuser
Warning: Always use
-aG(append) withusermod. Bare-Greplaces all supplementary groups — can lock you out of sudo.
Inspect users
Current user info:
idSpecific user:
id newuserLogged in:
who/wAll users:
getent passwdGroups for user:
groups newuserChange own login shell:
chsh -s /bin/zsh
Password expiry (chage)
Show:
sudo chage -l newuserExpire after 90 days:
sudo chage -M 90 newuserExpire on date:
sudo chage -E 2025-12-31 newuserForce change at next login:
sudo chage -d 0 newuser
Groups
Create:
sudo groupadd developersWith GID:
sudo groupadd -g 2000 developersRemove user from group:
sudo gpasswd -d newuser developersChange primary group:
sudo usermod -g developers newuserDelete:
sudo groupdel developersList members:
getent group wheel
chmod — symbolic
Add execute for owner:
chmod u+x script.shRemove write for group/others:
chmod go-w file.txtSet exactly (owner rw, group r):
chmod u=rw,g=r,o= file.txtEveryone read:
chmod a+r file.txtCapital
X= execute only when already executable / on dirs:chmod -R u=rwX,g=rX,o= /projectSeparate dirs vs files:
find . -type d -exec chmod 755 {} + find . -type f -exec chmod 644 {} +
chmod — octal
| # | bits | Permission |
|---|---|---|
| 0 | --- | none |
| 1 | --x | execute |
| 2 | -w- | write |
| 3 | -wx | write + execute |
| 4 | r-- | read |
| 5 | r-x | read + execute |
| 6 | rw- | read + write |
| 7 | rwx | all |
- Examples:
chmod 755 script.sh chmod 644 file.txt chmod 600 secret.txt chmod 700 dir/ chmod 775 shared_dir/
chmod — special bits
SUID (run as file owner):
chmod u+s /usr/bin/program/chmod 4755 ...SGID (run as group; on dirs, files inherit group):
chmod g+s /shared/dir/chmod 2775 ...Sticky bit (only owner can delete in dir, e.g. /tmp):
chmod +t /tmp/chmod 1777 /tmpFind SUID/SGID files:
find / -perm /4000 -type f 2>/dev/null # SUID find / -perm /2000 -type f 2>/dev/null # SGID
chown
Change owner:
sudo chown newuser file.txtOwner + group:
sudo chown newuser:developers file.txtGroup only:
sudo chown :developers file.txtorchgrp developers file.txtRecursive:
sudo chown -R newuser:developers /projectConditional on current owner:
sudo chown --from=olduser newuser file.txtCopy ownership from another file:
sudo chown --reference=source.txt target.txt
ACLs
ls -l shows + after permissions when ACLs are set.
View:
getfacl file.txtView recursively:
getfacl -R /projectGrant per-user read+write:
setfacl -m u:jo:rw file.txtGrant per-group:
setfacl -m g:developers:rx /projectDefault ACL (inherited by new files in dir):
setfacl -d -m g:developers:rwx /projectRecursive:
setfacl -R -m g:developers:rx /projectRemove entry:
setfacl -x u:jo file.txtRemove all ACLs:
setfacl -b file.txtCopy ACLs:
getfacl source.txt | setfacl --set-file=- target.txt
sudoers
Always edit via visudo (validates before saving).
Edit main:
sudo visudoDrop-in (preferred):
sudo visudo -f /etc/sudoers.d/myuserCommon rules:
jo ALL=(ALL:ALL) ALL # full sudo with password jo ALL=(ALL:ALL) NOPASSWD: ALL # full sudo no password jo ALL=(ALL) /usr/bin/pacman, /usr/bin/systemctl # specific commands only %wheel ALL=(ALL:ALL) ALL # group rule jo ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart nginx jo ALL=(postgres) /usr/bin/psql # run as specific userList allowed:
sudo -lRun as another user:
sudo -u postgres psqlSafer edit (drops privileges after opening):
sudoedit /etc/hosts
PAM
Config in /etc/pam.d/. Common files: system-auth, system-login, su, sudo, sshd.
Require wheel for
su, add to/etc/pam.d/su:auth required pam_wheel.so use_uidFailed login lockout (
/etc/security/faillock.conf):deny = 5 unlock_time = 600Show failed attempts:
faillock --user joReset:
sudo faillock --user jo --resetPassword requirements (
/etc/security/pwquality.conf):minlen = 12 dcredit = -1 ucredit = -1Resource limits (
/etc/security/limits.conf):jo hard nofile 65535 @developers soft nproc 4096
Key files
| File | Purpose |
|---|---|
/etc/passwd | accounts (name, UID, GID, home, shell) |
/etc/shadow | password hashes + expiry |
/etc/group | group definitions |
/etc/gshadow | encrypted group passwords |
/etc/sudoers | sudo rules (edit with visudo) |
/etc/sudoers.d/ | drop-in sudo rules |
/etc/login.defs | default UID ranges, password aging |
/etc/skel/ | skeleton home dir |
/etc/pam.d/ | PAM config |
/etc/security/ | limits, faillock, pwquality |