The usermod command
modify a user account 7 examples from the lessons of the IVski Linux Playground — try them in the terminal next to them.
Options in the examples
-a, --append- Add the user to the supplementary group(s).
-G, --groups GROUP1[,GROUP2,...[,GROUPN]]]- A list of supplementary groups which the user is also a member of.
-L, --lock- Lock a user's password. This puts a '!' in front of the encrypted password, effectively disabling the password.
-l, --login NEW_LOGIN- The name of the user will be changed from LOGIN to NEW_LOGIN.
-s, --shell SHELL- changes the user's login shell. An empty string for SHELL blanks the field in /etc/passwd and logs the user into the system's default shell.
-U, --unlock- Unlock a user's password. This removes the '!' in front of the encrypted password.
Examples
sudo usermod -aG sudo usernameAdd to sudo group
sudo usermod -s /bin/zsh usernameChange shell
sudo usermod -l newname oldnameRename user
sudo usermod -L usernameLock account
sudo usermod -U usernameUnlock account
usermod -aG developers NAMEInto the group, keeping the others (-a)
sudo usermod -aG sudo anaGrant sudo access