Modifying accounts
Modifying user accounts in a Linux system often requires the use of various commands and utilities.
1. Changing User Password:
-
To change a user's password, use the
passwdcommand followed by the username:sudo passwd username -
Replace
usernamewith the name of the user whose password you want to change. You'll be prompted to enter and confirm the new password.
2. Modifying User Account Details:
-
To modify user account details such as the full name or contact information, you can use the
usermodcommand with appropriate options. For example, to change a user's full name:sudo usermod -c "New Full Name" usernameReplace
"New Full Name"with the updated full name andusernamewith the user's name.
3. Changing User Shell:
-
To change a user's default shell, use the
chshcommand:sudo chsh -s /path/to/newshell usernameReplace
/path/to/newshellwith the path to the desired shell (e.g.,/bin/bash,/bin/zsh) andusernamewith the user's name.
4. Adding Users to Groups:
-
To add a user to one or more groups, you can use the
usermodcommand with the-aGoption:sudo usermod -aG group1,group2 usernameReplace
group1andgroup2with the names of the groups you want to add the user to, separated by commas.
5. Modifying Home Directory:
-
To change a user's home directory, it's recommended to create a new user account with the desired settings, including the home directory path. However, if you need to move an existing user's home directory, use the
usermodcommand with the-moption:sudo usermod -m -d /new/home/directory usernameReplace
/new/home/directorywith the new path to the home directory andusernamewith the user's name.
6. Locking and Unlocking User Accounts:
-
You can lock a user account to prevent login using the
passwdcommand:sudo passwd -l username -
To unlock a locked account, use the
-uoption:sudo passwd -u username
7. Expire or Disable User Accounts:
-
To expire or disable a user account, use the
chagecommand:-
To set an expiration date for an account:
sudo chage -E YYYY-MM-DD username -
To disable an account (no login allowed):
sudo chage -E -1 username
-
8. Delete User Accounts:
-
To delete a user account and remove their home directory, use the
userdelcommand:sudo userdel -r username -
The
-roption ensures that the user's home directory and mail spool (if present) are also removed.