Red Hat Enterprise Linux-9-Configuring Basic System Settings-En-Us
Red Hat Enterprise Linux-9-Configuring Basic System Settings-En-Us
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons
Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is
available at
http://creativecommons.org/licenses/by-sa/3.0/
. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must
provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert,
Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift,
Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States
and other countries.
Linux ® is the registered trademark of Linus Torvalds in the United States and other countries.
XFS ® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States
and/or other countries.
MySQL ® is a registered trademark of MySQL AB in the United States, the European Union and
other countries.
Node.js ® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the
official Joyent Node.js open source or commercial project.
The OpenStack ® Word Mark and OpenStack logo are either registered trademarks/service marks
or trademarks/service marks of the OpenStack Foundation, in the United States and other
countries and are used with the OpenStack Foundation's permission. We are not affiliated with,
endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
Abstract
This document describes basics of system administration on Red Hat Enterprise Linux 9. The title
focuses on: basic tasks that a system administrator needs to do just after the operating system has
been successfully installed, installing software with DNF, using systemd for service management,
managing users, groups and file permissions, using chrony to configure NTP and others.
Table of Contents
Table of Contents
. . . . . . . . . .OPEN
MAKING . . . . . . SOURCE
. . . . . . . . . .MORE
. . . . . . .INCLUSIVE
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7. . . . . . . . . . . . .
. . . . . . . . . . . . . FEEDBACK
PROVIDING . . . . . . . . . . . . ON
. . . .RED
. . . . .HAT
. . . . .DOCUMENTATION
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8. . . . . . . . . . . . .
.CHAPTER
. . . . . . . . . . 1.. .PREPARING
. . . . . . . . . . . . .A. .CONTROL
. . . . . . . . . . . NODE
. . . . . . .AND
. . . . . MANAGED
. . . . . . . . . . . .NODES
. . . . . . . .TO
. . . USE
. . . . . RHEL
. . . . . . SYSTEM
. . . . . . . . . .ROLES
. . . . . . . . . . . . . . 9. . . . . . . . . . . . .
1.1. INTRODUCTION TO RHEL SYSTEM ROLES 9
1.2. RHEL SYSTEM ROLES TERMINOLOGY 9
1.3. PREPARING A CONTROL NODE 10
1.4. PREPARING A MANAGED NODE 12
1.5. VERIFYING ACCESS FROM THE CONTROL NODE TO MANAGED NODES 13
.CHAPTER
. . . . . . . . . . 2.
. . CHANGING
. . . . . . . . . . . . .BASIC
. . . . . . .ENVIRONMENT
. . . . . . . . . . . . . . . . SETTINGS
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
..............
2.1. CONFIGURING THE DATE AND TIME 15
2.1.1. Displaying the current date and time 15
2.2. CONFIGURING THE SYSTEM LOCALE 15
2.3. CONFIGURING THE KEYBOARD LAYOUT 16
2.4. CHANGING THE LANGUAGE USING DESKTOP GUI 17
2.5. ADDITIONAL RESOURCES 19
.CHAPTER
. . . . . . . . . . 3.
. . CONFIGURING
. . . . . . . . . . . . . . . . AND
. . . . . .MANAGING
. . . . . . . . . . . . NETWORK
. . . . . . . . . . . .ACCESS
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20
..............
3.1. CONFIGURING THE NETWORK AND HOST NAME IN THE GRAPHICAL INSTALLATION MODE 20
3.2. CONFIGURING A STATIC ETHERNET CONNECTION USING NMCLI 21
3.3. CONFIGURING A DYNAMIC ETHERNET CONNECTION USING NMTUI 23
3.4. CONFIGURING A STATIC ETHERNET CONNECTION USING NMTUI 24
3.5. MANAGING NETWORKING IN THE RHEL WEB CONSOLE 27
3.6. MANAGING NETWORKING USING RHEL SYSTEM ROLES 28
3.7. ADDITIONAL RESOURCES 29
.CHAPTER
. . . . . . . . . . 4.
. . .REGISTERING
. . . . . . . . . . . . . . .THE
. . . . SYSTEM
. . . . . . . . . .AND
. . . . .MANAGING
. . . . . . . . . . . . SUBSCRIPTIONS
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .30
..............
4.1. REGISTERING THE SYSTEM AFTER THE INSTALLATION 30
4.2. REGISTERING SUBSCRIPTIONS WITH CREDENTIALS IN THE WEB CONSOLE 31
4.3. REGISTERING A SYSTEM USING RED HAT ACCOUNT ON GNOME 32
4.4. REGISTERING A SYSTEM USING AN ACTIVATION KEY ON GNOME 33
.CHAPTER
. . . . . . . . . . 5.
. . MAKING
. . . . . . . . . .SYSTEMD
. . . . . . . . . . .SERVICES
. . . . . . . . . . .START
. . . . . . .AT
. . . BOOT
. . . . . . . TIME
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .35
..............
5.1. ENABLING OR DISABLING SERVICES 35
.CHAPTER
. . . . . . . . . . 6.
. . .CONFIGURING
. . . . . . . . . . . . . . . SYSTEM
. . . . . . . . . .SECURITY
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .36
..............
6.1. ENABLING THE FIREWALLD SERVICE 36
6.2. MANAGING BASIC SELINUX SETTINGS 37
6.3. ENSURING THE REQUIRED STATE OF SELINUX 37
6.4. ADDITIONAL RESOURCES 38
.CHAPTER
. . . . . . . . . . 7.
. . GETTING
. . . . . . . . . . .STARTED
. . . . . . . . . .WITH
. . . . . . MANAGING
. . . . . . . . . . . . .USER
. . . . . .ACCOUNTS
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .39
..............
7.1. MANAGING ACCOUNTS AND GROUPS USING COMMAND LINE TOOLS 39
7.2. SYSTEM USER ACCOUNTS MANAGED IN THE WEB CONSOLE 40
7.3. ADDING NEW ACCOUNTS USING THE WEB CONSOLE 40
. . . . . . . . . . . 8.
CHAPTER . . .DUMPING
..........A
. . CRASHED
. . . . . . . . . . . KERNEL
. . . . . . . . . FOR
. . . . . LATER
. . . . . . . .ANALYSIS
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42
..............
8.1. WHAT IS KDUMP 42
8.2. CONFIGURING KDUMP MEMORY USAGE AND TARGET LOCATION IN WEB CONSOLE 42
8.3. KDUMP USING RHEL SYSTEM ROLES 44
8.4. ADDITIONAL RESOURCES 45
1
Red Hat Enterprise Linux 9 Configuring basic system settings
.CHAPTER
. . . . . . . . . . 9.
. . .RECOVERING
. . . . . . . . . . . . . . AND
. . . . . RESTORING
. . . . . . . . . . . . . .A. .SYSTEM
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .46
..............
9.1. SETTING UP REAR 46
9.2. USING A REAR RESCUE IMAGE ON THE 64-BIT IBM Z ARCHITECTURE 47
.CHAPTER
. . . . . . . . . . 10.
. . . TROUBLESHOOTING
. . . . . . . . . . . . . . . . . . . . . . .PROBLEMS
. . . . . . . . . . . . USING
. . . . . . . .LOG
. . . . .FILES
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .50
..............
10.1. SERVICES HANDLING SYSLOG MESSAGES 50
10.2. SUBDIRECTORIES STORING SYSLOG MESSAGES 50
10.3. INSPECTING LOG FILES USING THE WEB CONSOLE 50
10.4. VIEWING LOGS USING THE COMMAND LINE 51
10.5. ADDITIONAL RESOURCES 52
. . . . . . . . . . . 11.
CHAPTER . . .ACCESSING
. . . . . . . . . . . . .THE
. . . . .RED
. . . . HAT
. . . . . SUPPORT
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .53
..............
11.1. OBTAINING RED HAT SUPPORT THROUGH RED HAT CUSTOMER PORTAL 53
11.2. TROUBLESHOOTING PROBLEMS USING SOSREPORT 53
. . . . . . . . . . . 12.
CHAPTER . . . INTRODUCTION
. . . . . . . . . . . . . . . . . TO
. . . .SYSTEMD
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .55
..............
.CHAPTER
. . . . . . . . . . 13.
. . . MANAGING
. . . . . . . . . . . . .SYSTEM
. . . . . . . . . SERVICES
. . . . . . . . . . . WITH
. . . . . . SYSTEMCTL
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .57
..............
13.1. LISTING SYSTEM SERVICES 57
13.2. DISPLAYING SYSTEM SERVICE STATUS 58
13.3. STARTING A SYSTEM SERVICE 60
13.4. STOPPING A SYSTEM SERVICE 61
13.5. RESTARTING A SYSTEM SERVICE 62
13.6. ENABLING A SYSTEM SERVICE 63
13.7. DISABLING A SYSTEM SERVICE 64
.CHAPTER
. . . . . . . . . . 14.
. . . WORKING
. . . . . . . . . . . WITH
. . . . . . SYSTEMD
. . . . . . . . . . . TARGETS
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .65
..............
14.1. VIEWING THE DEFAULT TARGET 65
14.2. VIEWING THE TARGET UNITS 65
14.3. CHANGING THE DEFAULT TARGET 66
14.4. CHANGING THE DEFAULT TARGET USING A SYMBOLIC LINK 67
14.5. CHANGING THE CURRENT TARGET 68
14.6. BOOTING TO RESCUE MODE 68
14.7. BOOTING TO EMERGENCY MODE 69
. . . . . . . . . . . 15.
CHAPTER . . . SHUTTING
. . . . . . . . . . . .DOWN,
. . . . . . . .SUSPENDING,
. . . . . . . . . . . . . . .AND
. . . . . HIBERNATING
. . . . . . . . . . . . . . . THE
. . . . . SYSTEM
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .70
..............
15.1. SYSTEM SHUTDOWN 70
15.2. SHUTTING DOWN THE SYSTEM USING THE SHUTDOWN COMMAND 70
15.3. SHUTTING DOWN THE SYSTEM USING THE SYSTEMCTL COMMAND 71
15.4. RESTARTING THE SYSTEM 71
15.5. SUSPENDING THE SYSTEM 72
15.6. HIBERNATING THE SYSTEM 72
15.7. OVERVIEW OF THE POWER MANAGEMENT COMMANDS WITH SYSTEMCTL 73
. . . . . . . . . . . 16.
CHAPTER . . . WORKING
. . . . . . . . . . . WITH
. . . . . . SYSTEMD
. . . . . . . . . . . UNIT
. . . . . .FILES
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .74
..............
16.1. INTRODUCTION TO UNIT FILES 74
16.2. UNIT FILE STRUCTURE 74
16.3. IMPORTANT [UNIT] SECTION OPTIONS 75
16.4. IMPORTANT [SERVICE] SECTION OPTIONS 76
16.5. IMPORTANT [INSTALL] SECTION OPTIONS 77
16.6. CREATING CUSTOM UNIT FILES 77
16.7. CREATING A CUSTOM UNIT FILE BY USING THE SECOND INSTANCE OF THE SSHD SERVICE 79
16.8. CONVERTING SYSV INIT SCRIPTS TO UNIT FILES 80
16.9. FINDING THE SYSTEMD SERVICE DESCRIPTION 81
16.10. FINDING THE SYSTEMD SERVICE DEPENDENCIES 81
2
Table of Contents
. . . . . . . . . . . 17.
CHAPTER . . . OPTIMIZING
. . . . . . . . . . . . . SYSTEMD
. . . . . . . . . . . TO
. . . .SHORTEN
. . . . . . . . . . .THE
. . . . .BOOT
. . . . . . TIME
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
..............
17.1. EXAMINING SYSTEM BOOT PERFORMANCE 91
Analyzing overall boot time 91
Analyzing unit initialization time 91
Identifying critical units 91
17.2. A GUIDE TO SELECTING SERVICES THAT CAN BE SAFELY DISABLED 92
17.3. ADDITIONAL RESOURCES 96
.CHAPTER
. . . . . . . . . . 18.
. . . INTRODUCTION
. . . . . . . . . . . . . . . . . TO
. . . .MANAGING
. . . . . . . . . . . . .USER
. . . . . .AND
. . . . .GROUP
. . . . . . . . ACCOUNTS
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .97
..............
18.1. INTRODUCTION TO USERS AND GROUPS 97
18.2. CONFIGURING RESERVED USER AND GROUP IDS 97
18.3. USER PRIVATE GROUPS 98
.CHAPTER
. . . . . . . . . . 19.
. . . MANAGING
. . . . . . . . . . . . .USER
. . . . . .ACCOUNTS
. . . . . . . . . . . . .IN
. . THE
. . . . . WEB
. . . . . .CONSOLE
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .99
..............
19.1. SYSTEM USER ACCOUNTS MANAGED IN THE WEB CONSOLE 99
19.2. ADDING NEW ACCOUNTS USING THE WEB CONSOLE 99
19.3. ENFORCING PASSWORD EXPIRATION IN THE WEB CONSOLE 100
19.4. TERMINATING USER SESSIONS IN THE WEB CONSOLE 101
. . . . . . . . . . . 20.
CHAPTER . . . .MANAGING
. . . . . . . . . . . . USERS
. . . . . . . .FROM
. . . . . . .THE
. . . . .COMMAND
. . . . . . . . . . . .LINE
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .103
...............
20.1. ADDING A NEW USER FROM THE COMMAND LINE 103
20.2. ADDING A NEW GROUP FROM THE COMMAND LINE 103
20.3. ADDING A USER TO A SUPPLEMENTARY GROUP FROM THE COMMAND LINE 104
20.4. CREATING A GROUP DIRECTORY 105
. . . . . . . . . . . 21.
CHAPTER . . . EDITING
. . . . . . . . . USER
. . . . . . .GROUPS
. . . . . . . . . USING
. . . . . . . .THE
. . . . COMMAND
. . . . . . . . . . . . .LINE
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .107
...............
21.1. PRIMARY AND SUPPLEMENTARY USER GROUPS 107
21.2. LISTING THE PRIMARY AND SUPPLEMENTARY GROUPS OF A USER 107
21.3. CHANGING THE PRIMARY GROUP OF A USER 108
21.4. ADDING A USER TO A SUPPLEMENTARY GROUP FROM THE COMMAND LINE 109
21.5. REMOVING A USER FROM A SUPPLEMENTARY GROUP 109
21.6. CHANGING ALL OF THE SUPPLEMENTARY GROUPS OF A USER 110
.CHAPTER
. . . . . . . . . . 22.
. . . .MANAGING
. . . . . . . . . . . . SUDO
. . . . . . .ACCESS
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .112
..............
22.1. USER AUTHORIZATIONS IN SUDOERS 112
22.2. GRANTING SUDO ACCESS TO A USER 113
22.3. ENABLING UNPRIVILEGED USERS TO RUN CERTAIN COMMANDS 114
22.4. ADDITIONAL RESOURCES 116
. . . . . . . . . . . 23.
CHAPTER . . . .CHANGING
. . . . . . . . . . . .AND
. . . . . RESETTING
. . . . . . . . . . . . .THE
. . . . .ROOT
. . . . . . PASSWORD
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .117
..............
23.1. CHANGING THE ROOT PASSWORD AS THE ROOT USER 117
23.2. CHANGING OR RESETTING THE FORGOTTEN ROOT PASSWORD AS A NON-ROOT USER 117
23.3. RESETTING THE ROOT PASSWORD ON BOOT 117
3
Red Hat Enterprise Linux 9 Configuring basic system settings
.CHAPTER
. . . . . . . . . . 24.
. . . .MANAGING
. . . . . . . . . . . . FILE
. . . . . .PERMISSIONS
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .120
...............
24.1. BASE FILE PERMISSIONS 120
24.2. USER FILE-CREATION MODE MASK 122
24.3. DEFAULT FILE PERMISSIONS 123
24.4. CHANGING FILE PERMISSIONS USING SYMBOLIC VALUES 125
24.5. CHANGING FILE PERMISSIONS USING OCTAL VALUES 127
.CHAPTER
. . . . . . . . . . 25.
. . . .MANAGING
. . . . . . . . . . . . THE
. . . . .UMASK
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
...............
25.1. DISPLAYING THE CURRENT VALUE OF THE UMASK 128
25.2. DISPLAYING THE DEFAULT BASH UMASK 128
25.3. SETTING THE UMASK USING SYMBOLIC VALUES 129
25.4. SETTING THE UMASK USING OCTAL VALUES 130
25.5. CHANGING THE DEFAULT UMASK FOR THE NON-LOGIN SHELL 130
25.6. CHANGING THE DEFAULT UMASK FOR THE LOGIN SHELL 131
25.7. CHANGING THE DEFAULT UMASK FOR A SPECIFIC USER 131
25.8. SETTING DEFAULT PERMISSIONS FOR NEWLY CREATED HOME DIRECTORIES 132
. . . . . . . . . . . 26.
CHAPTER . . . .MANAGING
. . . . . . . . . . . . THE
. . . . . ACCESS
. . . . . . . . . CONTROL
. . . . . . . . . . . .LIST
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .133
...............
26.1. DISPLAYING THE CURRENT ACCESS CONTROL LIST 133
26.2. SETTING THE ACCESS CONTROL LIST 133
.CHAPTER
. . . . . . . . . . 27.
. . . .USING
. . . . . . .THE
. . . . .CHRONY
. . . . . . . . . .SUITE
. . . . . . TO
. . . .CONFIGURE
. . . . . . . . . . . . . NTP
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
...............
27.1. INTRODUCTION TO CHRONY SUITE 135
27.2. USING CHRONYC TO CONTROL CHRONYD 135
. . . . . . . . . . . 28.
CHAPTER . . . .USING
. . . . . . .CHRONY
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
...............
28.1. MANAGING CHRONY 137
28.2. CHECKING IF CHRONY IS SYNCHRONIZED 137
28.3. MANUALLY ADJUSTING THE SYSTEM CLOCK 138
28.4. SETTING UP CHRONY FOR A SYSTEM IN AN ISOLATED NETWORK 139
28.5. CONFIGURING REMOTE MONITORING ACCESS 140
28.6. MANAGING TIME SYNCHRONIZATION USING RHEL SYSTEM ROLES 141
28.7. ADDITIONAL RESOURCES 142
. . . . . . . . . . . 29.
CHAPTER . . . .CHRONY
. . . . . . . . . .WITH
. . . . . .HW
. . . .TIMESTAMPING
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .143
...............
29.1. VERIFYING SUPPORT FOR HARDWARE TIMESTAMPING 143
29.2. ENABLING HARDWARE TIMESTAMPING 144
29.3. CONFIGURING CLIENT POLLING INTERVAL 144
29.4. ENABLING INTERLEAVED MODE 144
29.5. CONFIGURING SERVER FOR LARGE NUMBER OF CLIENTS 145
29.6. VERIFYING HARDWARE TIMESTAMPING 145
29.7. CONFIGURING PTP-NTP BRIDGE 146
.CHAPTER
. . . . . . . . . . 30.
. . . .OVERVIEW
. . . . . . . . . . . .OF
. . . NETWORK
. . . . . . . . . . . .TIME
. . . . . .SECURITY
. . . . . . . . . . .(NTS)
. . . . . . IN
. . .CHRONY
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .147
...............
30.1. ENABLING NETWORK TIME SECURITY (NTS) IN THE CLIENT CONFIGURATION FILE 147
30.2. ENABLING NETWORK TIME SECURITY (NTS) ON THE SERVER 148
. . . . . . . . . . . 31.
CHAPTER . . . USING
. . . . . . . .SECURE
. . . . . . . . .COMMUNICATIONS
. . . . . . . . . . . . . . . . . . . . .BETWEEN
. . . . . . . . . . .TWO
. . . . . SYSTEMS
. . . . . . . . . . .WITH
. . . . . .OPENSSH
. . . . . . . . . . . . . . . . . . . . . .150
...............
31.1. SSH AND OPENSSH 150
31.2. CONFIGURING AND STARTING AN OPENSSH SERVER 151
31.3. SETTING AN OPENSSH SERVER FOR KEY-BASED AUTHENTICATION 153
31.4. GENERATING SSH KEY PAIRS 154
31.5. USING SSH KEYS STORED ON A SMART CARD 155
31.6. MAKING OPENSSH MORE SECURE 156
31.7. CONNECTING TO A REMOTE SERVER USING AN SSH JUMP HOST 159
4
Table of Contents
31.8. CONNECTING TO REMOTE MACHINES WITH SSH KEYS USING SSH-AGENT 160
31.9. ADDITIONAL RESOURCES 161
5
Red Hat Enterprise Linux 9 Configuring basic system settings
6
MAKING OPEN SOURCE MORE INCLUSIVE
7
Red Hat Enterprise Linux 9 Configuring basic system settings
1. View the documentation in the Multi-page HTML format and ensure that you see the
Feedback button in the upper right corner after the page fully loads.
2. Use your cursor to highlight the part of the text that you want to comment on.
3. Click the Add Feedback button that appears near the highlighted text.
4. Enter your suggestion for improvement in the Description field. Include links to the relevant
parts of the documentation.
8
CHAPTER 1. PREPARING A CONTROL NODE AND MANAGED NODES TO USE RHEL SYSTEM ROLES
On Red Hat Enterprise Linux 9, the interface currently consists of the following roles:
Metrics (metrics)
Network Bound Disk Encryption client and Network Bound Disk Encryption server (nbde_client
and nbde_server)
Networking (network)
Postfix (postfix)
All these roles are provided by the rhel-system-roles package available in the AppStream repository.
Additional resources
Ansible playbook
Playbooks are Ansible’s configuration, deployment, and orchestration language. They can describe a
policy you want your remote systems to enforce, or a set of steps in a general IT process.
Control node
Any machine with Ansible installed. You can run commands and playbooks, invoking /usr/bin/ansible
or /usr/bin/ansible-playbook, from any control node. You can use any computer that has Python
installed on it as a control node - laptops, shared desktops, and servers can all run Ansible. However,
9
Red Hat Enterprise Linux 9 Configuring basic system settings
you cannot use a Windows machine as a control node. You can have multiple control nodes.
Inventory
A list of managed nodes. An inventory file is also sometimes called a “hostfile”. Your inventory can
specify information like IP address for each managed node. An inventory can also organize managed
nodes, creating and nesting groups for easier scaling. To learn more about inventory, see the
Working with Inventory section.
Managed nodes
The network devices, servers, or both that you manage with Ansible. Managed nodes are also
sometimes called “hosts”. Ansible is not installed on managed nodes.
Prerequisites
You attached a Red Hat Enterprise Linux Server subscription to the system.
If available in your Customer Portal account, you attached an Ansible Automation Platform
subscription to the system.
Procedure
2. Create a user that you later use to manage and execute playbooks:
[root@control-node]# su - ansible
[ansible@control-node]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ansible/.ssh/id_rsa): password
...
5. Optional: Configure an SSH agent to prevent Ansible from prompting you for the SSH key
10
CHAPTER 1. PREPARING A CONTROL NODE AND MANAGED NODES TO USE RHEL SYSTEM ROLES
5. Optional: Configure an SSH agent to prevent Ansible from prompting you for the SSH key
password each time you establish a connection.
[defaults]
inventory = /home/ansible/inventory
remote_user = ansible
[privilege_escalation]
become = True
become_method = sudo
become_user = root
become_ask_pass = True
Ansible uses the account set in the remote_user parameter when it establishes SSH
connections to managed nodes.
Ansible uses the sudo utility to execute tasks on managed nodes as the root user.
For security reasons, configure sudo on managed nodes to require entering the password
of the remote user to become root. By specifying the become_ask_pass=True setting in
~/.ansible.cfg, Ansible prompts for this password when you execute a playbook.
Settings in the ~/.ansible.cfg file have a higher priority and override settings from the global
/etc/ansible/ansible.cfg file.
7. Create the ~/inventory file. For example, the following is an inventory file in the INI format with
three hosts and one host group named US:
managed-node-01.example.com
[US]
managed-node-02.example.com ansible_host=192.0.2.100
managed-node-03.example.com
Note that the control node must be able to resolve the hostnames. If the DNS server cannot
resolve certain hostnames, add the ansible_host parameter next to the host entry to specify its
IP address.
Verification
Additional resources
Scope of support for the Ansible Core package included in the RHEL 9 and RHEL 8.6 and later
AppStream repositories
How to register and subscribe a system to the Red Hat Customer Portal using subscription-
manager
11
Red Hat Enterprise Linux 9 Configuring basic system settings
However, direct SSH access as the root user can be a security risk. Therefore, when you prepare a
managed node, you create a local user on this node and configure a sudo policy. Ansible on the control
node can then use this account to log in to the managed node and execute playbooks as different users,
such as root.
Prerequisites
Procedure
1. Create a user:
The control node later uses this user to establish an SSH connection to this host.
You must enter this password when Ansible uses sudo to perform tasks as the root user.
3. Install the ansible user’s SSH public key on the managed node:
a. Log into the control node as the ansible user, and copy the SSH public key to the managed
node:
12
CHAPTER 1. PREPARING A CONTROL NODE AND MANAGED NODES TO USE RHEL SYSTEM ROLES
b. Remotely execute a command on the control node to verify the SSH connection:
a. Use the visudo command to create and edit the /etc/sudoers.d/ansible file:
The benefit of using visudo over a normal editor is that this utility provides basic sanity
checks and checks for parse errors before installing the file.
These settings grant permissions to the ansible user to run all commands as any user and
group on this host without entering the password of the ansible user.
Additional resources
Prerequisites
You prepared at least one managed node as described in Preparing a managed node .
If you want to run playbooks on host groups, the managed node is listed in the inventory file on
the control node.
Procedure
13
Red Hat Enterprise Linux 9 Configuring basic system settings
1. Use the Ansible ping module to verify that you can execute commands on an all managed hosts:
The hard-coded all host group dynamically contains all hosts listed in the inventory file.
2. Use the Ansible command module to run the whoami utility on a managed host:
If the command returns root, you configured sudo on the managed nodes correctly, and
privilege escalation works.
14
CHAPTER 2. CHANGING BASIC ENVIRONMENT SETTINGS
System locales
Keyboard layout
Language
Red Hat Enterprise Linux 8 and later versions use the chronyd daemon to implement NTP. chronyd is
available from the chrony package. For more information, see Using the chrony suite to configure NTP .
Procedure
$ date
Mon Mar 30 16:02:59 CEST 2020
$ timedatectl
Local time: Mon 2020-03-30 16:04:42 CEST
Universal time: Mon 2020-03-30 14:04:42 UTC
RTC time: Mon 2020-03-30 14:04:41
Time zone: Europe/Prague (CEST, +0200)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
Additional resources
System-wide locale settings are stored in the /etc/locale.conf file, which is read at early boot by the
15
Red Hat Enterprise Linux 9 Configuring basic system settings
System-wide locale settings are stored in the /etc/locale.conf file, which is read at early boot by the
systemd daemon. Every service or user inherits the locale settings configured in /etc/locale.conf, unless
individual programs or individual users override them.
Procedure
$ localectl list-locales
C.utf8
aa_DJ
aa_DJ.iso88591
aa_DJ.utf8
...
$ localectl status
To set or change the default system locale settings, use a localectl set-locale sub-command as
the root user. For example:
Additional resources
Procedure
$ localectl list-keymaps
ANSI-dvorak
al
al-plisi
amiga-de
amiga-us
...
$ localectl status
...
VC Keymap: us
...
16
CHAPTER 2. CHANGING BASIC ENVIRONMENT SETTINGS
# localectl set-keymap us
Additional resources
Prerequisites
Procedure
1. Open the GNOME Control Center from the System menu by clicking on its icon.
2. In the GNOME Control Center, choose Region & Language from the left vertical bar.
17
Red Hat Enterprise Linux 9 Configuring basic system settings
If your region and language are not listed, scroll down, and click More to select from available
regions and languages.
5. Click Done.
18
CHAPTER 2. CHANGING BASIC ENVIRONMENT SETTINGS
NOTE
Some applications do not support certain languages. The text of an application that
cannot be translated into the selected language remains in US English.
Additional resources
19
Red Hat Enterprise Linux 9 Configuring basic system settings
Procedure
1. From the Installation Summary window, click Network and Host Name.
2. From the list in the left-hand pane, select an interface. The details are displayed in the right-
hand pane.
NOTE
There are several types of network device naming standards used to identify
network devices with persistent names, for example, em1 and wl3sp0. For
information about these standards, see the Configuring and managing
networking document.
NOTE
4. Click + to add a virtual network interface, which can be either: Team (deprecated), Bond, Bridge,
or VLAN.
6. Click Configure to change settings such as IP addresses, DNS servers, or routing configuration
for an existing interface (both virtual and physical).
7. Type a host name for your system in the Host Name field.
NOTE
20
CHAPTER 3. CONFIGURING AND MANAGING NETWORK ACCESS
NOTE
The host name can be either a fully-qualified domain name (FQDN) in the
format hostname.domainname, or a short host name with no domain name.
Many networks have a Dynamic Host Configuration Protocol (DHCP) service
that automatically supplies connected systems with a domain name. To allow
the DHCP service to assign the domain name to this machine, specify only
the short host name. The value localhost means that no specific static host
name for the target system is configured, and the actual host name of the
installed system is configured during the processing of the network
configuration, for example, by NetworkManager using DHCP or DNS.
9. Alternatively, in the Network and Hostname window, you can choose the Wireless option. Click
Select network in the right-hand pane to select your wifi connection, enter the password if
required, and click Done.
Additional resources
Procedure
The further steps modify the Example-Connection connection profile you created.
21
Red Hat Enterprise Linux 9 Configuring basic system settings
To set multiple DNS servers, specify them space-separated and enclosed in quotes.
7. Set the DNS search domain for the IPv4 and IPv6 connection:
Verification steps
2. Use the ping utility to verify that this host can send packets to other hosts:
# ping host_name_or_IP_address
Troubleshooting
Make sure that the network cable is plugged-in to the host and a switch.
Check whether the link failure exists only on this host or also on other hosts connected to the
same switch.
Verify that the network cable and the network interface are working as expected. Perform
22
CHAPTER 3. CONFIGURING AND MANAGING NETWORK ACCESS
Verify that the network cable and the network interface are working as expected. Perform
hardware diagnosis steps and replace defect cables and network interface cards.
If the configuration on the disk does not match the configuration on the device, starting or
restarting NetworkManager creates an in-memory connection that reflects the configuration of
the device. For further details and how to avoid this problem, see NetworkManager duplicates a
connection after restart of NetworkManager service.
Additional resources
NOTE
In nmtui:
Procedure
1. If you do not know the network device name you want to use in the connection, display the
available devices:
2. Start nmtui:
# nmtui
5. Select Ethernet from the list of network types, and press Enter.
23
Red Hat Enterprise Linux 9 Configuring basic system settings
8. Press the OK button to create and automatically activate the new connection.
10. Select Quit, and press Enter to close the nmtui application.
Verification
2. Use the ping utility to verify that this host can send packets to other hosts:
# ping host_name_or_IP_address
Troubleshooting
Make sure that the network cable is plugged-in to the host and a switch.
Check whether the link failure exists only on this host or also on other hosts connected to the
same switch.
Verify that the network cable and the network interface are working as expected. Perform
hardware diagnosis steps and replace defect cables and network interface cards.
If the configuration on the disk does not match the configuration on the device, starting or
restarting NetworkManager creates an in-memory connection that reflects the configuration of
the device. For further details and how to avoid this problem, see NetworkManager duplicates a
connection after restart of NetworkManager service.
Additional resources
The nmtui application provides a text-based user interface for NetworkManager. You can use nmtui to
24
CHAPTER 3. CONFIGURING AND MANAGING NETWORK ACCESS
The nmtui application provides a text-based user interface for NetworkManager. You can use nmtui to
configure an Ethernet connection with a static IP address on a host without a graphical interface.
NOTE
In nmtui:
Procedure
1. If you do not know the network device name you want to use in the connection, display the
available devices:
2. Start nmtui:
# nmtui
5. Select Ethernet from the list of network types, and press Enter.
8. Configure the IPv4 and IPv6 address settings in the IPv4 configuration and IPv6
configuration areas:
a. Press the Automatic button, and select Manual from the displayed list.
b. Press the Show button next to the protocol you want to configure to display additional
fields.
c. Press the Add button next to Addresses, and enter the IP address and the subnet mask in
Classless Inter-Domain Routing (CIDR) format.
If you do not specify a subnet mask, NetworkManager sets a /32 subnet mask for IPv4
addresses and /64 for IPv6 addresses.
e. Press the Add button next to DNS servers, and enter the DNS server address.
f. Press the Add button next to Search domains, and enter the DNS search domain.
9. Press the OK button to create and automatically activate the new connection.
11. Select Quit, and press Enter to close the nmtui application.
Verification
26
CHAPTER 3. CONFIGURING AND MANAGING NETWORK ACCESS
2. Use the ping utility to verify that this host can send packets to other hosts:
# ping host_name_or_IP_address
Troubleshooting
Make sure that the network cable is plugged-in to the host and a switch.
Check whether the link failure exists only on this host or also on other hosts connected to the
same switch.
Verify that the network cable and the network interface are working as expected. Perform
hardware diagnosis steps and replace defect cables and network interface cards.
If the configuration on the disk does not match the configuration on the device, starting or
restarting NetworkManager creates an in-memory connection that reflects the configuration of
the device. For further details and how to avoid this problem, see NetworkManager duplicates a
connection after restart of NetworkManager service.
Additional resources
27
Red Hat Enterprise Linux 9 Configuring basic system settings
Ethernet
Bridge
Bonded
VLAN
MacVLAN
InfiniBand
The required networking connections for each host are provided as a list within the
network_connections variable.
WARNING
The network role updates or creates all connection profiles on the target system
exactly as specified in the network_connections variable. Therefore, the network
role removes options from the specified profiles if the options are only present on
the system but not in the network_connections variable.
The following example shows how to apply the network role to ensure that an Ethernet connection with
the required parameters exists:
An example playbook applying the network role to set up an Ethernet connection with the
required parameters
# SPDX-License-Identifier: BSD-3-Clause
---
- hosts: managed-node-01.example.com
vars:
network_connections:
28
CHAPTER 3. CONFIGURING AND MANAGING NETWORK ACCESS
roles:
- rhel-system-roles.network
Additional resources
Preparing a control node and managed nodes to use RHEL System Roles
29
Red Hat Enterprise Linux 9 Configuring basic system settings
You can use a subscription to Red Hat Content Delivery Network to track:
Registered systems
Prerequisites
For more information about the installation process, see Performing a standard RHEL 9
installation.
Procedure
The command prompts you to enter your Red Hat Customer Portal user name and password.
If the registration process fails, you can register your system with a specific pool. For guidance
on how to do it, proceed with the following steps:
This command displays all available subscriptions for your Red Hat account. For every
subscription, various characteristics are displayed, including the pool ID.
30
CHAPTER 4. REGISTERING THE SYSTEM AND MANAGING SUBSCRIPTIONS
b. Attach the appropriate subscription to your system by replacing pool_id with the pool ID
determined in the previous step:
NOTE
To register the system with Red Hat Insights, you can use the rhc connect utility. See
Setting up Red Hat connector .
Additional resources
Prerequisites
Procedure
1. Log in to the RHEL web console. For details, see Logging in to the web console .
2. In the Health filed in the Overview page, click the Not registered warning, or click
Subscriptions in the main menu to move to page with your subscription information.
31
Red Hat Enterprise Linux 9 Configuring basic system settings
4. In the Register system dialog box, select that you want to register using your account
credentials.
If you do not want to connect your system to Red Hat Insights, uncheck the Insights check
box.
At this point, your Red Hat Enterprise Linux system has been successfully registered.
32
CHAPTER 4. REGISTERING THE SYSTEM AND MANAGING SUBSCRIPTIONS
Prerequisites
Procedure
1. Open the system menu, which is accessible from the upper-right screen corner, and click
Settings.
2. Go to About → Subscription.
Enter your Red Hat account user name in the Login field.
6. Click Register.
Prerequisites
Procedure
1. Open the system menu, which is accessible from the upper-right screen corner, and click
Settings.
2. Go to About → Subscription.
33
Red Hat Enterprise Linux 9 Configuring basic system settings
6. Click Register.
34
CHAPTER 5. MAKING SYSTEMD SERVICES START AT BOOT TIME
Prerequisites
The service you want to enable must not be masked. If you have a masked service, you must
unmask it first:
Procedure
35
Red Hat Enterprise Linux 9 Configuring basic system settings
This section covers only the basic security features that you can configure after installation of the
operating system.
The firewalld service, which provides a firewall in Red Hat Enterprise Linux, is automatically enabled
during installation.
Procedure
If firewalld is not enabled and running, switch to the root user, and start the firewalld service
and enable to start it automatically after the system restarts:
Verification steps
Additional resources
man firewalld(1)
36
CHAPTER 6. CONFIGURING SYSTEM SECURITY
Disabled
Enabled
Enabled
Enforcing
Permissive
In enforcing mode, SELinux enforces the loaded policies. SELinux denies access based on SELinux
policy rules and enables only the interactions that are explicitly allowed. Enforcing mode is the safest
SELinux mode and is the default mode after installation.
In permissive mode, SELinux does not enforce the loaded policies. SELinux does not deny access, but
reports actions that break the rules to the /var/log/audit/audit.log log. Permissive mode is the default
mode during installation. Permissive mode is also useful in some specific cases, for example when
troubleshooting problems.
Additional resources
Using SELinux
IMPORTANT
Red Hat recommends to keep your system in enforcing mode. For debugging purposes,
you can set SELinux to permissive mode.
Follow this procedure to change the state and mode of SELinux on your system.
Procedure
$ getenforce
a. To Enforcing mode:
37
Red Hat Enterprise Linux 9 Configuring basic system settings
# setenforce Enforcing
b. To Permissive mode:
# setenforce Permissive
NOTE
3. To set SELinux mode to persist across reboots, modify the SELINUX variable in the
/etc/selinux/config configuration file.
For example, to switch SELinux to enforcing mode:
WARNING
Additional resources
Security hardening
Using SELinux
Securing networks
38
CHAPTER 7. GETTING STARTED WITH MANAGING USER ACCOUNTS
WARNING
For system accounts, user IDs below 1000 are reserved. For normal accounts, you can use IDs
starting at 1000. However, the recommended practice is to assign IDs starting at 5000. For
assigning IDs, see the /etc/login.defs file.
Group:
A group is an entity which ties together multiple user accounts for a common purpose, such as
granting access to particular files.
$ id
uid=1000(example.user) gid=1000(example.user) groups=1000(example.user),10(wheel)
context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
# useradd example.user
39
Red Hat Enterprise Linux 9 Configuring basic system settings
# passwd example.user
Additional resources
The RHEL web console displays all user accounts located in the system. Therefore, you can see at least
one user account just after the first login to the web console.
After logging into the RHEL web console, you can perform the following operations:
Lock accounts.
Prerequisites
The RHEL web console must be installed and accessible. For details, see Installing the web
console.
Procedure
2. Click Accounts.
1. In the Full Name field, enter the full name of the user.
The RHEL web console automatically suggests a user name from the full name and fills it in the
40
CHAPTER 7. GETTING STARTED WITH MANAGING USER ACCOUNTS
The RHEL web console automatically suggests a user name from the full name and fills it in the
User Name field. If you do not want to use the original naming convention consisting of the first
letter of the first name and the whole surname, update the suggestion.
2. In the Password/Confirm fields, enter the password and retype it for verification that your
password is correct.
The color bar placed below the fields shows you security level of the entered password, which
does not allow you to create a user with a weak password.
1. Click Create to save the settings and close the dialog box.
Now you can see the new account in the Accounts settings and you can use the credentials to
connect to the system.
41
Red Hat Enterprise Linux 9 Configuring basic system settings
IMPORTANT
A kernel crash dump can be the only information available in the event of a system failure
(a critical bug). Therefore, operational kdump is important in mission-critical
environments. Red Hat advise that system administrators regularly update and test
kexec-tools in your normal kernel update cycle. This is especially important when new
kernel features are implemented.
You can enable kdump for all installed kernels on a machine or only for specified kernels. This is useful
when there are multiple kernels used on a machine, some of which are stable enough that there is no
concern that they could crash.
When kdump is installed, a default /etc/kdump.conf file is created. The file includes the default
minimum kdump configuration. You can edit this file to customize the kdump configuration, but it is not
required.
Procedure
1. Open the Kernel Dump tab and start the kdump service.
42
CHAPTER 8. DUMPING A CRASHED KERNEL FOR LATER ANALYSIS
4. Select the Local Filesystem option from the drop-down and specify the directory you want to
save the dump in.
Alternatively, select the Remote over SSH option from the drop-down to send the vmcore
to a remote machine using the SSH protocol.
Fill the Server, ssh key, and Directory fields with the remote machine address, ssh key
location, and a target directory.
Another choice is to select the Remote over NFS option from the drop-down and fill the
Mount field to send the vmcore to a remote machine using the NFS protocol.
NOTE
Tick the Compression check box to reduce the size of the vmcore file.
43
Red Hat Enterprise Linux 9 Configuring basic system settings
WARNING
This step disrupts execution of the kernel and results in a system crash
and loss of data.
Additional resources
WARNING
The kdump role replaces the kdump configuration of the managed hosts entirely
by replacing the /etc/kdump.conf file. Additionally, if the kdump role is applied, all
previous kdump settings are also replaced, even if they are not specified by the role
variables, by replacing the /etc/sysconfig/kdump file.
The following example playbook shows how to apply the kdump system role to set the location of the
44
CHAPTER 8. DUMPING A CRASHED KERNEL FOR LATER ANALYSIS
The following example playbook shows how to apply the kdump system role to set the location of the
crash dump files:
---
- hosts: kdump-test
vars:
kdump_path: /var/crash
roles:
- rhel-system-roles.kdump
For a detailed reference on kdump role variables, install the rhel-system-roles package, and see the
README.md or README.html files in the /usr/share/doc/rhel-system-roles/kdump directory.
Additional resources
45
Red Hat Enterprise Linux 9 Configuring basic system settings
You can use the utility as a disaster recovery solution and also for system migration.
Produce a bootable image and restore the system from an existing backup, using the image.
Additionally, for disaster recovery, you can also integrate certain backup software with ReaR.
1. Install ReaR.
Prerequisites
Procedure
2. Modify the ReaR configuration file in an editor of your choice, for example:
# vi /etc/rear/local.conf
3. Add the backup setting details to /etc/rear/local.conf. For example, in the case of the NETFS
backup method, add the following lines:
BACKUP=NETFS
BACKUP_URL=backup.location
46
CHAPTER 9. RECOVERING AND RESTORING A SYSTEM
4. To configure ReaR to keep the previous backup archive when the new one is created, also add
the following line to the configuration file:
NETFS_KEEP_OLD_BACKUP_COPY=y
5. To make the backups incremental, meaning that only the changed files are backed up on each
run, add the following line:
BACKUP_TYPE=incremental
# rear mkrescue
7. Take a backup as per the restore plan. For example, in the case of the NETFS backup method,
run the following command:
# rear mkbackuponly
Alternatively, you can create the rescue system and the backup in a single step by running the
following command:
# rear mkbackup
This command combines the functionality of the rear mkrescue and rear mkbackuponly
commands.
IMPORTANT
ReaR on the 64-bit IBM Z architecture is a Technology Preview feature only. Technology
Preview features are not supported with Red Hat production service level agreements
(SLAs) and might not be functionally complete. Red Hat does not recommend using
them in production. These features provide early access to upcoming product features,
enabling customers to test functionality and provide feedback during the development
process. For more information about the support scope of Red Hat Technology Preview
features, see https://access.redhat.com/support/offerings/techpreview.
The only output method currently available is Initial Program Load (IPL). IPL produces a kernel and an
initial ramdisk (initrd) that can be used with the zIPL bootloader.
Prerequisites
47
Red Hat Enterprise Linux 9 Configuring basic system settings
ReaR is installed.
Procedure
Add the following variables to the /etc/rear/local.conf to configure ReaR for producing a rescue image
on the 64-bit IBM Z architecture:
2. To configure the backup method and destination, add BACKUP and BACKUP_URL variables.
For example:
BACKUP=NETFS
IMPORTANT
The local backup storage is currently not supported on the 64-bit IBM Z
architecture.
3. Optionally, you can also configure the OUTPUT_URL variable to save the kernel and initrd files.
By default, the OUTPUT_URL is aligned with BACKUP_URL.
rear mkbackup
5. This creates the kernel and initrd files at the location specified by the BACKUP_URL or
OUTPUT_URL (if set) variable, and a backup using the specified backup method.
6. To recover the system, use the ReaR kernel and initrd files created in step 3, and boot from a
Direct Attached Storage Device (DASD) or a Fibre Channel Protocol (FCP)-attached SCSI
device prepared with the zipl boot loader, kernel, and initrd. For more information, see Using a
Prepared DASD.
7. When the rescue kernel and initrd get booted, it starts the ReaR rescue environment. Proceed
with system recovery.
WARNING
Currently, the rescue process reformats all the DASDs (Direct Attached Storage
Devices) connected to the system. Do not attempt a system recovery if there is any
valuable data present on the system storage devices. This also includes the device
prepared with the zipl bootloader, ReaR kernel, and initrd that were used to boot
into the rescue environment. Ensure to keep a copy.
Additional resources
48
CHAPTER 9. RECOVERING AND RESTORING A SYSTEM
49
Red Hat Enterprise Linux 9 Configuring basic system settings
The systemd-journald daemon collects messages from various sources and forwards them to Rsyslog
for further processing. The systemd-journald daemon collects messages from the following sources:
Kernel
Syslog
The Rsyslog service sorts the syslog messages by type and priority and writes them to the files in the
/var/log directory. The /var/log directory persistently stores the log messages.
Procedure
1. Log into the RHEL web console. For details see Logging in to the web console .
2. Click Logs.
Figure 10.1. Inspecting the log files in the RHEL 9 web console
50
CHAPTER 10. TROUBLESHOOTING PROBLEMS USING LOG FILES
Figure 10.1. Inspecting the log files in the RHEL 9 web console
You can use the journalctl command to view messages in the system journal using the command line,
for example:
Command Description
journalctl FILEPATH Shows logs related to a specific file. For example, the
journalctl /dev/sda command displays logs related
to the /dev/sda file system.
Command Description
journalctl -b _SYSTEMD_UNIT=foo Filters log to see ones matching the "foo" systemd
service.
51
Red Hat Enterprise Linux 9 Configuring basic system settings
Command Description
Command Description
journalctl --list-boots Shows a tabular list of boot numbers, their IDs, and
the timestamps of the first and last message
pertaining to the boot. You can use the ID in the next
command to view detailed information.
journalctl --boot=ID _SYSTEMD_UNIT=foo Shows information about the specified boot ID.
52
CHAPTER 11. ACCESSING THE RED HAT SUPPORT
To obtain support from Red Hat, use the Red Hat Customer Portal, which provides access to everything
available with your subscription.
Prerequisites
A valid user account on the Red Hat Customer Portal. See Create a Red Hat Login .
Procedure
The following section describes how to use the sosreport command to produce reports for your support
cases.
Prerequisites
A valid user account on the Red Hat Customer Portal. See Create a Red Hat Login .
A support-case number.
Procedure
NOTE
53
Red Hat Enterprise Linux 9 Configuring basic system settings
NOTE
The default minimal installation of Red Hat Enterprise Linux does not include the
sos package, which provides the sosreport command.
2. Generate a report:
# sosreport
Note that when attaching the report, you are prompted to enter the number of the relevant
support case.
Additional resources
What is an sosreport and how to create one in Red Hat Enterprise Linux?
54
CHAPTER 12. INTRODUCTION TO SYSTEMD
As a representation of system resources and services, systemd introduces the concept of systemd
units. A systemd unit, which performs or controls a particular task, is the basic object that systemd
manages. See the following examples of various systemd unit types:
service,
target,
device,
mount,
timer,
NOTE
# systemctl -t help
A systemd unit consists of a name, type and a configuration file, which defines the task of the unit. The
unit configuration files are located in one of the directories listed in the following table:
Directory Description
55
Red Hat Enterprise Linux 9 Configuring basic system settings
Directory Description
The default configuration of systemd is defined during the compilation and you can find the
configuration in the /etc/systemd/system.conf file. Use this file if you want to deviate from those
defaults and override selected default values for systemd units globally.
For example, to override the default value of the timeout limit, which is set to 90 seconds, use the
DefaultTimeoutStartSec parameter to input the required value in seconds.
DefaultTimeoutStartSec=required value
56
CHAPTER 13. MANAGING SYSTEM SERVICES WITH SYSTEMCTL
Procedure
46 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'
By default, the systemctl list-units command displays only active units. For each service unit
file, the command displays:
ACTIVE or SUB: its high-level and low-level unit file activation state
To list all loaded units regardless of their state, enter the following command with the --all or
-a command line option:
To list the status (enabled or disabled) of all available service units, enter:
57
Red Hat Enterprise Linux 9 Configuring basic system settings
abrtd.service enabled
...
wpa_supplicant.service disabled
ypbind.service disabled
Additional resources
Procedure
To display detailed information about a service unit that corresponds to a system service, enter:
Replace <name> with the name of the service unit you want to inspect (for example, gdm).
This command displays the name of the selected service unit followed by its short description,
one or more fields described in Available service unit information , if it is executed by the root
user, and the most recent log entries.
Field Description
58
CHAPTER 13. MANAGING SYSTEM SERVICES WITH SYSTEMCTL
Field Description
The service unit for the GNOME Display Manager is named gdm.service. To determine the
current status of this service unit, type the following at a shell prompt:
NOTE
To determine what services are ordered to start before the specified service unit, enter:
For example, to view the list of services ordered to start before gdm, enter:
59
Red Hat Enterprise Linux 9 Configuring basic system settings
├─livesys.service
├─plymouth-quit.service
├─system.slice
├─systemd-journald.socket
├─systemd-user-sessions.service
└─basic.target
[output truncated]
To determine what services are ordered to start after the specified service unit, enter:
For example, to view the list of services ordered to start after gdm, enter:
Additional resources
Prerequisites
Procedure
To start a selected service unit corresponding to a system service, type the following command
as root:
Replace <name> with the name of the service unit you want to start (for example,
httpd.service).
The service unit for the Apache HTTP Server is named httpd.service. To activate this service
60
CHAPTER 13. MANAGING SYSTEM SERVICES WITH SYSTEMCTL
The service unit for the Apache HTTP Server is named httpd.service. To activate this service
unit and start the httpd daemon in the current session, enter the following command as root:
NOTE
When you attempt to start a new service, systemd resolves all dependencies
automatically, without explicit notification to the user. This means that if you are
already running a service, and you attempt to start another service with a
negative dependency, the first service is automatically stopped.
For example, if you are running the postfix service, and you attempt to start the
sendmail service, systemd first automatically stops postfix, because these two
services are conflicting and cannot run on the same port.
Additional resources
Prerequisites
Procedure
To stop the service unit corresponding to a system service, enter the following command as
root:
Replace <name> with the name of the service unit you want to stop (for example, bluetooth).
The service unit for the bluetoothd daemon is named bluetooth.service. To deactivate this
service unit and stop the bluetoothd daemon in the current session, enter the following
command as root:
61
Red Hat Enterprise Linux 9 Configuring basic system settings
Additional resources
Stop the selected service unit in the current session and immediately start it again
Prerequisites
Procedure
Replace <name> with the name of the service unit you want to restart (for example, httpd).
NOTE
If the selected service unit is not running, this command starts it too.
Alternatively, restart a service unit only if the corresponding service is already running:
NOTE
System services that do not support this feature, ignore this command. To restart
such services, use the reload-or-restart and reload-or-try-restart commands
instead.
62
CHAPTER 13. MANAGING SYSTEM SERVICES WITH SYSTEMCTL
rendered web pages, the Apache HTTP Server allows you to edit and reload its configuration
without the need to restart it and interrupt actively processed requests. To do so, use the
following command:
Additional resources
Prerequisites
Procedure
Replace <name> with the name of the service unit you want to enable (for example, httpd).
Alternatively, if you want to ensure that the symbolic links are re-created, reenable the system
unit:
This command disables the selected service unit and immediately enables it again.
To configure the Apache HTTP Server to start automatically at boot time, use the following
command:
Additional resources
63
Red Hat Enterprise Linux 9 Configuring basic system settings
Prerequisites
Procedure
To configure a service unit that corresponds to a system service not to start automatically at
boot time, enter the following command as root:
Replace <name> with the name of the service unit you want to disable (for example, bluetooth).
The service unit for the bluetoothd daemon is named bluetooth.service. To prevent this
service unit from starting at boot time, enter the following command as a root:
Alternatively, you can mask any service unit and prevent it from being started manually or by
another service:
Additional resources
64
CHAPTER 14. WORKING WITH SYSTEMD TARGETS
The graphical.target unit for starting a graphical session, starts system services such as the
GNOME Display Manager (gdm.service) or Accounts Service (accounts-daemon.service),
and also activates the multi-user.target unit.
Similarly, the multi-user.target unit starts other essential system services such as
NetworkManager (NetworkManager.service) or D-Bus (dbus.service) and activates another
target unit named basic.target.
While working with systemd targets, you can view the default target, change it or change the current
target.
Procedure
$ systemctl get-default
graphical.target
$ ls -l /usr/lib/systemd/system/default.target
Procedure
65
Red Hat Enterprise Linux 9 Configuring basic system settings
Procedure
# systemctl get-default
66
CHAPTER 14. WORKING WITH SYSTEMD TARGETS
3. Reboot
# reboot
Additional resources
Procedure
# ls -l /etc/systemd/system/default.target
Note that in certain cases, the /etc/systemd/system/default.target link might not exist, and
systemd looks for the default target unit in /usr. In such cases, determine the default target unit
using the following command:
# ls -l /usr/lib/systemd/system/default.target
# rm /etc/systemd/system/default.target
# reboot
Verification steps
67
Red Hat Enterprise Linux 9 Configuring basic system settings
$ systemctl get-default
multi-user.target
Procedure
This command starts the target unit named multi-user and all dependent units, and immediately
stops all others.
Replace multi-user with the name of the target unit you want to use by default.
Verification steps
$ systemctl get-default
multi-user.target
Procedure
To enter the rescue mode, change the current target in the current session:
# systemctl rescue
NOTE
68
CHAPTER 14. WORKING WITH SYSTEMD TARGETS
NOTE
To prevent systemd from sending a message, run the following command with
the --no-wall command-line option:
Procedure
# systemctl emergency
NOTE
To prevent systemd from sending this message, run the following command with
the --no-wall command-line option:
69
Red Hat Enterprise Linux 9 Configuring basic system settings
Additional resources
Prerequisites
Procedure
To shut down the system and power off the machine at a certain time, use the command in the
following format:
Where hh:mm is the time in 24 hour clock format. The /run/nologin file is created 5 minutes
before system shutdown to prevent new logins.
When a time argument is used, an optional wall message can be appended to the command.
Alternatively, to shut down and halt the system after a delay, without powering off the machine,
use:
70
CHAPTER 15. SHUTTING DOWN, SUSPENDING, AND HIBERNATING THE SYSTEM
shutdown --halt +m
Where +m is the delay time in minutes. The now keyword is an alias for +0.
shutdown -c
Additional resources
Prerequisites
Procedure
To shut down the system and power off the machine, use the command in the following format:
systemctl poweroff
Alternatively, to shut down and halt the system without powering off the machine, use:
systemctl halt
NOTE
Additional resources
Prerequisites
71
Red Hat Enterprise Linux 9 Configuring basic system settings
Procedure
systemctl reboot
NOTE
By default, this command causes systemd to send an informative message to all users
that are currently logged into the system. To prevent systemd from sending this
message, run this command with the --no-wall command line option.
Prerequisites
Procedure
systemctl suspend
This command saves the system state in RAM and with the exception of the RAM module,
powers off most of the devices in the machine. When you turn the machine back on, the system
then restores its state from RAM without having to boot again.
Because the system state is saved in RAM and not on the hard disk, restoring the system from
suspend mode is significantly faster than from hibernation. However, note that the suspended
system state is also vulnerable to power outages.
Additional resources
Prerequisites
Procedure
72
CHAPTER 15. SHUTTING DOWN, SUSPENDING, AND HIBERNATING THE SYSTEM
systemctl hibernate
This command saves the system state on the hard disk drive and powers off the machine. When
you turn the machine back on, the system then restores its state from the saved data without
having to boot again.
Because the system state is saved on the hard disk and not in RAM, the machine does not have
to maintain electrical power to the RAM module. However, as a consequence, restoring the
system from hibernation is significantly slower than restoring it from suspend mode.
Alternatively, to hibernate and suspend the system, run the following command:
systemctl hybrid-sleep
Additional resources
73
Red Hat Enterprise Linux 9 Configuring basic system settings
unit_name.type_extension
Here, unit_name stands for the name of the unit and type_extension identifies the unit type. For a
complete list of unit types, see systemd unit files
For example, there usually is sshd.service as well as sshd.socket unit present on your system.
Unit files can be supplemented with a directory for additional configuration files. For example, to add
custom configuration options to sshd.service, create the sshd.service.d/custom.conf file and insert
additional directives there. For more information on configuration directories, see Modifying existing unit
files.
Many unit file options can be set using the so called unit specifiers – wildcard strings that are
dynamically replaced with unit parameters when the unit file is loaded. This enables creation of generic
unit files that serve as templates for generating instantiated units. See Working with instantiated units .
The [Unit] section — contains generic options that are not dependent on the type of the unit.
These options provide unit description, specify the unit’s behavior, and set dependencies to
other units. For a list of most frequently used [Unit] options, see Important [Unit] section
options.
The [Unit type] section — if a unit has type-specific directives, these are grouped under a
section named after the unit type. For example, service unit files contain the [Service] section.
74
CHAPTER 16. WORKING WITH SYSTEMD UNIT FILES
The [Install] section — contains information about unit installation used by systemctl enable
and disable commands. For a list of options for the [Install] section, see Important [Install]
section options.
Additional resources
After [b] Defines the order in which units are started. The unit
starts only after the units specified in After are
active. Unlike Requires, After does not explicitly
activate the specified units. The Before option has
the opposite functionality to After .
[a] For a complete list of options configurable in the [Unit] section, see the systemd.unit(5) manual page.
[b] In most cases, it is sufficient to set only the ordering dependencies with After and Before unit file options. If you also
set a requirement dependency with Wants (recommended) or Requires, the ordering dependency still needs to be
specified. That is because ordering and requirement dependencies work independently from each other.
75
Red Hat Enterprise Linux 9 Configuring basic system settings
76
CHAPTER 16. WORKING WITH SYSTEMD UNIT FILES
[a] For a complete list of options configurable in the [Service] section, see the systemd.service(5) manual page.
RequiredBy A list of units that depend on the unit. When this unit
is enabled, the units listed in RequiredBy gain a
Require dependency on the unit.
[a] For a complete list of options configurable in the [Install] section, see the systemd.unit(5) manual page.
On the other hand, if you intend just to modify or extend the behavior of an existing unit, use the
77
Red Hat Enterprise Linux 9 Configuring basic system settings
On the other hand, if you intend just to modify or extend the behavior of an existing unit, use the
instructions from Modifying existing unit files .
Procedure
The following procedure describes the general process of creating a custom service:
1. Prepare the executable file with the custom service. This can be a custom-created script, or an
executable delivered by a software provider. If required, prepare a PID file to hold a constant
PID for the main process of the custom service. It is also possible to include environment files to
store shell variables for the service. Make sure the source script is executable (by executing the
chmod a+x) and is not interactive.
2. Create a unit file in the /etc/systemd/system/ directory and make sure it has correct file
permissions. Execute as root:
touch /etc/systemd/system/name.service
Replace name with a name of the service to be created. Note that file does not need to be
executable.
3. Open the name.service file created in the previous step, and add the service configuration
options. There is a variety of options that can be used depending on the type of service you wish
to create, see Unit file structure.
The following is an example unit configuration for a network-related service:
[Unit]
Description=service_description
After=network.target
[Service]
ExecStart=path_to_executable
Type=forking
PIDFile=path_to_pidfile
[Install]
WantedBy=default.target
Where:
the After setting ensures that the service is started only after the network is running. Add a
space-separated list of other relevant services or targets.
Type=forking is used for daemons that make the fork system call. The main process of the
service is created with the PID specified in path_to_pidfile. Find other startup types in
Important [Service] section options .
WantedBy states the target or targets that the service should be started under. Think of
these targets as of a replacement of the older concept of runlevels.
78
CHAPTER 16. WORKING WITH SYSTEMD UNIT FILES
4. Notify systemd that a new name.service file exists by executing the following command as
root:
systemctl daemon-reload
WARNING
Procedure
1. Create a copy of the sshd_config file that will be used by the second daemon:
# cp /etc/ssh/sshd{,-second}_config
2. Edit the sshd-second_config file created in the previous step to assign a different port number
and PID file to the second daemon:
Port 22220
PidFile /var/run/sshd-second.pid
See the sshd_config(5) manual page for more information on Port and PidFile options. Make
sure the port you choose is not in use by any other service. The PID file does not have to exist
before running the service, it is generated automatically on service start.
3. Create a copy of the systemd unit file for the sshd service:
# cp /usr/lib/systemd/system/sshd.service /etc/systemd/system/sshd-second.service
79
Red Hat Enterprise Linux 9 Configuring basic system settings
b. Add sshd.service to services specified in the After option, so that the second instance starts
only after the first one has already started:
c. The first instance of sshd includes key generation, therefore remove the
ExecStartPre=/usr/sbin/sshd-keygen line.
[Unit]
Description=OpenSSH server second instance daemon
After=syslog.target network.target auditd.service sshd.service
[Service]
EnvironmentFile=/etc/sysconfig/sshd
ExecStart=/usr/sbin/sshd -D -f /etc/ssh/sshd-second_config $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
5. If using SELinux, add the port for the second instance of sshd to SSH ports, otherwise the
second instance of sshd will be rejected to bind to the port:
If the firewall is in use, make sure that it is configured appropriately in order to allow connections
to the second instance of sshd.
Before taking time to convert a SysV init script to a unit file, make sure that the conversion was not
80
CHAPTER 16. WORKING WITH SYSTEMD UNIT FILES
Before taking time to convert a SysV init script to a unit file, make sure that the conversion was not
already done elsewhere. All core services installed on Red Hat Enterprise Linux come with default unit
files, and the same applies for many third-party software packages.
Converting an init script to a unit file requires analyzing the script and extracting the necessary
information from it. Based on this data you can create a unit file. As init scripts can vary greatly
depending on the type of the service, you might need to employ more configuration options for
translation than outlined in this chapter. Note that some levels of customization that were available with
init scripts are no longer supported by systemd units.
The majority of information needed for conversion is provided in the script’s header. The following
example shows the opening section of the init script used to start the postfix service on Red Hat
Enterprise Linux 6:
#!/bin/bash
# postfix Postfix Mail Transfer Agent
# chkconfig: 2345 80 30
# description: Postfix is a Mail Transport Agent, which is the program that moves mail from one
machine to another.
# processname: master
# pidfile: /var/spool/postfix/pid/master.pid
# config: /etc/postfix/main.cf
# config: /etc/postfix/master.cf
### BEGIN INIT INFO
# Provides: postfix MTA
# Required-Start: $local_fs $network $remote_fs
# Required-Stop: $local_fs $network $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop postfix
# Description: Postfix is a Mail Transport Agent, which is the program that moves mail from one
machine to another.
### END INIT INFO
In the above example, only lines starting with # chkconfig and # description are mandatory, so you
might not find the rest in different init files. The text enclosed between the BEGIN INIT INFO and END
INIT INFO lines is called Linux Standard Base (LSB) header. If specified, LSB headers contain
directives defining the service description, dependencies, and default runlevels. What follows is an
overview of analytic tasks aiming to collect the data needed for a new unit file. The postfix init script is
used as an example.
81
Red Hat Enterprise Linux 9 Configuring basic system settings
The other two values specified on the #chkconfig line represent startup and shutdown priorities of the
init script. These values are interpreted by systemd if it loads the init script, but there is no unit file
equivalent.
The key information that is not included in the init script header is the path to the service executable,
82
CHAPTER 16. WORKING WITH SYSTEMD UNIT FILES
and potentially some other files required by the service. In previous versions of Red Hat Enterprise Linux,
init scripts used a Bash case statement to define the behavior of the service on default actions, such as
start, stop, or restart, as well as custom-defined actions. The following excerpt from the postfix init
script shows the block of code to be executed at service start.
conf_check() {
[ -x /usr/sbin/postfix ] || exit 5
[ -d /etc/postfix ] || exit 6
[ -d /var/spool/postfix ] || exit 5
}
make_aliasesdb() {
if [ "$(/usr/sbin/postconf -h alias_database)" == "hash:/etc/aliases" ]
then
# /etc/aliases.db might be used by other MTA, make sure nothing
# has touched it since our last newaliases call
[ /etc/aliases -nt /etc/aliases.db ] ||
[ "$ALIASESDB_STAMP" -nt /etc/aliases.db ] ||
[ "$ALIASESDB_STAMP" -ot /etc/aliases.db ] || return
/usr/bin/newaliases
touch -r /etc/aliases.db "$ALIASESDB_STAMP"
else
/usr/bin/newaliases
fi
}
start() {
[ "$EUID" != "0" ] && exit 4
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 1
conf_check
# Start daemons.
echo -n $"Starting postfix: "
make_aliasesdb >/dev/null 2>&1
[ -x $CHROOT_UPDATE ] && $CHROOT_UPDATE
/usr/sbin/postfix start 2>/dev/null 1>&2 && success || failure $"$prog start"
RETVAL=$?
[ $RETVAL -eq 0 ] && touch $lockfile
echo
return $RETVAL
}
The extensibility of the init script allowed specifying two custom functions, conf_check() and
make_aliasesdb(), that are called from the start() function block. On closer look, several external files
and directories are mentioned in the above code: the main service executable /usr/sbin/postfix, the
/etc/postfix/ and /var/spool/postfix/ configuration directories, as well as the /usr/sbin/postconf/
directory.
systemd supports only the predefined actions, but enables executing custom executables with
ExecStart, ExecStartPre, ExecStartPost, ExecStop, and ExecReload options. The /usr/sbin/postfix
together with supporting scripts are executed on service start. Converting complex init scripts requires
understanding the purpose of every statement in the script. Some of the statements are specific to the
operating system version, therefore you do not need to translate them. On the other hand, some
adjustments might be needed in the new environment, both in unit file as well as in the service
executable and supporting files.
83
Red Hat Enterprise Linux 9 Configuring basic system settings
Procedure
1. Depending on the extent of the required changes, pick one of the following approaches:
2. To return to the default configuration of the unit, delete custom-created configuration files in
/etc/systemd/system/.
systemctl daemon-reload
The daemon-reload option reloads all unit files and recreates the entire dependency tree, which
is needed to immediately apply any change to a unit file. As an alternative, you can achieve the
same result with the following command, which must be executed under the root user:
init q
4. If the modified unit file belongs to a running service, this service must be restarted to accept
new settings:
IMPORTANT
84
CHAPTER 16. WORKING WITH SYSTEMD UNIT FILES
IMPORTANT
Then manage this service in the same way as a normal systemd service.
For example, to extend the configuration of the network service, do not modify the
/etc/rc.d/init.d/network initscript file. Instead, create new directory
/etc/systemd/system/network.service.d/ and a systemd drop-in file
/etc/systemd/system/network.service.d/my_config.conf. Then, put the modified values
into the drop-in file. Note: systemd knows the network service as network.service,
which is why the created directory must be called network.service.d
Procedure
1. To extend the default unit file with additional configuration options, first create a configuration
directory in /etc/systemd/system/. If extending a service unit, execute the following command
as root:
mkdir /etc/systemd/system/name.service.d/
Replace name with the name of the service you want to extend. The above syntax applies to all
unit types.
2. Create a configuration file in the directory made in the previous step. Note that the file name
must end with the .conf suffix. Type:
touch /etc/systemd/system/name.service.d/config_name.conf
Replace config_name with the name of the configuration file. This file adheres to the normal unit
file structure, therefore all directives must be specified under appropriate sections, see Unit file
structure.
For example, to add a custom dependency, create a configuration file with the following
content:
[Unit]
Requires=new_dependency
After=new_dependency
Where new_dependency stands for the unit to be marked as a dependency. Another example is a
configuration file that restarts the service after its main process exited, with a delay of 30
seconds:
[Service]
Restart=always
RestartSec=30
85
Red Hat Enterprise Linux 9 Configuring basic system settings
It is recommended to create small configuration files focused only on one task. Such files can be
easily moved or linked to configuration directories of other services.
systemctl daemon-reload
systemctl restart name.service
To modify the httpd.service unit so that a custom shell script is automatically executed when starting
the Apache service, perform the following steps.
# mkdir /etc/systemd/system/httpd.service.d/
# touch /etc/systemd/system/httpd.service.d/custom_script.conf
2. Provided that the script you want to start automatically with Apache is located at
/usr/local/bin/custom.sh, insert the following text to the custom_script.conf file:
[Service]
ExecStartPost=/usr/local/bin/custom.sh
# systemctl daemon-reload
NOTE
Procedure
1. To make changes that will persist after updating the package that provides the unit file, first
copy the file to the /etc/systemd/system/ directory. To do so, execute the following command
as root:
cp /usr/lib/systemd/system/name.service /etc/systemd/system/name.service
86
CHAPTER 16. WORKING WITH SYSTEMD UNIT FILES
Where name stands for the name of the service unit you wish to modify. The above syntax
applies to all unit types.
2. Open the copied file with a text editor, and make the desired changes. To apply the unit
changes, execute as root:
systemctl daemon-reload
systemctl restart name.service
Procedure
cp /usr/lib/systemd/system/httpd.service /etc/systemd/system/httpd.service
…
[Service]
…
PrivateTmp=true
TimeoutStartSec=10
[Install]
WantedBy=multi-user.target
…
systemctl daemon-reload
NOTE
87
Red Hat Enterprise Linux 9 Configuring basic system settings
This section describes how to display an overview of overridden or modified unit files.
Procedure
To display an overview of overridden or modified unit files, use the following command:
systemd-delta
For example, the output of the above command can look as follows:
[Install]
WantedBy=multi-user.target
template_name@instance_name.service
Where template_name stands for the name of the template configuration file. Replace instance_name
with the name for the unit instance. Several instances can point to the same template file with
configuration options common for all instances of the unit. Template unit name has the form of:
[email protected] [email protected]
first makes systemd search for given service units. If no such units are found, the part between "@" and
88
CHAPTER 16. WORKING WITH SYSTEMD UNIT FILES
first makes systemd search for given service units. If no such units are found, the part between "@" and
the type suffix is ignored and systemd searches for the [email protected] file, reads the configuration
from it, and starts the services.
[Unit]
Description=Getty on %I
…
[Service]
ExecStart=-/sbin/agetty --noclear %I $TERM
…
When the [email protected] and [email protected] are instantiated from the above template,
Description= is resolved as Getty on ttyA and Getty on ttyB.
89
Red Hat Enterprise Linux 9 Configuring basic system settings
For a complete list of unit specifiers, see the systemd.unit(5) manual page.
How to decide what dependencies a systemd service unit definition should have
90
CHAPTER 17. OPTIMIZING SYSTEMD TO SHORTEN THE BOOT TIME
The purpose of systemd units enabled by default, and circumstances under which you can safely
disable such systemd units in order to shorten the boot time.
For a complete list and detailed description of all options, see the systemd-analyze man page.
Prerequisites
Before starting to examine systemd in order to tune the boot time, you may want to list all
enabled services:
Procedure
Procedure
For the overall information about the time that the last successful boot took, use:
$ systemd-analyze
Procedure
For the information about the initialization time of each systemd unit, use:
$ systemd-analyze blame
The output lists the units in descending order according to the time they took to initialize during the last
successful boot.
Procedure
91
Red Hat Enterprise Linux 9 Configuring basic system settings
To identify the units that took most time to initialize at the last successful boot, use:
$ systemd-analyze critical-chain
The output highlights the units that critically slow down the boot with the red color.
However, certain services must stay enabled in order that your operating system is safe and functions in
the way you need.
You can use the table below as a guide to selecting the services that you can safely disable. The table
lists all services enabled by default on a minimal installation of Red Hat Enterprise Linux, and for each
service it states whether this service can be safely disabled.
The table also provides more information about the circumstances under which the service can be
disabled, or the reason why you should not disable the service.
92
CHAPTER 17. OPTIMIZING SYSTEMD TO SHORTEN THE BOOT TIME
auditd.servic yes Disable auditd.service only if you do not need audit messages
e from the kernel. Be aware that if you disable auditd.service, the
/var/log/audit/audit.log file is not produced. Consequently, you
are not able to retroactively review some commonly-reviewed
actions or events, such as user logins, service starts or password
changes. Also note that auditd has two parts: a kernel part, and a
service itself. By using the systemctl disable auditd command,
you only disable the service, but not the kernel part. To disable
system auditing in its entirety, set audit=0 on kernel command
line.
[email protected] no This service runs only when it is really needed, so it does not need
ce to be disabled.
crond.service yes Be aware that no items from crontab will run if you disable
crond.service.
[email protected] no This service runs only when it is really needed, so it does not need
e to be disabled.
irqbalance.se yes Disable irqbalance.service only if you have just one CPU. Do not
rvice disable irqbalance.service on systems with multiple CPUs.
93
Red Hat Enterprise Linux 9 Configuring basic system settings
kdump.servic yes Disable kdump.service only if you do not need reports from
e kernel crashes.
rhsmcertd.se no
rvice
rngd.service yes Disable rngd.service only if you do not need a lot of entropy on
your system, or you do not have any sort of hardware generator.
Note that the service is necessary in environments that require a
lot of good entropy, such as systems used for generation of X.509
certificates (for example the FreeIPA server).
rsyslog.servic yes Disable rsyslog.service only if you do not need persistent logs,
e or you set systemd-journald to persistent mode.
94
CHAPTER 17. OPTIMIZING SYSTEMD TO SHORTEN THE BOOT TIME
sshd.service yes Disable sshd.service only if you do not need remote logins by
OpenSSH server.
sssd.service yes Disable sssd.service only if there are no users who log in the
system over the network (for example by using LDAP or Kerberos).
Red Hat recommends to disable all sssd-* units if you disable
sssd.service.
To find more information about a service, you can run one of the following commands:
The systemctl cat command provides the content of the service file located under
/usr/lib/systemd/system/<service>, as well as all applicable overrides. The applicable overrides include
unit file overrides from the /etc/systemd/system/<service> file or drop-in files from a corresponding
unit.type.d directory.
For more information on drop-in files, see the systemd.unit man page.
The systemctl help command shows the man page of the particular service.
95
Red Hat Enterprise Linux 9 Configuring basic system settings
96
CHAPTER 18. INTRODUCTION TO MANAGING USER AND GROUP ACCOUNTS
Each user is associated with a unique numerical identification number called user ID (UID). Each group is
associated with a group ID (GID). Users within a group share the same permissions to read, write, and
execute files owned by that group.
cat /usr/share/doc/setup*/uidgid
It is recommended to assign IDs to the new users and groups starting at 5000, as the reserved range
can increase in the future.
To make the IDs assigned to new users start at 5000 by default, modify the UID_MIN and GID_MIN
parameters in the /etc/login.defs file.
Procedure
To modify and make the IDs assigned to new users start at 5000 by default:
2. Find the lines that define the minimum value for automatic UID selection.
4. Find the lines that define the minimum value for automatic GID selection.
97
Red Hat Enterprise Linux 9 Configuring basic system settings
The dynamically assigned UIDs and GIDs for the regular users now start at 5000.
NOTE
The UID’s and GID’s of users and groups created before you changed the
UID_MIN and GID_MIN values do not change.
This will allow new user’s group to have same 5000+ ID as UID and GID.
WARNING
UPGs simplify the collaboration on a project between multiple users. In addition, UPG system
configuration makes it safe to set default permissions for a newly created file or directory, as it allows
both the user, and the group this user is a part of, to make modifications to the file or directory.
98
CHAPTER 19. MANAGING USER ACCOUNTS IN THE WEB CONSOLE
Prerequisites
Set up the RHEL web console. For details, see Getting started using the RHEL web console .
Log in to the RHEL web console with an account that has administrator permissions assigned.
For details, see Logging in to the RHEL web console .
The RHEL web console displays all user accounts located in the system. Therefore, you can see at least
one user account just after the first login to the web console.
After logging into the RHEL web console, you can perform the following operations:
Lock accounts.
Prerequisites
The RHEL web console must be installed and accessible. For details, see Installing the web
console.
99
Red Hat Enterprise Linux 9 Configuring basic system settings
Procedure
2. Click Accounts.
1. In the Full Name field, enter the full name of the user.
The RHEL web console automatically suggests a user name from the full name and fills it in the
User Name field. If you do not want to use the original naming convention consisting of the first
letter of the first name and the whole surname, update the suggestion.
2. In the Password/Confirm fields, enter the password and retype it for verification that your
password is correct.
The color bar placed below the fields shows you security level of the entered password, which
does not allow you to create a user with a weak password.
1. Click Create to save the settings and close the dialog box.
Now you can see the new account in the Accounts settings and you can use the credentials to
connect to the system.
Procedure
2. Click Accounts.
100
CHAPTER 19. MANAGING USER ACCOUNTS IN THE WEB CONSOLE
5. In the Password Expiration dialog box, select Require password change every … days and
enter a positive whole number representing the number of days after which the password
expires.
6. Click Change.
Verification steps
To verify that the password expiration is set, open the account settings.
The RHEL 9 web console displays a link with the date of expiration.
In each user account in the RHEL 9 web console, you can terminate all sessions for the account except
for the web console session you are currently using. This prevents you from loosing access to your
system.
Procedure
2. Click Accounts.
3. Click the user account for which you want to terminate the session.
101
Red Hat Enterprise Linux 9 Configuring basic system settings
102
CHAPTER 20. MANAGING USERS FROM THE COMMAND LINE
Prerequisites
Root access
Procedure
Replace options with the command-line options for the useradd command, and replace
username with the name of the user.
Verification steps
# id sarah
Additional resources
Prerequisites
103
Red Hat Enterprise Linux 9 Configuring basic system settings
Root access
Procedure
Replace options with the command-line options for the groupadd command, and replace
group-name with the name of the group.
Verification steps
# tail /etc/group
sysadmins:x:5000:
Additional resources
Prerequisites
root access
Procedure
Replace group-name with the name of the group, and replace username with the name of the
user.
104
CHAPTER 20. MANAGING USERS FROM THE COMMAND LINE
Verification steps
To verify the new groups is added to the supplementary groups of the user sysadmin, use:
# groups sysadmin
Prerequisites
Root access
Procedure
1. Create a directory:
# mkdir directory-name
2. Create a group:
# groupadd group-name
Replace group-name with the name of the group, and replace username with the name of the
user.
105
Red Hat Enterprise Linux 9 Configuring basic system settings
4. Associate the user and group ownership of the directory with the group-name group:
Replace group-name with the name of the group, and replace directory-name with the name of
the directory.
5. Set the write permissions to allow the users to create and modify files and directories and set
the setgid bit to make this permission be applied within the directory-name directory:
Now all members of the group-name group can create and edit files in the directory-name
directory. Newly created files retain the group ownership of group-name group.
Verification steps
# ls -ld directory-name
106
CHAPTER 21. EDITING USER GROUPS USING THE COMMAND LINE
On Linux, user groups can act as primary or supplementary. Primary and supplementary groups have the
following properties:
Primary group
Supplementary groups
You can add an existing user to an existing supplementary group to manage users with the
same security and access privileges within the group.
Procedure
Display the names of the primary and any supplementary group of a user:
$ groups user-name
Replace user-name with the name of the user. If you do not provide a user name, the command
displays the group membership for the current user. The first group is the primary group
followed by the optional supplementary groups.
$ groups sarah
User sarah has a primary group sarah and is a member of supplementary groups wheel and
107
Red Hat Enterprise Linux 9 Configuring basic system settings
User sarah has a primary group sarah and is a member of supplementary groups wheel and
developer.
$ groups marc
marc : marc
User marc has only a primary group marc and no supplementary groups.
Prerequisites:
1. root access
Procedure
Replace group-name with the name of the new primary group, and replace user-name with the
name of the user.
NOTE
When you change a user’s primary group, the command also automatically
changes the group ownership of all files in the user’s home directory to the new
primary group. You must fix the group ownership of files outside of the user’s
home directory manually.
If the user sarah belongs to the primary group sarah1, and you want to change the primary
group of the user to sarah2, use:
Verification steps
108
CHAPTER 21. EDITING USER GROUPS USING THE COMMAND LINE
$ groups sarah
sarah : sarah2
Prerequisites
root access
Procedure
Replace group-name with the name of the group, and replace username with the name of the
user.
Verification steps
To verify the new groups is added to the supplementary groups of the user sysadmin, use:
# groups sysadmin
Prerequisites
109
Red Hat Enterprise Linux 9 Configuring basic system settings
root access
Procedure
Replace user-name with the name of the user, and replace group-name with the name of the
supplementary group.
If the user sarah has a primary group sarah2, and belongs to the secondary groups wheel
and developers, and you want to remove that user from the group developers, use:
Verification steps
Verify that you removed the user sarah from the secondary group developers:
$ groups sarah
Prerequisites
root access
Procedure
Replace group-names with the name of one or more supplementary groups. To add the user to
several supplementary groups at once, separate the group names using commas and no
intervening spaces. For example: wheel,developer.
IMPORTANT
110
CHAPTER 21. EDITING USER GROUPS USING THE COMMAND LINE
IMPORTANT
If the user is currently a member of a group that you do not specify, the
command removes the user from the group.
If the user sarah has a primary group sarah2, and belongs to the supplementary group
wheel, and you want the user to belong to three more supplementary groups developer,
sysadmin, and security, use:
Verification steps
Verify that you set the list of the supplementary groups correct:
# groups sarah
111
Red Hat Enterprise Linux 9 Configuring basic system settings
When a user tries to use sudo privileges to run a command that is not allowed in the /etc/sudoers file,
the system records a message containing username : user NOT in sudoers to the journal log.
The default /etc/sudoers file provides information and examples of authorizations. You can activate a
specific example rule by removing the # comment character from the beginning of the line. The
authorizations section relevant for user is marked with the following introduction:
## Next comes the main part: which users can run what software on
## which machines (the sudoers file can be shared between multiple
## systems).
You can use the following format to create new sudoers authorizations and to modify existing
authorizations:
username hostname=path/to/command
Where:
username is the name of the user or group, for example, user1 or %group1.
path/to/command is the complete absolute path to the command. You can also limit the user to
only performing a command with specific options and arguments by adding those options after
the command path. If you do not specify any options, the user can use the command with all
options.
You can replace any of these variables with ALL to apply the rule to all users, hosts, or commands.
WARNING
With overly permissive rules, such as ALL ALL=(ALL) ALL, all users are able to run
all commands as all users on all hosts. This can lead to security risks.
You can specify the arguments negatively using the ! operator. For example, use !root to specify all
users except the root user. Note that using the allowlists to allow specific users, groups, and commands,
112
CHAPTER 22. MANAGING SUDO ACCESS
is more secure than using the blocklists to disallowing specific users, groups, and commands. By using
the allowlists you also block new unauthorized users or groups.
WARNING
Avoid using negative rules for commands because users can overcome such rules by
renaming commands using the alias command.
The system reads the /etc/sudoers file from beginning to end. Therefore, if the file contains multiple
entries for a user, the entries are applied in order. In case of conflicting values, the system uses the last
match, even if it is not the most specific match.
The preferred way of adding new rules to sudoers is by creating new files in the /etc/sudoers.d/
directory instead of entering rules directly to the /etc/sudoers file. This is because the contents of this
directory are preserved during system updates. In addition, it is easier to fix any errors in the separate
files than in the /etc/sudoers file. The system reads the files in the /etc/sudoers.d directory when it
reaches the following line in the /etc/sudoers file:
#includedir /etc/sudoers.d
Note that the number sign # at the beginning of this line is part of the syntax and does not mean the line
is a comment. The names of files in that directory must not contain a period . and must not end with a
tilde ~.
When users need to perform an administrative command, they can precede that command with sudo.
The command is then executed as if they were the root user.
Only users listed in the /etc/sudoers configuration file can use the sudo command.
The command is executed in the shell of the user, not in the root shell.
Prerequisites
root access
Procedure
# visudo
113
Red Hat Enterprise Linux 9 Configuring basic system settings
The /etc/sudoers file defines the policies applied by the sudo command.
2. In the /etc/sudoers file, find the lines that grant sudo access to users in the administrative
wheel group.
3. Make sure the line that starts with %wheel does not have the # comment character before it.
5. Add users you want to grant sudo access to into the administrative wheel group.
Verification steps
# id username
uid=5000(username) gid=5000(_username) groups=5000(username),10(wheel)
Prerequisites
root access
Procedure
# mkdir -p /etc/sudoers.d/
# visudo -f /etc/sudoers.d/file-name
Replace file-name with the name of the file you want to create. The file will open automatically.
Replace username with the name of the user. Replace hostname with the name of the host.
114
CHAPTER 22. MANAGING SUDO ACCESS
Replace username with the name of the user. Replace hostname with the name of the host.
Replace /path/to/the/command with the absolute path to the command (for example,
/usr/bin/dnf).
# mkdir -p /etc/sudoers.d/
# visudo -f /etc/sudoers.d/sarah
Ensure that the two command paths are separated by a , comma followed by a space.
4. Optional: To receive email notifications every time the user sarah attempts to use sudo
privileges, add the following lines to the file:
Defaults mail_always
Defaults mailto="[email protected]"
5. To verify if the user sarah can run the dnf command with sudo privileges, switch the
account:
# su sarah -
$ sudo dnf
[sudo] password for sarah:
...
usage: dnf [options] COMMAND
...
If you receive the sarah is not in the sudoers file. This incident will be reported.
message, the configuration was not completed correctly. Ensure that you are executing
this procedure as root and that you followed the steps thoroughly.
115
Red Hat Enterprise Linux 9 Configuring basic system settings
116
CHAPTER 23. CHANGING AND RESETTING THE ROOT PASSWORD
Prerequisites
Root access
Procedure
# passwd
You are prompted to enter your current password before you can change it.
Prerequisites
Procedure
To change or reset the root password as a non-root user that belongs to the wheel group, use:
You are prompted to enter your current non-root password before you can change the root
password.
Procedure
1. Reboot the system and, on the GRUB 2 boot screen, press the e key to interrupt the boot
process.
117
Red Hat Enterprise Linux 9 Configuring basic system settings
load_video
set gfx_payload=keep
insmod gzio
linux ($root)/vmlinuz-5.14.0-70.22.1.e19_0.x86_64 root=/dev/mapper/rhel-root ro crash\
kernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv/swap rhgb quiet
initrd ($root)/initramfs-5.14.0-70.22.1.e19_0.x86_64.img $tuned_initrd
3. Add rd.break to the end of the line that starts with linux.
The file system is mounted as read-only in the /sysroot directory. Remounting the file system
as writable allows you to change the password.
chroot /sysroot
passwd
Follow the instructions displayed by the command line to finalize the change of the root
password.
touch /.autorelabel
exit
118
CHAPTER 23. CHANGING AND RESETTING THE ROOT PASSWORD
exit
11. Wait until the SELinux relabeling process is finished. Note that relabeling a large disk might take
a long time. The system reboots automatically when the process is complete.
Verification steps
1. To verify that the root password is successfully changed, log in as a normal user and open the
Terminal.
$ su
4. Print the user name associated with the current effective user ID:
whoami
root
119
Red Hat Enterprise Linux 9 Configuring basic system settings
Others (o).
Read (r).
Write (w).
Execute (x).
Note that the execute permission for a file allows you to execute that file. The execute permission for a
directory allows you to access the contents of the directory, but not execute it.
When a new file or directory is created, the default set of permissions are automatically assigned to it.
The default permissions for a file or directory are based on two factors:
Base permission.
No permission --- 0
Execute --x 1
Write -w- 2
Read r-- 4
120
CHAPTER 24. MANAGING FILE PERMISSIONS
The base permission for a directory is 777 (drwxrwxrwx), which grants everyone the permissions to
read, write, and execute. This means that the directory owner, the group, and others can list the
contents of the directory, create, delete, and edit items within the directory, and descend into it.
Note that individual files within a directory can have their own permission that might prevent you from
editing them, despite having unrestricted access to the directory.
The base permission for a file is 666 (-rw-rw-rw-), which grants everyone the permissions to read and
write. This means that the file owner, the group, and others can read and edit the file.
$ ls -l
-rwxrw----. 1 sysadmins sysadmins 2 Mar 2 08:43 file
- indicates it is a file.
rwx indicates that the file owner has permissions to read, write, and execute the file.
rw- indicates that the group has permissions to read and write, but not execute the file.
--- indicates that other users have no permission to read, write, or execute the file.
. indicates that the SELinux security context is set for the file.
$ ls -dl directory
drwxr-----. 1 sysadmins sysadmins 2 Mar 2 08:43 directory
d indicates it is a directory.
rwx indicates that the directory owner has the permissions to read, write, and access the
contents of the directory.
As a directory owner, you can list the items (files, subdirectories) within the directory, access
the content of those items, and modify them.
r-- indicates that the group has permissions to read, but not write or access the contents of
the directory.
As a member of the group that owns the directory, you can list the items within the directory.
You cannot access information about the items within the directory or modify them.
--- indicates that other users have no permission to read, write, or access the contents of the
directory.
As someone who is not a user owner, or as group owner of the directory, you cannot list the
items within the directory, access information about those items, or modify them.
121
Red Hat Enterprise Linux 9 Configuring basic system settings
. indicates that the SELinux security context is set for the directory.
NOTE
The base permission that is automatically assigned to a file or directory is not the default
permission the file or directory ends up with. When you create a file or directory, the base
permission is altered by the umask. The combination of the base permission and the
umask creates the default permission for files and directories.
Read r-- 3
Write -w- 5
Execute --x 6
No permissions --- 7
The default umask for a standard user is 0002. The default umask for a root user is 0022.
The first digit of the umask represents special permissions (sticky bit, ). The last three digits of the
umask represent the permissions that are removed from the user owner ( u), group owner (g), and
others (o) respectively.
The following example illustrates how the umask with an octal value of 0137 is applied to the file with
the base permission of 777, to create the file with the default permission of 640.
122
CHAPTER 24. MANAGING FILE PERMISSIONS
When a standard user creates a new directory, the umask is set to 002 (rwxrwxr-x), and the base
permissions for a directory are set to 777 (rwxrwxrwx). This brings the default permissions to 775
(drwxrwxr-x).
This means that the directory owner and the group can list the contents of the directory, create, delete,
and edit items within the directory, and descend into it. Other users can only list the contents of the
directory and descend into it.
When a standard user creates a new file, the umask is set to 002 (rwxrwxr-x), and the base
permissions for a file are set to 666 (rw-rw-rw-). This brings the default permissions to 664 (-rw-rw-r-
-).
123
Red Hat Enterprise Linux 9 Configuring basic system settings
This means that the file owner and the group can read and edit the file, while other users can only
read the file.
Example 24.6. Default permissions for a directory created by the root user
When a root user creates a new directory, the umask is set to 022 (rwxr-xr-x), and the base
permissions for a directory are set to 777 (rwxrwxrwx). This brings the default permissions to 755
(rwxr-xr-x).
This means that the directory owner can list the contents of the directory, create, delete, and edit
items within the directory, and descend into it. The group and others can only list the contents of the
directory and descend into it.
Example 24.7. Default permissions for a file created by the root user
When a root user creates a new file, the umask is set to 022 (rwxr-xr-x), and the base permissions
for a file are set to 666 (rw-rw-rw-). This brings the default permissions to 644 (-rw-r—r--).
This means that the file owner can read and edit the file, while the group and others can only read
the file.
124
CHAPTER 24. MANAGING FILE PERMISSIONS
NOTE
For security reasons, regular files cannot have execute permissions by default, even if the
umask is set to 000 (rwxrwxrwx). However, directories can be created with execute
permissions.
Read (r)
Write (w)
Execute (x)
Other (o)
All (a)
= to remove the existing permissions and explicitly define the new ones
Procedure
Replace <level> with the level of ownership you want to set the permissions for. Replace
<operation> with one of the signs. Replace <permission> with the permissions you want to
assign. Replace file-name with the name of the file or directory. For example, to grant everyone
the permissions to read, write, and execute (rwx) my-script.sh, use the chmod a=rwx my-
script.sh command.
Verification steps
$ ls -l file-name
125
Red Hat Enterprise Linux 9 Configuring basic system settings
$ ls -dl directory-name
To see the permissions for all the files within a particular directory, use:
$ ls -l directory-name
$ ls -l my-file.txt
-rw-rw-r--. 1 username username 0 Feb 24 17:56 my-file.txt
2. Remove the permissions to read, write, and execute (rwx) the file from group owner ( g)
and others (o):
Note that any permission that is not specified after the equals sign (=) is automatically
prohibited.
$ ls -l my-file.txt
-rw-------. 1 username username 0 Feb 24 17:56 my-file.txt
$ ls -dl my-directory
drwxrwx---. 2 username username 4096 Feb 24 18:12 my-directory
2. Add the read and execute (r-x) access for all users ( a):
3. Verify that the permissions for my-directory and its content were set correctly:
$ ls -dl my-directory
drwxrwxr-x. 2 username username 4096 Feb 24 18:12 my-directory
126
CHAPTER 24. MANAGING FILE PERMISSIONS
Procedure
Replace file-name with the name of the file or directory. Replace octal_value with an octal value.
See Base file permissions for more details.
127
Red Hat Enterprise Linux 9 Configuring basic system settings
Procedure
$ umask -S
To display the current value of the umask in the octal mode, use:
$ umask
NOTE
When displaying the umask in octal mode, you may notice it displayed as a four
digit number (0002 or 0022). The first digit of the umask represents a special bit
(sticky bit, SGID bit, or SUID bit). If the first digit is set to 0, the special bit is not
set.
To determine whether you are executing a command in a login or a non-login shell, use the echo $0
command.
Example 25.1. Determining if you are working in a login or a non-login bash shell
If the output of the echo $0 command returns bash, you are executing the command in a
non-login shell.
$ echo $0
bash
The default umask for the non-login shell is set in the /etc/bashrc configuration file.
If the output of the echo $0 command returns -bash, you are executing the command in a
login shell.
# echo $0
-bash
The default umask for the login shell is set in the /etc/login.defs configuration file.
128
CHAPTER 25. MANAGING THE UMASK
Procedure
To display the default bash umask for the non-login shell, use:
# By default, we want umask to get set. This sets it for non-login shell.
umask 002
umask 022
To display the default bash umask for the login shell, use:
# UMASK is also used by useradd(8) and newusers(8) to set the mode for new
UMASK 022
# If HOME_MODE is not set, the value of UMASK is used to create the mode.
Read (r)
Write (w)
Execute (x)
Other (o)
All (a)
= to remove the existing permissions and explicitly define the new ones
NOTE
129
Red Hat Enterprise Linux 9 Configuring basic system settings
NOTE
Any permission that is not specified after the equals sign (=) is automatically
prohibited.
Procedure
$ umask -S <level><operation><permission>
Replace <level> with the level of ownership you want to set the umask for. Replace
<operation> with one of the signs. Replace <permission> with the permissions you want to
assign. For example, to set the umask to u=rwx,g=rwx,o=rwx, use umask -S a=rwx.
NOTE
Procedure
$ umask octal_value
Replace octal_value with an octal value. See User file-creation mode mask for more details.
NOTE
Prerequisites
root access
Procedure
130
CHAPTER 25. MANAGING THE UMASK
else
umask 022
fi
Replace the default octal value of the umask (002) with another octal value. See User file-
creation mode mask for more details.
Prerequisites
root access
Procedure
UMASK 022
Replace the default octal value of the umask (022) with another octal value. See User file-
creation mode mask for more details.
Procedure
Append the line that specifies the octal value of the umask into the .bashrc file for the
particular user.
Replace octal_value with an octal value and replace username with the name of the user. See
User file-creation mode mask for more details.
Procedure
# HOME_MODE is used by useradd(8) and newusers(8) to set the mode for new
# home directories.
# If HOME_MODE is not set, the value of UMASK is used to create the mode.
HOME_MODE 0700
Replace the default octal value (0700) with another octal value. The selected mode will be used
to create the permissions for the home directory.
4. If HOME_MODE is not set, modify the UMASK to set the mode for the newly created home
directories:
UMASK 022
Replace the default octal value (022) with another octal value. See User file-creation mode
mask for more details.
132
CHAPTER 26. MANAGING THE ACCESS CONTROL LIST
Procedure
$ getfacl file-name
Prerequisites
root access.
Procedure
Replace username with the name of the user, symbolic_value with a symbolic value, and file-name with
the name of the file or directory. For more information see the setfacl man page.
The following example describes how to modify permissions for the group-project file owned by the
root user that belongs to the root group so that this file is:
Procedure
133
Red Hat Enterprise Linux 9 Configuring basic system settings
Verification steps
To verify that the user andrew has the rw- permission, the user susan has the ---
permission, and other users have the r-- permission, use:
$ getfacl group-project
# file: group-project
# owner: root
# group: root
user:andrew:rw-
user:susan:---
group::r--
mask::rw-
other::r--
134
CHAPTER 27. USING THE CHRONY SUITE TO CONFIGURE NTP
The user space daemon updates the system clock running in the kernel. The system clock can keep time
by using various clock sources. Usually, the Time Stamp Counter (TSC) is used. The TSC is a CPU
register which counts the number of cycles since it was last reset. It is very fast, has a high resolution,
and there are no interruptions.
Starting with Red Hat Enterprise Linux 8, the NTP protocol is implemented by the chronyd daemon,
available from the repositories in the chrony package.
The following sections describe how to use the chrony suite to configure NTP.
To synchronize the system clock with a reference clock, for example a GPS receiver
As an NTPv4(RFC 5905) server or peer to provide a time service to other computers in the
network
chrony performs well in a wide range of conditions, including intermittent network connections, heavily
congested networks, changing temperatures (ordinary computer clocks are sensitive to temperature),
and systems that do not run continuously, or run on a virtual machine.
Typical accuracy between two machines synchronized over the Internet is within a few milliseconds, and
for machines on a LAN within tens of microseconds. Hardware timestamping or a hardware reference
clock may improve accuracy between two machines synchronized to a sub-microsecond level.
chrony consists of chronyd, a daemon that runs in user space, and chronyc, a command line program
which can be used to monitor the performance of chronyd and to change various operating parameters
when it is running.
The chrony daemon, chronyd, can be monitored and controlled by the command line utility chronyc.
This utility provides a command prompt which allows entering a number of commands to query the
current state of chronyd and make changes to its configuration. By default, chronyd accepts only
commands from a local instance of chronyc, but it can be configured to accept monitoring commands
also from remote hosts. The remote access should be restricted.
Procedure
1. To make changes to the local instance of chronyd using the command line utility chronyc in
135
Red Hat Enterprise Linux 9 Configuring basic system settings
1. To make changes to the local instance of chronyd using the command line utility chronyc in
interactive mode, enter the following command as root:
# chronyc
chronyc must run as root if some of the restricted commands are to be used.
chronyc>
3. Alternatively, the utility can also be invoked in non-interactive command mode if called together
with a command as follows:
chronyc command
NOTE
Changes made using chronyc are not permanent, they will be lost after a chronyd
restart. For permanent changes, modify /etc/chrony.conf.
136
CHAPTER 28. USING CHRONY
Procedure
1. The chrony suite is installed by default on Red Hat Enterprise Linux. To ensure that it is, run the
following command as root:
The default location for the chrony daemon is /usr/sbin/chronyd. The command line utility will
be installed to /usr/bin/chronyc.
To ensure chronyd starts automatically at system start, issue the following command as root:
To prevent chronyd from starting automatically at system start, issue the following command
as root:
Procedure
137
Red Hat Enterprise Linux 9 Configuring basic system settings
$ chronyc tracking
Reference ID : CB00710F (foo.example.net)
Stratum :3
Ref time (UTC) : Fri Jan 27 09:49:17 2017
System time : 0.000006523 seconds slow of NTP time
Last offset : -0.000006747 seconds
RMS offset : 0.000035822 seconds
Frequency : 3.225 ppm slow
Residual freq : 0.000 ppm
Skew : 0.129 ppm
Root delay : 0.013639022 seconds
Root dispersion : 0.001100737 seconds
Update interval : 64.2 seconds
Leap status : Normal
2. The sources command displays information about the current time sources that chronyd is
accessing. To check chrony sources, issue the following command:
$ chronyc sources
210 Number of sources = 3
MS Name/IP address Stratum Poll Reach LastRx Last sample
===========================================================================
====
#* GPS0 0 4 377 11 -479ns[ -621ns] /- 134ns
^? a.b.c 2 6 377 23 -923us[ -924us] +/- 43ms
^ d.e.f 1 6 377 21 -2629us[-2619us] +/- 86ms
The optional argument -v can be specified, meaning verbose. In this case, extra caption lines are
shown as a reminder of the meanings of the columns.
3. The sourcestats command displays information about the drift rate and offset estimation
process for each of the sources currently being examined by chronyd. To check chrony source
statistics, issue the following command:
$ chronyc sourcestats
210 Number of sources = 1
Name/IP Address NP NR Span Frequency Freq Skew Offset Std Dev
===========================================================================
====
abc.def.ghi 11 5 46m -0.001 0.045 1us 25us
The optional argument -v can be specified, meaning verbose. In this case, extra caption lines are
shown as a reminder of the meanings of the columns.
Additional resources
Procedure
1. To step the system clock immediately, bypassing any adjustments in progress by slewing, issue
138
CHAPTER 28. USING CHRONY
1. To step the system clock immediately, bypassing any adjustments in progress by slewing, issue
the following command as root:
# chronyc makestep
If the rtcfile directive is used, the real-time clock should not be manually adjusted. Random adjustments
would interfere with chrony's need to measure the rate at which the real-time clock drifts.
The following procedure describes how to set up chrony for asystem in an isolated network.
Procedure
1. On the system selected to be the master, using a text editor running as root, edit
/etc/chrony.conf as follows:
driftfile /var/lib/chrony/drift
commandkey 1
keyfile /etc/chrony.keys
initstepslew 10 client1 client3 client6
local stratum 8
manual
allow 192.0.2.0
Where 192.0.2.0 is the network or subnet address from which the clients are allowed to connect.
2. On the systems selected to be direct clients of the master, using a text editor running as root,
edit the /etc/chrony.conf as follows:
server master
driftfile /var/lib/chrony/drift
logdir /var/log/chrony
log measurements statistics tracking
keyfile /etc/chrony.keys
commandkey 24
local stratum 10
initstepslew 20 master
allow 192.0.2.123
Where 192.0.2.123 is the address of the master, and master is the host name of the master.
Clients with this configuration will resynchronize the master if it restarts.
On the client systems which are not to be direct clients of the master, the /etc/chrony.conf file should
be the same except that the local and allow directives should be omitted.
In an isolated network, you can also use the local directive that enables a local reference mode, which
139
Red Hat Enterprise Linux 9 Configuring basic system settings
In an isolated network, you can also use the local directive that enables a local reference mode, which
allows chronyd operating as an NTP server to appear synchronized to real time, even when it was never
synchronized or the last update of the clock happened a long time ago.
To allow multiple servers in the network to use the same local configuration and to be synchronized to
one another, without confusing clients that poll more than one server, use the orphan option of the
local directive which enables the orphan mode. Each server needs to be configured to poll all other
servers with local. This ensures that only the server with the smallest reference ID has the local
reference active and other servers are synchronized to it. When the server fails, another one will take
over.
Unix domain socket, which is accessible locally by the root or chrony user.
By default, chronyc connects to the Unix domain socket. The default path is
/var/run/chrony/chronyd.sock. If this connection fails, which can happen for example when chronyc is
running under a non-root user, chronyc tries to connect to 127.0.0.1 and then ::1.
Only the following monitoring commands, which do not affect the behavior of chronyd, are allowed from
the network:
activity
manual list
rtcdata
smoothing
sources
sourcestats
tracking
waitsync
The set of hosts from which chronyd accepts these commands can be configured with the cmdallow
directive in the configuration file of chronyd, or the cmdallow command in chronyc. By default, the
commands are accepted only from localhost (127.0.0.1 or ::1).
All other commands are allowed only through the Unix domain socket. When sent over the network,
chronyd responds with a Not authorised error, even if it is from localhost.
The following procedure describes how to access chronyd remotely with chronyc.
Procedure
1. Allow access from both IPv4 and IPv6 addresses by adding the following to the
/etc/chrony.conf file:
140
CHAPTER 28. USING CHRONY
bindcmdaddress 0.0.0.0
or
bindcmdaddress ::
2. Allow commands from the remote IP address, network, or subnet by using the cmdallow
directive.
Add the following content to the /etc/chrony.conf file:
cmdallow 192.168.1.0/24
Optionally, you can open port 323 permanently using the --permanent option:
firewall-cmd --reload
Additional resources
WARNING
The timesync role replaces the configuration of the given or detected provider
service on the managed host. Previous settings are lost, even if they are not
specified in the role variables. The only preserved setting is the choice of provider if
the timesync_ntp_provider variable is not defined.
The following example shows how to apply the timesync role in a situation with just one pool of servers.
Example 28.1. An example playbook applying the timesync role for a single pool of servers
141
Red Hat Enterprise Linux 9 Configuring basic system settings
---
- hosts: timesync-test
vars:
timesync_ntp_servers:
- hostname: 2.rhel.pool.ntp.org
pool: yes
iburst: yes
roles:
- rhel-system-roles.timesync
For a detailed reference on timesync role variables, install the rhel-system-roles package, and see the
README.md or README.html files in the /usr/share/doc/rhel-system-roles/timesync directory.
Additional resources
Preparing a control node and managed nodes to use RHEL System Roles
142
CHAPTER 29. CHRONY WITH HW TIMESTAMPING
Another protocol for time synchronization that uses hardware timestamping is PTP.
Unlike NTP, PTP relies on assistance in network switches and routers. If you want to reach the best
accuracy of synchronization, use PTP on networks that have switches and routers with PTP support, and
prefer NTP on networks that do not have such switches and routers.
# ethtool -T eth0
Output:
143
Red Hat Enterprise Linux 9 Configuring basic system settings
off (HWTSTAMP_TX_OFF)
on (HWTSTAMP_TX_ON)
Hardware Receive Filter Modes:
none (HWTSTAMP_FILTER_NONE)
all (HWTSTAMP_FILTER_ALL)
ptpv1-l4-sync (HWTSTAMP_FILTER_PTP_V1_L4_SYNC)
ptpv1-l4-delay-req (HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ)
ptpv2-l4-sync (HWTSTAMP_FILTER_PTP_V2_L4_SYNC)
ptpv2-l4-delay-req (HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ)
ptpv2-l2-sync (HWTSTAMP_FILTER_PTP_V2_L2_SYNC)
ptpv2-l2-delay-req (HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ)
ptpv2-event (HWTSTAMP_FILTER_PTP_V2_EVENT)
ptpv2-sync (HWTSTAMP_FILTER_PTP_V2_SYNC)
ptpv2-delay-req (HWTSTAMP_FILTER_PTP_V2_DELAY_REQ)
hwtimestamp eth0
hwtimestamp eth1
hwtimestamp *
The following directive in /etc/chrony.conf specifies a local NTP server using one second polling
interval:
144
CHAPTER 29. CHRONY WITH HW TIMESTAMPING
clientloglimit 100000000
Example 29.3. Log messages for interfaces with enabled hardware timestamping
When chronyd is configured as an NTP client or peer, you can have the transmit and receive
timestamping modes and the interleaved mode reported for each NTP source by the chronyc ntpdata
command:
Example 29.4. Reporting the transmit, receive timestamping and interleaved mode for each
NTP source
# chronyc ntpdata
Output:
145
Red Hat Enterprise Linux 9 Configuring basic system settings
TX timestamping : Hardware
RX timestamping : Hardware
Total TX : 27
Total RX : 27
Total valid RX : 27
# chronyc sourcestats
With hardware timestamping enabled, stability of NTP measurements should be in tens or hundreds
of nanoseconds, under normal load. This stability is reported in the Std Dev column of the output of
the chronyc sourcestats command:
Output:
Configure the ptp4l and phc2sys programs from the linuxptp packages to use one interface to
synchronize the system clock using PTP.
Configure chronyd to provide the system time using the other interface:
Example 29.6. Configuring chronyd to provide the system time using the other interface
bindaddress 203.0.113.74
hwtimestamp eth1
local stratum 1
146
CHAPTER 30. OVERVIEW OF NETWORK TIME SECURITY (NTS) IN CHRONY
Prerequisites
Procedure
In the client configuration file:
1. Specify the server with the nts option in addition to the recommended iburst option.
For example:
server time.example.com iburst nts
server nts.netnod.se iburst nts
server ptbtime1.ptb.de iburst nts
2. To avoid repeating the Network Time Security-Key Establishment (NTS-KE) session during
system boot, add the following line to chrony.conf, if it is not present:
ntsdumpdir /var/lib/chrony
3. To disable synchronization with Network Time Protocol (NTP) servers provided by DHCP,
comment out or remove the following line in chrony.conf, if it is present:
sourcedir /run/chrony-dhcp
Verification
# chronyc -N authdata
147
Red Hat Enterprise Linux 9 Configuring basic system settings
Name/IP address Mode KeyID Type KLen Last Atmp NAK Cook CLen
================================================================
time.example.com NTS 1 15 256 33m 0 0 8 100
nts.sth1.ntp.se NTS 1 15 256 33m 0 0 8 100
nts.sth2.ntp.se NTS 1 15 256 33m 0 0 8 100
The KeyID, Type, and KLen should have non-zero values. If the value is zero, check the system
log for error messages from chronyd.
# chronyc -N sources
The Reach column should have a non-zero value; ideally 377. If the value rarely gets 377 or
never gets to 377, it indicates that NTP requests or responses are getting lost in the network.
Additional resources
If the NTP server is a client of other servers, that is, it is not a Stratum 1 server, it should use NTS or
symmetric key for its synchronization.
Prerequisites
Procedure
For example:
ntsserverkey /etc/pki/tls/private/foo.example.net.key
ntsservercert /etc/pki/tls/certs/foo.example.net.crt
2. Ensure that both the key and certificate files are readable by the chrony system user, by setting
the group ownership.
For example:
chown :chrony /etc/pki/tls/*/foo.example.net.*
148
CHAPTER 30. OVERVIEW OF NETWORK TIME SECURITY (NTS) IN CHRONY
IMPORTANT
If the server has a firewall, it needs to allow both the UDP 123 and TCP 4460
ports for NTP and Network Time Security-Key Establishment (NTS-KE).
Verification
Perform a quick test from a client machine with the following command:
$ chronyd -Q -t 3 'server
The System clock wrong message indicates the NTP server is accepting NTS-KE connections
and responding with NTS-protected NTP messages.
Verify the NTS-KE connections and authenticated NTP packets observed on the server:
# chronyc serverstats
If the value of the NTS-KE connections accepted and Authenticated NTP packets field is a
non-zero value, it means that at least one client was able to connect to the NTS-KE port and
send an authenticated NTP request.
149
Red Hat Enterprise Linux 9 Configuring basic system settings
Red Hat Enterprise Linux includes the basic OpenSSH packages: the general openssh package, the
openssh-server package and the openssh-clients package. Note that the OpenSSH packages require
the OpenSSL package openssl-libs, which installs several important cryptographic libraries that enable
OpenSSH to provide encrypted communications.
The SSH protocol mitigates security threats, such as interception of communication between two
systems and impersonation of a particular host, when you use it for remote shell login or file copying.
This is because the SSH client and server use digital signatures to verify their identities. Additionally, all
communication between the client and server systems is encrypted.
A host key authenticates hosts in the SSH protocol. Host keys are cryptographic keys that are
generated automatically when OpenSSH is first installed, or when the host boots for the first time.
OpenSSH is an implementation of the SSH protocol supported by Linux, UNIX, and similar operating
systems. It includes the core files necessary for both the OpenSSH client and server. The OpenSSH
suite consists of the following user-space tools:
ssh-copy-id is a script that adds local public keys to the authorized_keys file on a remote SSH
server.
NOTE
150
CHAPTER 31. USING SECURE COMMUNICATIONS BETWEEN TWO SYSTEMS WITH OPENSSH
NOTE
In RHEL 9, the Secure copy protocol (SCP) is replaced with the SSH File Transfer
Protocol (SFTP) by default. This is because SCP has already caused security issues, for
example CVE-2020-15778.
If SFTP is unavailable or incompatible in your scenario, you can use the -O option to force
use of the original SCP/RCP protocol.
For additional information, see the OpenSSH SCP protocol deprecation in Red Hat
Enterprise Linux 9 article.
Two versions of SSH currently exist: version 1, and the newer version 2. The OpenSSH suite in RHEL
supports only SSH version 2. It has an enhanced key-exchange algorithm that is not vulnerable to
exploits known in version 1.
OpenSSH, as one of core cryptographic subsystems of RHEL, uses system-wide crypto policies. This
ensures that weak cipher suites and cryptographic algorithms are disabled in the default configuration.
To modify the policy, the administrator must either use the update-crypto-policies command to adjust
the settings or manually opt out of the system-wide crypto policies.
The OpenSSH suite uses two sets of configuration files: one for client programs (that is, ssh, scp, and
sftp), and another for the server (the sshd daemon).
System-wide SSH configuration information is stored in the /etc/ssh/ directory. User-specific SSH
configuration information is stored in ~/.ssh/ in the user’s home directory. For a detailed list of
OpenSSH configuration files, see the FILES section in the sshd(8) man page.
Additional resources
Prerequisites
Procedure
1. Start the sshd daemon in the current session and set it to start automatically at boot time:
2. To specify different addresses than the default 0.0.0.0 (IPv4) or :: (IPv6) for the
ListenAddress directive in the /etc/ssh/sshd_config configuration file and to use a slower
dynamic network configuration, add the dependency on the network-online.target target unit
151
Red Hat Enterprise Linux 9 Configuring basic system settings
[Unit]
Wants=network-online.target
After=network-online.target
3. Review if OpenSSH server settings in the /etc/ssh/sshd_config configuration file meet the
requirements of your scenario.
4. Optionally, change the welcome message that your OpenSSH server displays before a client
authenticates by editing the /etc/issue file, for example:
Welcome to ssh-server.example.com
Warning: By accessing this server, you agree to the referenced terms and conditions.
Ensure that the Banner option is not commented out in /etc/ssh/sshd_config and its value
contains /etc/issue:
Note that to change the message displayed after a successful login you have to edit the
/etc/motd file on the server. See the pam_motd man page for more information.
5. Reload the systemd configuration and restart sshd to apply the changes:
# systemctl daemon-reload
# systemctl restart sshd
Verification
152
CHAPTER 31. USING SECURE COMMUNICATIONS BETWEEN TWO SYSTEMS WITH OPENSSH
# ssh [email protected]
ECDSA key fingerprint is SHA256:dXbaS0RG/UzlTTku8GtXSz0S1++lPegSy31v3L/FAEc.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'ssh-server-example.com' (ECDSA) to the list of known hosts.
[email protected]'s password:
Additional resources
Prerequisites
Procedure
# vi /etc/ssh/sshd_config
PasswordAuthentication no
On a system other than a new default installation, check that PubkeyAuthentication no has not
been set and the ChallengeResponseAuthentication directive is set to no. If you are
connected remotely, not using console or out-of-band access, test the key-based login process
before disabling password authentication.
# setsebool -P use_nfs_home_dirs 1
Additional resources
153
Red Hat Enterprise Linux 9 Configuring basic system settings
IMPORTANT
If you complete the following steps as root, only root is able to use the keys.
Procedure
$ ssh-keygen -t ecdsa
Generating public/private ecdsa key pair.
Enter file in which to save the key (/home/joesec/.ssh/id_ecdsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/joesec/.ssh/id_ecdsa.
Your public key has been saved in /home/joesec/.ssh/id_ecdsa.pub.
The key fingerprint is:
SHA256:Q/x+qms4j7PCQ0qFd09iZEFHA+SqwBKRNaU72oZfaCI
[email protected]
The key's randomart image is:
+---[ECDSA 256]---+
|.oo..o=++ |
|.. o .oo . |
|. .. o. o |
|....o.+... |
|o.oo.o +S . |
|.=.+. .o |
|E.*+. . . . |
|.=..+ +.. o |
| . oo*+o. |
+----[SHA256]-----+
You can also generate an RSA key pair by using the -t rsa option with the ssh-keygen
command or an Ed25519 key pair by entering the ssh-keygen -t ed25519 command.
$ ssh-copy-id [email protected]
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are
already installed
[email protected]'s password:
...
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '[email protected]'" and check to
make sure that only the key(s) you wanted were added.
If you do not use the ssh-agent program in your session, the previous command copies the
most recently modified ~/.ssh/id*.pub public key if it is not yet installed. To specify another
public-key file or to prioritize keys in files over keys cached in memory by ssh-agent, use the
154
CHAPTER 31. USING SECURE COMMUNICATIONS BETWEEN TWO SYSTEMS WITH OPENSSH
NOTE
If you reinstall your system and want to keep previously generated key pairs, back up the
~/.ssh/ directory. After reinstalling, copy it back to your home directory. You can do this
for all users on your system, including root.
Verification
$ ssh [email protected]
Welcome message.
...
Last login: Mon Nov 18 18:28:42 2019 from ::1
Additional resources
Prerequisites
On the client side, the opensc package is installed and the pcscd service is running.
Procedure
1. List all keys provided by the OpenSC PKCS #11 module including their PKCS #11 URIs and save
the output to the keys.pub file:
2. To enable authentication using a smart card on a remote server (example.com), transfer the
public key to the remote server. Use the ssh-copy-id command with keys.pub created in the
previous step:
3. To connect to example.com using the ECDSA key from the output of the ssh-keygen -D
command in step 1, you can use just a subset of the URI, which uniquely references your key, for
example:
155
Red Hat Enterprise Linux 9 Configuring basic system settings
4. You can use the same URI string in the ~/.ssh/config file to make the configuration permanent:
$ cat ~/.ssh/config
IdentityFile "pkcs11:id=%01?module-path=/usr/lib64/pkcs11/opensc-pkcs11.so"
$ ssh example.com
Enter PIN for 'SSH key':
[example.com] $
Because OpenSSH uses the p11-kit-proxy wrapper and the OpenSC PKCS #11 module is
registered to PKCS#11 Kit, you can simplify the previous commands:
If you skip the id= part of a PKCS #11 URI, OpenSSH loads all keys that are available in the proxy module.
This can reduce the amount of typing required:
Additional resources
IMPORTANT
To make SSH truly effective, prevent the use of insecure connection protocols that are replaced
by the OpenSSH suite. Otherwise, a user’s password might be protected using SSH for one
session only to be captured later when logging in using Telnet. For this reason, consider
disabling insecure protocols, such as telnet, rsh, rlogin, and ftp.
156
CHAPTER 31. USING SECURE COMMUNICATIONS BETWEEN TWO SYSTEMS WITH OPENSSH
Disabling passwords for authentication and allowing only key pairs reduces the attack surface
and it also might save users’ time. On clients, generate key pairs using the ssh-keygen tool and
use the ssh-copy-id utility to copy public keys from clients on the OpenSSH server. To disable
password-based authentication on your OpenSSH server, edit /etc/ssh/sshd_config and
change the PasswordAuthentication option to no:
PasswordAuthentication no
Key types
Although the ssh-keygen command generates a pair of RSA keys by default, you can instruct it
to generate ECDSA or Ed25519 keys by using the -t option. The ECDSA (Elliptic Curve Digital
Signature Algorithm) offers better performance than RSA at the equivalent symmetric key
strength. It also generates shorter keys. The Ed25519 public-key algorithm is an implementation
of twisted Edwards curves that is more secure and also faster than RSA, DSA, and ECDSA.
OpenSSH creates RSA, ECDSA, and Ed25519 server host keys automatically if they are missing.
To configure the host key creation in RHEL, use the [email protected] instantiated
service. For example, to disable the automatic creation of the RSA key type:
To exclude particular key types for SSH connections, comment out the relevant lines in
/etc/ssh/sshd_config, and reload the sshd service. For example, to allow only Ed25519 host
keys:
# HostKey /etc/ssh/ssh_host_rsa_key
# HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
Non-default port
By default, the sshd daemon listens on TCP port 22. Changing the port reduces the exposure
of the system to attacks based on automated network scanning and thus increase security
through obscurity. You can specify the port using the Port directive in the
/etc/ssh/sshd_config configuration file.
You also have to update the default SELinux policy to allow the use of a non-default port. To do
so, use the semanage tool from the policycoreutils-python-utils package:
In the previous commands, replace port_number with the new port number specified using the
Port directive.
Root login
157
Red Hat Enterprise Linux 9 Configuring basic system settings
CAUTION
Enabling logging in as the root user is not a secure practice because the administrator cannot
audit which users run which privileged commands. For using administrative commands, log in
and use sudo instead.
The X server in Red Hat Enterprise Linux clients does not provide the X Security extension.
Therefore, clients cannot request another security layer when connecting to untrusted SSH
servers with X11 forwarding. Most applications are not able to run with this extension enabled
anyway.
By default, the ForwardX11Trusted option in the /etc/ssh/ssh_config.d/05-redhat.conf file is
set to yes, and there is no difference between the ssh -X remote_machine (untrusted host)
and ssh -Y remote_machine (trusted host) command.
If your scenario does not require the X11 forwarding feature at all, set the X11Forwarding
directive in the /etc/ssh/sshd_config configuration file to no.
AllowUsers *@192.168.1.*,*@10.0.0.*,!*@192.168.1.2
AllowGroups example-group
The previous configuration lines accept connections from all users from systems in 192.168.1.*
and 10.0.0.* subnets except from the system with the 192.168.1.2 address. All users must be in
the example-group group. The OpenSSH server denies all other connections.
Note that using allowlists (directives starting with Allow) is more secure than using blocklists
(options starting with Deny) because allowlists block also new unauthorized users or groups.
OpenSSH uses RHEL system-wide cryptographic policies, and the default system-wide
cryptographic policy level offers secure settings for current threat models. To make your
cryptographic settings more strict, change the current policy level:
To opt-out of the system-wide crypto policies for your OpenSSH server, uncomment the line
with the CRYPTO_POLICY= variable in the /etc/sysconfig/sshd file. After this change, values
that you specify in the Ciphers, MACs, KexAlgoritms, and GSSAPIKexAlgorithms sections in
the /etc/ssh/sshd_config file are not overridden. Note that this task requires deep expertise in
configuring cryptographic options.
See Using system-wide cryptographic policies in the Security hardening title for more
information.
Additional resources
158
CHAPTER 31. USING SECURE COMMUNICATIONS BETWEEN TWO SYSTEMS WITH OPENSSH
Prerequisites
A remote server accepts SSH connections only from the jump host.
Procedure
1. Define the jump host by editing the ~/.ssh/config file on your local system, for example:
Host jump-server1
HostName jump1.example.com
The Host parameter defines a name or alias for the host you can use in ssh commands. The
value can match the real host name, but can also be any string.
The HostName parameter sets the actual host name or IP address of the jump host.
2. Add the remote server jump configuration with the ProxyJump directive to ~/.ssh/config file
on your local system, for example:
Host remote-server
HostName remote1.example.com
ProxyJump jump-server1
3. Use your local system to connect to the remote server through the jump server:
$ ssh remote-server
NOTE
159
Red Hat Enterprise Linux 9 Configuring basic system settings
NOTE
You can specify more jump servers and you can also skip adding host definitions to the
configurations file when you provide their complete host names, for example:
$ ssh -J jump1.example.com,jump2.example.com,jump3.example.com
remote1.example.com
Change the host name-only notation in the previous command if the user names or SSH
ports on the jump servers differ from the names and ports on the remote server, for
example:
$ ssh -J
[email protected]:75,[email protected]:75,[email protected]
xample.com:75 [email protected]:220
Additional resources
Prerequisites
You have a remote host with SSH daemon running and reachable through the network.
You know the IP address or hostname and credentials to log in to the remote host.
You have generated an SSH key pair with a passphrase and transferred the public key to the
remote machine.
Procedure
1. Optional: Verify you can use the key to authenticate to the remote host:
b. Enter the passphrase you set while creating the key to grant access to the private key.
160
CHAPTER 31. USING SECURE COMMUNICATIONS BETWEEN TWO SYSTEMS WITH OPENSSH
$ eval $(ssh-agent)
Agent pid 20062
$ ssh-add ~/.ssh/id_rsa
Enter passphrase for ~/.ssh/id_rsa:
Identity added: ~/.ssh/id_rsa ([email protected])
Verification
$ ssh [email protected]
161