08.1 – Create, delete, and modify local user accounts
Overview
Managing user accounts is a fundamental task in system administration. This guide covers how to create, delete, and modify local user accounts using command-line tools such as useradd, usermod, and userdel.
Creating Local User Accounts
Using useradd
The useradd command is used to create new user accounts.
Syntax
sudo useradd [options] <username>Examples
- Create a User with Default Settings:
sudo useradd alice- Create a User with a Home Directory:
sudo useradd -m bob- Create a User with a Specific Home Directory:
sudo useradd -m -d /home/customdir charlie- Create a User with a Specific Shell:
sudo useradd -s /bin/bash dave- Create a User with a Specific User ID (UID):
sudo useradd -u 1001 eve- Create a User with a Specific Group ID (GID):
sudo useradd -g 1001 frankSetting User Passwords
Use the passwd command to set or change a user’s password.
Syntax
sudo passwd <username>Example
Set the password for user alice:
sudo passwd aliceDeleting Local User Accounts
Using userdel
The userdel command is used to delete user accounts.
Syntax
sudo userdel [options] <username>Examples
- Delete a User Account:
sudo userdel alice- Delete a User Account and Their Home Directory:
sudo userdel -r bobModifying Local User Accounts
Using usermod
The usermod command is used to modify existing user accounts.
Syntax
sudo usermod [options] <username>Examples
- Change a User’s Home Directory:
sudo usermod -d /new/home/dir -m charlie- Change a User’s Shell:
sudo usermod -s /bin/zsh dave- Change a User’s User ID (UID):
sudo usermod -u 2001 eve- Change a User’s Group ID (GID):
sudo usermod -g 2001 frank- Add a User to a Supplementary Group:
sudo usermod -aG wheel alice- Lock a User Account:
sudo usermod -L bob
- Unlock a User Account:
sudo usermod -U bobPractical Examples
Example 1: Create a User with a Home Directory and Specific Shell
- Create the User:
sudo useradd -m -s /bin/bash alice- Set the User’s Password:
sudo passwd aliceExample 2: Delete a User and Their Home Directory
- Delete the User:
sudo userdel -r bobExample 3: Modify a User’s Home Directory and Shell
- Change the User’s Home Directory:
sudo usermod -d /new/home/dir -m charlie- Change the User’s Shell:
sudo usermod -s /bin/zsh charlieExample 4: Add a User to a Supplementary Group
- Add the User to the
wheelGroup:
sudo usermod -aG wheel daveExample 5: Lock and Unlock a User Account
- Lock the User Account:
sudo usermod -L eve- Unlock the User Account:
sudo usermod -U eveAdditional Tips
- Check User Information:Use the
idcommand to check user information.
id alice- List All Users:Use the
getent passwdcommand to list all users.
getent passwd- Check User’s Home Directory:Use the
lscommand to check the contents of a user’s home directory.
ls -l /home/alice- Check User’s Groups:Use the
groupscommand to check the groups a user belongs to.
groups alice- Create a User with an Expiry Date:Use the
-eoption withuseraddto set an account expiry date.
sudo useradd -e 2023-12-31 alice- Change a User’s Password Expiry Information:Use the
chagecommand to change password expiry information.
sudo chage -l aliceConclusion
Creating, deleting, and modifying local user accounts is essential for managing system access and security. Mastery of these tasks ensures that user accounts are managed efficiently and securely, which is crucial for the RHCSA exam.
These notes should help you understand how to create, delete, and modify local user accounts for the RHCSA exam.
08.2 – Change passwords and adjust password aging for local user accounts
Overview
Managing user passwords and configuring password aging policies are essential tasks for maintaining system security. This guide covers how to change user passwords and adjust password aging settings using commands like passwd and chage.
Changing User Passwords
Using passwd
The passwd command is used to change user passwords.
Syntax
sudo passwd <username>Examples
- Change Your Own Password:
passwd- Change Another User’s Password:
sudo passwd alice- Force a User to Change Password at Next Login:
sudo passwd -e aliceExample: Change a User’s Password
- Change the Password for User
alice:
sudo passwd alice- Force User
aliceto Change Password at Next Login:
sudo passwd -e aliceAdjusting Password Aging
Using chage
The chage command is used to adjust password aging policies for user accounts.
Syntax
sudo chage [options] <username>Options
-l: List password aging information.-m: Set the minimum number of days between password changes.-M: Set the maximum number of days a password is valid.-W: Set the number of days of warning before a password expires.-I: Set the number of days after password expiration until the account is locked.-E: Set the account expiration date.
Examples
- List Password Aging Information:
sudo chage -l alice- Set Minimum Days Between Password Changes:
sudo chage -m 7 alice- Set Maximum Days a Password is Valid:
sudo chage -M 90 alice- Set Days of Warning Before Password Expires:
sudo chage -W 7 alice- Set Days After Password Expiration Until Account is Locked:
sudo chage -I 30 alice- Set Account Expiration Date:
sudo chage -E 2023-12-31 aliceExample: Adjust Password Aging for a User
- List Password Aging Information for User
alice:
sudo chage -l alice- Set Minimum Days Between Password Changes to 7:
sudo chage -m 7 alice- Set Maximum Days a Password is Valid to 90:
sudo chage -M 90 alice- Set Days of Warning Before Password Expires to 7:
sudo chage -W 7 alice- Set Days After Password Expiration Until Account is Locked to 30:
sudo chage -I 30 alice- Set Account Expiration Date to December 31, 2023:
sudo chage -E 2023-12-31 alicePractical Examples
Example 1: Change a User’s Password and Force Password Change at Next Login
- Change the Password for User
bob:
sudo passwd bob- Force User
bobto Change Password at Next Login:
sudo passwd -e bobExample 2: Adjust Password Aging for a User
- List Password Aging Information for User
charlie:
sudo chage -l charlie- Set Minimum Days Between Password Changes to 10:
sudo chage -m 10 charlie- Set Maximum Days a Password is Valid to 60:
sudo chage -M 60 charlie- Set Days of Warning Before Password Expires to 5:
sudo chage -W 5 charlie- Set Days After Password Expiration Until Account is Locked to 15:
sudo chage -I 15 charlie- Set Account Expiration Date to June 30, 2023:
sudo chage -E 2023-06-30 charlieAdditional Tips
- Check Current Password Policies:Use the
chage -lcommand to check the current password policies for a user.
sudo chage -l alice- Set Default Password Aging Policies:Edit the
/etc/login.defsfile to set default password aging policies for new users.
sudo nano /etc/login.defsExample Entries:
PASS_MAX_DAYS 90PASS_MIN_DAYS 7PASS_WARN_AGE 7- Lock and Unlock User Accounts:Use the
passwdcommand to lock and unlock user accounts.Lock a User Account:
sudo passwd -l aliceUnlock a User Account:
sudo passwd -u alice- Force All Users to Change Passwords at Next Login:Use a loop to force all users to change their passwords at the next login.
for user in $(cut -f1 -d: /etc/passwd); do sudo passwd -e $user; doneConclusion
Changing passwords and adjusting password aging policies are essential for maintaining system security. Mastery of these tasks ensures that user accounts are managed securely and efficiently, which is crucial for the RHCSA exam.
These notes should help you understand how to change passwords and adjust password aging for local user accounts for the RHCSA exam.
08.3 – Create, delete, and modify local groups and group memberships
Overview
Managing groups and group memberships is essential for controlling access to resources and organizing users. This guide covers how to create, delete, and modify local groups and group memberships using commands like groupadd, groupdel, usermod, and gpasswd.
Creating Local Groups
Using groupadd
The groupadd command is used to create new groups.
Syntax
sudo groupadd [options] <groupname>Examples
- Create a Group with Default Settings:
sudo groupadd developers- Create a Group with a Specific Group ID (GID):
sudo groupadd -g 1001 adminsExample: Create a Group
- Create the
developersGroup:
sudo groupadd developers- Create the
adminsGroup with GID 1001:
sudo groupadd -g 1001 adminsDeleting Local Groups
Using groupdel
The groupdel command is used to delete groups.
Syntax
sudo groupdel <groupname>Examples
- Delete a Group:
sudo groupdel developersExample: Delete a Group
- Delete the
developersGroup:
sudo groupdel developersModifying Local Groups and Group Memberships
Using usermod
The usermod command is used to modify user accounts, including group memberships.
Syntax
sudo usermod [options] <username>Examples
- Add a User to a Group:sudo usermod -aG <groupname> <username>Example:sudo usermod -aG developers alice
- Remove a User from a Group:To remove a user from a group, you can use the
gpasswdcommand or manually edit the/etc/groupfile.
Using gpasswd
The gpasswd command is used to administer /etc/group and /etc/gshadow.
Syntax
sudo gpasswd [options] <groupname>Examples
- Add a User to a Group:
sudo gpasswd -a <username> <groupname>Example:
sudo gpasswd -a alice developers- Remove a User from a Group:
sudo gpasswd -d <username> <groupname>Example:
sudo gpasswd -d alice developersExample: Modify Group Memberships
- Add User
aliceto thedevelopersGroup:
sudo usermod -aG developers alice- Remove User
alicefrom thedevelopersGroup:
sudo gpasswd -d alice developersPractical Examples
Example 1: Create and Delete Groups
- Create the
developersGroup:
sudo groupadd developers- Create the
adminsGroup with GID 1001:
sudo groupadd -g 1001 admins- Delete the
developersGroup:
sudo groupdel developersExample 2: Add and Remove Users from Groups
- Add User
bobto theadminsGroup:
sudo usermod -aG admins bob- Add User
charlieto thedevelopersGroup:
sudo gpasswd -a charlie developers- Remove User
charliefrom thedevelopersGroup:
sudo gpasswd -d charlie developersExample 3: Create a Group and Add Multiple Users
- Create the
projectGroup:
sudo groupadd project- Add Multiple Users to the
projectGroup:
sudo usermod -aG project alice
sudo usermod -aG project bob
sudo usermod -aG project charlieAdditional Tips
- Check Group Information:Use the
getent groupcommand to check group information.
getent group developers- List All Groups:Use the
getent groupcommand to list all groups.
getent group- Check User’s Groups:Use the
groupscommand to check the groups a user belongs to.
groups alice- Manually Edit Group Memberships:You can manually edit the
/etc/groupfile to modify group memberships.
sudo nano /etc/group- Create a Group with a Password:Use the
gpasswdcommand to set a password for a group.
sudo gpasswd <groupname>- Change a User’s Primary Group:Use the
usermod -gcommand to change a user’s primary group.
sudo usermod -g <groupname> <username>Example:
sudo usermod -g developers aliceConclusion
Creating, deleting, and modifying local groups and group memberships are essential tasks for managing system access and organizing users. Mastery of these tasks ensures that user accounts and groups are managed efficiently and securely, which is crucial for the RHCSA exam.
These notes should help you understand how to create, delete, and modify local groups and group memberships for the RHCSA exam.
08.4 – Configure superuser access
Overview
Superuser access, typically granted to the root user, allows full control over the system. For security and administrative purposes, it is often necessary to grant superuser privileges to other users. This guide covers how to configure superuser access using the sudo command and the /etc/sudoers file.
Using sudo for Superuser Access
Installing sudo
Ensure the sudo package is installed on your system.
sudo yum install sudoGranting Superuser Access
Step 1: Edit the /etc/sudoers File
The /etc/sudoers file is used to configure sudo access. Use the visudo command to safely edit this file, as it performs syntax checking to prevent errors.
sudo visudoStep 2: Add User or Group to /etc/sudoers
Add entries to grant superuser access to specific users or groups.
Granting Superuser Access to a User
To grant superuser access to a user, add the following line:
<username> ALL=(ALL) ALLExample:
alice ALL=(ALL) ALLGranting Superuser Access to a Group
To grant superuser access to all members of a group, add the following line:
%<groupname> ALL=(ALL) ALLExample:
%wheel ALL=(ALL) ALLExample: Grant Superuser Access to a User
- Edit the
/etc/sudoersFile:
sudo visudo- Add the Following Line to Grant Superuser Access to User
alice:
alice ALL=(ALL) ALL- Save and Exit.
Example: Grant Superuser Access to a Group
- Edit the
/etc/sudoersFile:
sudo visudo- Add the Following Line to Grant Superuser Access to the
wheelGroup:
%wheel ALL=(ALL) ALL- Save and Exit.
Using sudo to Execute Commands
Users with sudo privileges can execute commands with superuser access by prefixing the command with sudo.
Syntax
sudo <command>Examples
- Execute a Command as Superuser:
sudo yum update- Edit a System Configuration File:
sudo nano /etc/hosts- Restart a Service:
sudo systemctl restart httpdUsing sudo with a Password
By default, sudo prompts for the user’s password before executing a command. This behavior can be modified in the /etc/sudoers file.
Example: Disable Password Prompt for a User
- Edit the
/etc/sudoersFile:
sudo visudo- Add the Following Line to Disable the Password Prompt for User
alice:
alice ALL=(ALL) NOPASSWD: ALL- Save and Exit.
Using sudo with Command Restrictions
You can restrict the commands that a user or group can execute with sudo.
Example: Allow a User to Execute Specific Commands
- Edit the
/etc/sudoersFile:
sudo visudo- Add the Following Line to Allow User
bobto Execute OnlysystemctlandjournalctlCommands:
bob ALL=(ALL) NOPASSWD: /bin/systemctl, /bin/journalctl- Save and Exit.
Practical Examples
Example 1: Grant Superuser Access to a User
- Edit the
/etc/sudoersFile:
sudo visudo- Add the Following Line to Grant Superuser Access to User
charlie:
charlie ALL=(ALL) ALL- Save and Exit.
Example 2: Grant Superuser Access to a Group
- Edit the
/etc/sudoersFile:
sudo visudo- Add the Following Line to Grant Superuser Access to the
adminGroup:
%admin ALL=(ALL) ALL- Save and Exit.
Example 3: Disable Password Prompt for a User
- Edit the
/etc/sudoersFile:
sudo visudo- Add the Following Line to Disable the Password Prompt for User
dave:
dave ALL=(ALL) NOPASSWD: ALL- Save and Exit.
Example 4: Restrict a User to Specific Commands
- Edit the
/etc/sudoersFile:
sudo visudo- Add the Following Line to Allow User
eveto Execute OnlysystemctlandjournalctlCommands:
eve ALL=(ALL) NOPASSWD: /bin/systemctl, /bin/journalctl- Save and Exit.
Additional Tips
- Check Sudo Access:Use the
sudo -lcommand to list the commands that a user is allowed to run withsudo.
sudo -l- Add Users to the
wheelGroup:Thewheelgroup is often used to grant sudo access. Add users to this group to grant them sudo privileges.
sudo usermod -aG wheel <username>Example:
sudo usermod -aG wheel alice- Test Sudo Configuration:Always use the
visudocommand to edit the/etc/sudoersfile, as it checks for syntax errors. - Use Aliases for Commands:You can define command aliases in the
/etc/sudoersfile to simplify complex command restrictions.
Example:
Cmnd_Alias WEBADMIN = /bin/systemctl restart httpd, /bin/systemctl restart nginx
alice ALL=(ALL) NOPASSWD: WEBADMIN- Include Additional Sudoers Files:You can include additional configuration files in the
/etc/sudoersfile using the#includedirdirective.
Example:
#includedir /etc/sudoers.dConclusion
Configuring superuser access using sudo ensures that administrative tasks can be performed securely and efficiently. Mastery of these tasks is crucial for managing system access and security, which is essential for the RHCSA exam.
These notes should help you understand how to configure superuser access for the RHCSA exam.
Discover more from Altgr Blog
Subscribe to get the latest posts sent to your email.
