4.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
passwd
command followed by the username:sudo passwd username
Replace
username
with 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
usermod
command with appropriate options. For example, to change a user's full name:sudo usermod -c "New Full Name" username
Replace
"New Full Name"
with the updated full name andusername
with the user's name.
3. Changing User Shell:
To change a user's default shell, use the
chsh
command:sudo chsh -s /path/to/newshell username
Replace
/path/to/newshell
with the path to the desired shell (e.g.,/bin/bash
,/bin/zsh
) andusername
with the user's name.
4. Adding Users to Groups:
To add a user to one or more groups, you can use the
usermod
command with the-aG
option:sudo usermod -aG group1,group2 username
Replace
group1
andgroup2
with 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
usermod
command with the-m
option:sudo usermod -m -d /new/home/directory username
Replace
/new/home/directory
with the new path to the home directory andusername
with the user's name.
6. Locking and Unlocking User Accounts:
You can lock a user account to prevent login using the
passwd
command:sudo passwd -l username
To unlock a locked account, use the
-u
option:sudo passwd -u username
7. Expire or Disable User Accounts:
To expire or disable a user account, use the
chage
command: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
userdel
command:sudo userdel -r username
The
-r
option ensures that the user's home directory and mail spool (if present) are also removed.
Last updated
Was this helpful?