Managing User Accounts
Once you have created a new user account, you may need to perform various management tasks to maintain and control user access to your Linux system. Here are some common user account management operations:
Modifying User Accounts
To modify an existing user account, you can use the usermod
command. For example, to change the default shell for a user:
sudo usermod -s /bin/zsh newuser
This command changes the default shell for the newuser
account to Zsh.
Deleting User Accounts
If a user account is no longer needed, you can delete it using the userdel
command:
sudo userdel -r newuser
The -r
option removes the user's home directory and mail spool.
Listing User Accounts
To view a list of all user accounts on the system, you can use the cut
and awk
commands:
cut -d: -f1 /etc/passwd
This command displays a list of all usernames on the system.
User Groups
In Linux, users can be assigned to one or more groups, which can be used to manage permissions and access control. You can manage user groups using the following commands:
groupadd
: Create a new group
groupmod
: Modify an existing group
groupdel
: Delete a group
usermod
: Add a user to a group
For example, to add a user to an existing group:
sudo usermod -a -G developers newuser
This command adds the newuser
account to the developers
group.
By understanding these user account management operations, you can effectively maintain and control user access to your Linux system, ensuring a secure and organized environment.