After completing the work in this module you will be able to:
su
and sudo
to gain root privileges.Every file on a Linux system has an owner and belongs to a group. Every user on the system with the exception of the superuser has a limited set of permissions. The proper configuration of these permissions helps to secure the Linux operating system.
A user account provides security boundaries between different people and programs that can run commands. User accounts are fundamental to system security. Every process on the system runs as a particular user. Every file has a particular user as its owner and belongs to a group.
Red Hat Enterprise Linux uses specific UID numbers and ranges of numbers for specific purposes.
/etc/passwd
FileThe /etc/passwd
file lists accounts on the system, one account per line with the seven fields separated by colons.
[student@servera ~]$ grep student /etc/passwd student:x:1000:1000:Joe Student:/home/student:/bin/bash
The /etc/passwd
file lists accounts on the system, one account per line with the seven fields separated by colons.
student:x:1000:1000:Joe Student:/home/student:/bin/bash
The first field in the /etc/passwd
file is the name of the account.
student:x:1000:1000:Joe Student:/home/student:/bin/bash
Previously this field held the user's encrypted password which is now stored in the restricted /etc/shadow
file.
student:x:1000:1000:Joe Student:/home/student:/bin/bash
This field holds the User ID number. This is the number the computer uses to refer to the user account.
student:x:1000:1000:Joe Student:/home/student:/bin/bash
The User ID field is followed by the Group ID field. On most Linux distributions each user has a unique private group.
student:x:1000:1000:Joe Student:/home/student:/bin/bash
This comment or GECOS field contains the user's actual name, phone number, room number, etc.
student:x:1000:1000:Joe Student:/home/student:/bin/bash
This is the user's home directory and the working directory when the user first logs into the system.
student:x:1000:1000:Joe Student:/home/student:/bin/bash
The last field is the user's default shell. System accounts use the /sbin/nologin
shell. This prevents remote logins to the mail server account, for example, which would raise a red flag with any Linux administrator.
Members of a group share the same file permissions. Group accounts are listed in the /etc/group
file.
/etc/group
FileGroup information is kept in the /etc/group
file using the same format as the /etc/passwd
file with one account per line and fields separated by a colon. Here student
belongs to two groups, the private student
group and the wheel
group.
wheel:x:10:student
The first field of the group file is the name of the group.
wheel:x:10:student
The second field was used to store the encrypted group password, if used. Now that information is kept in a restricted shadow file.
wheel:x:10:student
The third field contains the GID number.
wheel:x:10:student,megan
The last field is a list of the users who are members of the group.
Each user belongs to a primary group which is unique to that user and each user can belong to supplementary groups as well. In this screenshot user student belongs to the private primary group student and the supplementary group wheel.
Complete this graded quiz in Canvas.
The superuser or root account is all powerful and should be reserved for system administration tasks. When logged in as root, the entire desktop environment unnecessarily runs with administrative privileges. A security vulnerability that might normally compromise only a normal user's account could potentially compromise the entire system. An ordinary, unprivileged user has limited permissions on the system and as such can not accidentally edit or delete system files.
su
)[student@servera ~]$ su -l megan Password: megan@servera ~]$ pwd /home/megan
Here student
uses the su
command to become megan
. Student must first know Megan's password. The -l
option assures that the shell environment changes to that of Megan's. If no user name is given then the root account is assumed and the root password must be given.
[student@servera ~]$ sudo grep wheel /etc/sudoers ## Allows people in group wheel to run all commands %wheel ALL=(ALL) ALL # %wheel ALL=(ALL) ALL=(ALL) NOPASSWD: ALL
Users in the sudoers file have elevated privileges and can run some or all commands as root. On a Red Hat system users in the wheel group have full superuser privileges. Lines in the sudoers file starting with a hash tag are commented out.
sudo
Command[megan@servera ~]$ sudo cd /etc/ssh/ [sudo] password for megan: megan is not in the sudoers file. This incident will be reported [megan@servera ~]$
Users in the sudoers
file can use sudo
to run commands with elevated privileges. Here Megan's attempt to use sudo
fails because she is not in the sudoers file. The incident is logged in /var/log/secure
.
This cartoon is from the xkcd website
[student@servera ~]$ su -i [sudo] password for root: root@servera ~]#
The -i
option to the su
command opens a root shell.
The /etc/sudoers
file is the main configuration file for the sudo
command. The visudo
command should be used to edit the /etc/sudoers
file or any file in the /etc/sudoers.d/
directory. visudo
checks for syntax errors in the file before exiting. Errors in the /etc/sudoers
file might prevent the root user from running commands.
wheel
Group%wheel ALL=(ALL:ALL) ALL
%wheel
string is the group that the rule applies to. Here it applies to all members of the wheel group.ALL
applies to all hosts.ALL
means that users in the wheel group can run commands as any user.ALL
means that users in the wheel group can run commands as any group.ALL
means that users in the wheel group can run any command./etc/sudoers.d
DirectoryPractice switching to the root account and running commands as root.
Create, modify, and delete local user accounts.
[root@servera ~]# useradd megan [root@servera ~]# passwd megan
Adding a user in Red Hat Enterprise Linux takes two steps. First the account must be created then a password assigned to the account. Until a password is assigned the account is locked.
[root@servera ~]# usermod -G wheel megan
In this example, user megan
is added to the wheel
group which gives her sudo
privileges.
[root@servera ~]# userdel -r megan
The userdel
command removes a user from the system. The optional -r
removes that user's home directory and mail spool.
This cartoon is from the xkcd website
[root@servera ~]# passwd megan Changing password for user megan. New password: redhat BAD PASSWORD: The password is shorter than 8 characters Retype new password: redhat passwd: all authentication tokens updated successfully. [root@host ~]#
The passwd
command warns that the password given does not meet the password policy set. Root, however, can override the policy but regular users can not. Remember on the command line no characters display when you type the password.
Create several users on your system and set passwords for those users.
[root@servera ~]# groupadd consultants
The groupadd
command adds a new group to the system.
[root@servera ~]# groupmod -n consoltants consultants
Here the groupmod
command is used to correct a misspelling.
[root@servera ~]# groupdel consultants
Before deleting a group use the find
command to locate all files owned by the group. You can not remove the primary group of a user.
[root@servera ~]# usermod -G users megan
This command changes Megan's primary group. A user can belong to only one primary group at a time.
[root@servera ~]# usermod -aG consultants megan
Here Megan is added to the consultants
group. The -a
(append) assures that Megan is not removed from the other supplemental groups she belongs to.
[megan@servera ~]$ newgrp consultants
A user's primary group can be temporarily changed to a supplementary group so new files create belong to the supplementary group.
Set a password management policy for users, and manually lock and unlock user accounts.
[root@servera ~]# grep student /etc/shadow student:$6$CSsXsd3rwghsdfarf:17933:0:99999:7:2:18113:
Originally, encrypted passwords were stored in the world-readable /etc/passwd
file. This was considered adequate until dictionary attacks on encrypted passwords became common. The /etc/shadow
file contains encrypted passwords and password expiry information. Similar to the passwd
file each row represents a single account and fields are separated by a colon.T he /etc/shadow
file require root privileges to read.
/etc/shadow
filestudent:$6$CSsXsd3rwghsdfarf:17933:0:99999:7:2:18113:
Like the /etc/passwd
file the first field contains the account name.
/etc/shadow
filestudent:$6$CSsXsd3rwghsdfarf:17933:0:99999:7:2:18113:
The next field contains the encrypted password the $6
indicates that the password is encrypted using SHA512 hashing algorithm.
/etc/shadow
filestudent:$6$CSsXsd3rwghsdfarf:17933:0:99999:7:2:18113:
This field shows the number of days since January 1, 1970 that the password was last changed.
/etc/shadow
filestudent:$6$CSsXsd3rwghsdfarf:17933:0:99999:7:2:18113:
Minimum number of days before password can be changed.
/etc/shadow
filestudent:$6$CSsXsd3rwghsdfarf:17933:0:99999:7:2:18113:
Maximum number of days before password must be changed. Five 9s means that the password doesn't need to be changed.
/etc/shadow
filestudent:$6$CSsXsd3rwghsdfarf:17933:0:99999:7:2:18113:
Days warning before password must be changed.
/etc/shadow
filestudent:$6$CSsXsd3rwghsdfarf:17933:0:99999:7:2::18113:
The number of days without activity, starting with the day that the password expired, before the account is automatically locked.
/etc/shadow
filestudent:$6$CSsXsd3rwghsdfarf:17933:0:99999:7:2::18113:
The day when the account expires in days since the epoch. An empty field means that the account never expires.
/etc/shadow
filestudent:$6$CSsXsd3rwghsdfarf:17933:0:99999:7:2:18113:
The last field is typically empty and is reserved for future use.
$6$CSsXcYG1L4ZfHr$2W6evvJahUfzfHpc9X.45Jc6H30E
The SHA512 hashing algorithm is used for this password.
$6$CSsXcYG1L4ZfHr$2W6evvJahUfzfHpc9X.45Jc6H30E
The salt in use to cryptographically hash the password.
$6$CSsXcYG1L4ZfHr$2W6evvJahUfzfHpc9X.45Jc6H30E
The cryptographical hash of the user's password; combining the salt and the plain text password and then cryptographically hashing to generate the password hash.
The chage
or "change age" command displays password information for the listed user. The root user can list password information for any user. The chage
command is also used to set a password aging policy.
[root@servera ~]# usermod -L megan
Root can lock an user's account with the -l
option to the usermod
command.
The nologin
shell prevents logins to system accounts such as the mail server account.
Set password policies for several users.
/etc/passwd
, /etc/group
, and /etc/shadow
critical files contain user and group information.Set a default local password policy, create a supplementary group for three users, allow that group to use sudo
to run commands as root, and modify the password policy for one user.
Thanks for watching. This is the end of the presentation.
Created on 17 February 2025 by Dennis Kibbe. Last modified on 9 June 2025 09:21:00 by DNK.
Keyboard Shortcuts
The audio accompanying this presentation is AI-generated.