Leaving presentation mode.

Manage Local Users and Groups

Dennis Kibbe

Mesa Community College

Keyboard Shortcuts

The audio accompanying this presentation is AI-generated.

Module Outline

Learning Objectives

After completing the work in this module you will be able to:

Describe User and Group Concepts

Introduction

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.

What Is a User?

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.

Types of User Accounts

Red Hat Enterprise Linux uses specific UID numbers and ranges of numbers for specific purposes.

The /etc/passwd File

The /etc/passwd file lists accounts on the system, one account per line with the seven fields separated by colons.

The student Account Entry

[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.

User Field

student:x:1000:1000:Joe Student:/home/student:/bin/bash
      

The first field in the /etc/passwd file is the name of the account.

Password Field (not used)

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.

UID Field

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.

GID Field

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.

Comment or GECOS Field

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.

Home Directory

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.

Default Shell

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.

What is a Group?

Members of a group share the same file permissions. Group accounts are listed in the /etc/group file.

The /etc/group File

Group 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.

Group Name

wheel:x:10:student
      

The first field of the group file is the name of the group.

Group Password (optional)

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.

Group ID Number

wheel:x:10:student
      

The third field contains the GID number.

Members of the Group

wheel:x:10:student,megan
      

The last field is a list of the users who are members of the group.

Primary Groups and Supplementary Groups

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.

Graded Quiz

Describe User and Group Concepts

Complete this graded quiz in Canvas.

The Superuser

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.

Switch User Accounts (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.

Run Commands with Sudo

[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.

The 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.

The Incident

This cartoon is from the xkcd website

Get an Interactive Root Shell with su

[student@servera ~]$ su -i
[sudo] password for root:
root@servera ~]#
      

The -i option to the su command opens a root shell.

Configure sudo

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.

The wheel Group

%wheel        ALL=(ALL:ALL)       ALL
    

The Advantages of Sudo

The /etc/sudoers.d Directory

Guided Exercise

Gain Superuser Access

Practice switching to the root account and running commands as root.

Manage Local User Accounts

Create, modify, and delete local user accounts.

Create Users from the Command Line

[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.

Modify Existing Users from the Command Line

[root@servera ~]# usermod -G wheel megan
      

In this example, user megan is added to the wheel group which gives her sudo privileges.

Delete Users from the Command Line

[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.

Letting Go

This cartoon is from the xkcd website

Set Passwords from the Command Line

[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.

Guided Exercise

Manage Local User Accounts

Create several users on your system and set passwords for those users.

Manage Local Groups

Create Groups from the Command Line

[root@servera ~]# groupadd consultants
      

The groupadd command adds a new group to the system.

Modify Existing Groups from the Command Line

[root@servera ~]# groupmod -n consoltants consultants 
      

Here the groupmod command is used to correct a misspelling.

Delete Groups from the Command Line

  [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.

Change Primary Group Membership from the Command Line

[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.

Add a User to a Group

[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.

Temporarily Change Your Primary Group

[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.

Guided Exercise

Manage Local Group Accounts

Manage User Passwords

Set a password management policy for users, and manually lock and unlock user accounts.

Shadow Passwords and Password Policy

[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.

The /etc/shadow file

Account name

student:$6$CSsXsd3rwghsdfarf:17933:0:99999:7:2:18113:
      

Like the /etc/passwd file the first field contains the account name.

The /etc/shadow file

Encrypted password

student:$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.

The /etc/shadow file

Days since password change

student:$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.

The /etc/shadow file

Min days before password change

student:$6$CSsXsd3rwghsdfarf:17933:0:99999:7:2:18113:
      

Minimum number of days before password can be changed.

The /etc/shadow file

Max days password is valid

student:$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.

The /etc/shadow file

Days warning before password expires

student:$6$CSsXsd3rwghsdfarf:17933:0:99999:7:2:18113:
      

Days warning before password must be changed.

The /etc/shadow file

Days after password expires that account is still open

student:$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.

The /etc/shadow file

Date account expires

student:$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.

The /etc/shadow file

Last field is unused

student:$6$CSsXsd3rwghsdfarf:17933:0:99999:7:2:18113:
      

The last field is typically empty and is reserved for future use.

Format of an Cryptographically Hashed Password

The SHA512 Hashing Algorithm

$6$CSsXcYG1L4ZfHr$2W6evvJahUfzfHpc9X.45Jc6H30E
      

The SHA512 hashing algorithm is used for this password.

Format of an Cryptographically Hashed Password

The Salt Added

$6$CSsXcYG1L4ZfHr$2W6evvJahUfzfHpc9X.45Jc6H30E
      

The salt in use to cryptographically hash the password.

Format of an Cryptographically Hashed Password

The Salt and Password Hashed

$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.

Display Password Information

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.

Restrict Access

[root@servera ~]# usermod -L megan
      

Root can lock an user's account with the -l option to the usermod command.

The nologin Shell

The nologin shell prevents logins to system accounts such as the mail server account.

Guided Exercise

Manage User Passwords

Set password policies for several users.

Summary

  1. User accounts is a way to restrict access to files and directories on a Linux system.
  2. A user has a primary group and may be a member of one or more supplementary groups.
  3. The /etc/passwd, /etc/group, and /etc/shadow critical files contain user and group information.
  4. You can run commands as the superuser with the su and sudo commands.
  5. The useradd, usermod, and userdel commands manage users.
  6. The groupadd, groupmod, and groupdel commands manage groups.
  7. The passwd command manages passwords for users.
  8. The chage command displays and configures password expiration settings for users.

Resources

Graded Lab

Manage Local Users and Groups

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

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.