← Users & Permissions
Linux · Users & Permissions
How to modify, lock, or delete a user in Linux
Lock, unlock, change the shell of, or delete a user account with usermod and userdel.
Change or remove a user account. Locking is reversible; deleting is not. Run as root.
Locking a user blocks login but keeps the account; userdel -r also removes the home directory and mail and cannot be undone. Prefer locking when in doubt, and check for files the user owns before deleting.
# Lock / unlock login
sudo usermod -L <user>
sudo usermod -U <user>
# Change the login shell (e.g. disable shell access)
sudo usermod -s /sbin/nologin <user>
# Delete the account only (keep the home directory)
sudo userdel <user>
# Delete the account AND its home + mail - irreversible
sudo userdel -r <user>
# Before deleting, find files the user owns
sudo find / -xdev -user <user> 2>/dev/null | headLinuxusermoduserdel