Creating and Modifying User Accounts
Creating and managing user accounts is a crucial task for Linux system administrators. This section will cover the essential commands and techniques for creating new user accounts, modifying existing ones, and managing user properties and passwords.
Creating User Accounts
The primary command for creating new user accounts in Linux is useradd
. This command allows you to specify various options to customize the user account, such as the user's home directory, default shell, and group memberships.
sudo useradd -m -s /bin/bash newuser
In this example, the -m
option creates a home directory for the new user, and the -s
option sets the default shell to /bin/bash
.
Modifying User Accounts
Once a user account has been created, you can use the usermod
command to modify its properties. Some common use cases for usermod
include:
- Changing the user's primary group:
sudo usermod -g developers newuser
- Adding the user to additional groups:
sudo usermod -aG sudo newuser
- Changing the user's login shell:
sudo usermod -s /bin/zsh newuser
- Locking or unlocking a user account:
sudo usermod -L newuser
sudo usermod -U newuser
Managing User Passwords
The passwd
command is used to change the password of a user account. This command can be used by both the root user and regular users to update their own passwords.
sudo passwd newuser
By understanding these user management commands and techniques, system administrators can effectively create, modify, and secure user accounts on their Linux systems.