Commands Flashcards

1
Q

Which command enables one to show all available NFS mounts on ‘server1’?

A

showmount -e server1

The ‘-e’ option specifies that the command show the servers export list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which command can be used to show all available disk space on mounted devices?

A

df -hT

Just ‘df’ works but the ‘-h’ option formats the output in a human readable form and the ‘-T’ option shows which file system type is used on the different mounts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which command gives an overview of all mounted devices?

A

mount

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which command would list all files/directories (including hidden ones) along with their permissions inside a given directory?

A

ls -al

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which command would copy the contents of the ‘/etc’ directory (including other directories) to the ‘/tmp’ directory?

A

cp -R /etc /tmp

The -R option stands for recursive and allows subdirectories to be copied as well.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which command would move the ‘myFile’ file to the
‘/tmp’ directory?

A

mv myFile /tmp

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which command would enable one to rename ‘myFile’ to ‘myNewFile’ ?

A

mv myFile myNewFile

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which command would create a symbolic link to the ‘/etc/passwd’ file in the current directory?

A

ln -s /etc/passwd .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which command would create a new archive named ‘archive.tar’ in the directory ‘/root’, containing the contents of the entire ‘/etc’ directory?

A

tar -cvf /root/archive.tar /etc

The ‘-v’ option can be omitted as it simply lists the verbose output during execution.
The ‘-f’ option is used to specify the name of the archive file. It can often be omitted.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How would one add a single file named ‘singleFile’ to the already existing ‘archive.tar’ file?

A

tar -rvf archive.tar singleFile

The ‘-r’ option appends files to an existing archive.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which command lists the contents of a tar archive ‘archive.tar’ without actually extracting it?

A

tar -tvf archive.tar

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Which command would extract the contents of the ‘/root/archive.tar’ file and move the contents to the ‘/tmp’ directory?

A

tar -xvf /root/archive.tar -C /tmp

Extracting also works like this for compressed archives as tar will automatically recognize compressed content and then decompress it during extraction.

The ‘-C’ option stands for ‘change directory and tells tar to change the directory to where the command output will be placed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Which command would create a compressed archive ‘archive.tar’ of everything within the ‘/etc’ directory and place that compressed archive in the ‘/home’ directory?

A

tar -czvf /home/archive.tar.gz /etc
tar -cjvf /home/archive.tar.bz2 /etc
tar -cJvf /home/archive.tar.xz /etc

All three of the above options work. The ‘-z’ option compresses with gzip. The ‘-j’ option compresses via bzip2 and the ‘-J’ option compresses via xz.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which command would enable one to set the system time to 4:24 P.M. ?

A

date -s 16:24

Normally, ‘date’ retrieves the current time setting but the ‘-s’ option allows one to set the time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Which command sets the hardware time from the system clock?

A

hwclock –systohc
hwclock -w

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Which command shows epoch time as human-readable time?

A

date -d ‘@nnnnnnnn’

‘nnnnnnnn’ is the number of seconds since midnight on January 1st, 1970.

The ‘-d’ option specifies that the ‘date’ command will take a string specifying a time rather than just displaying the current time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Which command enables you to use NTP time on your server?

A

timedatectl set-ntp 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Which configuration file contains the list of NTP servers to be used?

A

/etc/chrony.conf

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Which command displays information about the current time sources that ‘chronyd’ is currently accessing?

A

chronyc sources

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Which commands would you use to display only line number 5 from the file ‘/etc/passwd’?

A

head -n 5 /etc/passwd | tail -n 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Which command filters out just the first field from the file ‘/etc/passwd’?

A

cut -d : -f 1 /etc/passwd

The ‘-d’ option specifies the delimiter used in the file. The ‘-f’ option specifies which field to retrieve.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Which extended regular expression will match all files/subdirectories (including ‘/etc’) within the ‘/etc’ directory?

A

grep -rE ‘/etc(/.*)?’

The ‘.’ matches any single character.
The ‘*’ matches zero to an infinite number of the preceding character.
The ‘?’ matches zero or one of the preceding character.
The ‘-r’ option specifies to search files in the current directory and all subdirectories.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Which regular expression will match lines that do not begin with a ‘#’ in the file ‘/etc/services’?

A

grep -v ‘^#’ /etc/services

The ‘-v’ option shows lines that do not match the regular expression.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Which grep command enables you to see ‘text’ as well as ‘TEXT’ in a file named ‘/home/user/files’?

A

grep -i ‘text’ /home/user/files

The ‘-i’ option makes the regex case insensitive.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Which command enables you to replace all occurrences of the word user with the word users in ~/samplefile?

A

sed -i ‘s/user/users/g’ ~/samplefile

The ‘-i’ option for sed stands for ‘in-place’ which specifies that the command should edit the file rather than simply outputting the results.

If the ‘g’ at the end of the command is omitted, only the first occurrence of ‘user’ would be replaced.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

Which command will install the appropriate tools for working with containers in RHEL 9?

A

sudo dnf install container-tools

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Which command will list both currently running containers and ones that are now inactive?

A

podman ps -a

If you want to list the root containers, you must use ‘sudo podman ps’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Which command would run nginx in a container in the background?

A

podman run -d nginx

The ‘-d’ option stands for detached mode. This essentially runs it like a background daemon.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

Which command will run an nginx container in interactive TTY mode, along with the ‘/bin/sh’ command?

A

podman run -it nginx /bin/sh

The ‘-i’ option stands for interactive while the ‘-t’ option gives access to the container TTY. Adding ‘/bin/sh’ to the end tells the container to run the ‘/bin/sh’ command rather than the default command. ‘/bin/sh’ may be the only shell available as containers are minimal environments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What are the two common ways to exit interactive mode in a container?

A
  1. You could type ‘exit’ into the terminal. This could stop the whole container depending on the primary container command.
  2. You could use ‘Ctrl-P, Ctrl-Q’ to detach. This approach ensures that in all cases the container continues running in the background in detached mode.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

How could you reconnect to a shell running within a container named ‘mybusybox’ ?

A

podman attach mybusybox

This would re-enter the shell running inside the ‘mybusybox’ container.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

Which file specifies the container registries to be used?

A

‘/etc/containers/registries.conf’ or the user-specific file ‘~/.config/containers/registries.conf’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

Which commands will easily show which container registries are currently being used?

A

podman info | grep -A 10 registries

‘podman info’ shows general Podman related system information. One could then pipe the output of that command into grep and search for the lines following the ‘registries’ string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

Which command will allow you to access the ‘registry.access.redhat.com’ registry?

A

podman login registry.access.redhat.com

Some container registries require that you authenticate before pulling container images.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

Which command would search all container registries currently being used for ‘mariadb’ ?

A

podman search mariadb

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

Which command allows you to inspect container images before pulling them to your machine?

A

skopeo

‘podman inspect’ only works on images that are already pulled.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

Which command lists the container images that are locally available? (already pulled)

A

podman images

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

Which command would allow you to see the command that a container image named ‘docker.io/library/nginx’ will run by default when it is started as a container?

A

podman inspect docker.io/library/nginx | grep -A 10 Cmd

The ‘Cmd’ section of the inspect output shows the list of default commands to be executed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

Which command prints the kernel release for the system?

A

uname -r

The ‘-r’ option specifies kernel release information.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

Suppose you have a container running nginx named ‘mynginx’ and you want to get its kernel release. Which set of commands would accomplish that?

A

podman exec mynginx uname -r

‘podman exec’ executes a command in a running container.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

How would you run an nginx container named ‘mynginx’ and make it accessible on host port 8080?

A

podman run –name mynginx -d -p 8080:80 nginx

The ‘-p’ option allows one to specify port mapping.
The host firewall must also be updated to allow traffic through TCP port 8080.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

How could you find instructions on how to correctly run a specific container named ‘examplecontainer’ ?

A

podman inspect examplecontainer | grep -A 10 usage

The ‘usage’ section can sometimes include instructions for how to run the container. ‘podman logs examplecontainer’ could also include log information in case of a container failure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

How could you run the ‘mysql’ container with the ‘MYSQL_ROOT_PASSWORD’ environment variable set to ‘password’ ?

A

podman run -d -e MYSQL_ROOT_PASSWORD=password mysql

The ‘-e’ option allows one to specify an environment variable. Multiple ‘-e’ options can be used in sequence.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

What two things must be prepared before a host directory can be accessed from within a container?

A
  1. The host directory must be writable for the user account that runs the container.
  2. The appropriate SELinux context label must be set to container_file_t.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

Which commands would first create the directory ‘/opt/dbfiles’ and then allow others to write to that directory?

A

mkdir /opt/dbfiles; chmod o+w /opt/dbfiles

The ‘o+w’ part gives write permissions to everyone who isn’t the user owner or the group owner.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

Which command would run a ‘mariadb’ container with the ‘MYSQL_ROOT_PASSWORD’ environment variable set to ‘password’ and also mount the ‘user/dbfiles’ directory from the host machine to the ‘/var/lib/mysql’ directory from inside the container?

A

podman run -d –name mymariadb -v user/dbfiles:/var/lib/mysql:Z -e MYSQL_ROOT_PASSWORD=password mariadb

The ‘-v’ option stands for volume and is used to bind a mount volume into the container. Adding the ‘Z’ option to the end of the volume mount string is necessary to ensure that the correct SELinux labels are set.

Keep in mind, the user who is running the container must be the owner of the host directory that is being mounted.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

Which command makes Systemd services enabled for the user ‘student’ start running at system start rather than user log-in?

A

loginctl enable-linger student

Linger also ensures that the services will continue running after the user logs out.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
Q

Suppose you want to create a Systemd unit file that will start a container. Which directory must be created to store this Systemd unit file?

A

~/.config/systemd/user

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

Suppose you want to create a Systemd unit file that will start a container. Which command should be used to create a Systemd unit file based on a container named ‘mydb’ ?

A

podman generate systemd –name mydb –files –new

The ‘–files’ option specifies that a ‘.service’ file should be generated. The ‘–new’ option specifies that a new container should be created when the Systemd unit is started and that it should be deleted when stopped.

This ‘.service’ unit file should be generated inside the ~/.config/systemd/user directory. It should also be performed via an SSH session as the relevant user.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
49
Q

Once a Systemd unit file for a container named ‘mydb’ has been created, what two commands should be performed to ensure that it is detected and starts on reboot?

A

systemctl –user daemon-reload
systemctl –user enable container-mydb.service

The ‘daemon-reload’ option ensures that Systemd detects the changes. After a reboot, the ‘ps faux’ command should show that the ‘mydb’ container is running successfully.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
Q

Which command switches to the ‘tty4’ virtual terminal?

A

chvt 4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
51
Q

Which command would allow one to securely connect to remote host ‘server2’ as user ‘linda’ with graphical applications support?

A

ssh -Y linda@server2

The ‘-Y’ option enables support for graphical applications to be used via SSH.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
52
Q

Which file can be edited to create a systemwide configuration that permits ‘X forwarding’, which is starting graphical applications through an SSH session.

A

Edit the ‘/etc/ssh/ssh_config’ file to include the following line:

    ForwardX11 yes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
53
Q

Which command can remotely copy all of the ‘/etc’ directory and its contents from server2 to the ‘/tmp’ directory on the local machine.

A

scp -r server2:/etc/ /tmp

‘scp’ copies files between hosts on a network via SSH. The ‘-r’ option recursively copies entire directories.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
54
Q

How could one open an SFTP prompt as user ‘student’ on ‘server2’ ? Then, how would one upload the ‘/etc/hosts’ file to ‘server2’ ?

A

sftp student@server2
put /etc/hosts

In an ‘sftp’ prompt, ‘put’ is used to upload files to the remote server. ‘get’ would be used to download a file to the current directory on the local machine. ‘lcd’ and ‘lpwd’ are used to run the ‘cd’ and ‘pwd’ commands back on the local machine.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
55
Q

What would the procedure be for configuring key-based login as the root user via SSH between server1 and server2?

A

Run ‘ssh-keygen’ as the root user and accept the defaults.
Run ‘ssh-copy-id server2’ as root to copy the public key to server2.

Now, ‘ssh server2’ should automatically connect to server2 as root without asking for the password. Make sure you are logged in as ‘root’ on ‘server1’ for this process.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
56
Q

Which command will display information about a user, including the UID and GIDs for all groups to which the user belongs?

A

id

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
57
Q

Which command would give the user ‘lisa’ access to all sudo privileges?

A

usermod -aG wheel lisa

All members of the group ‘wheel’ have full sudo privileges. This command adds lisa to the group wheel. The ‘-a’ option stands for append and ‘-G’ specifies a group.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
58
Q

Which file contains configuration details for sudo privileges?

A

/etc/sudoers

Drop-in configuration files can also be added to the ‘/etc/sudoers.d’ directory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
59
Q

Which command allows you to safely edit the sudo privileges?

A

visudo

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
60
Q

Which line should be added to ‘/etc/sudoers’ to allow user ‘lisa’ to add new users and change their passwords but not for the root account?

A

lisa ALL=/usr/bin/useradd, /usr/bin/passwd, ! /usr/bin/passwd root

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
61
Q

How could one extend the lifetime of the token that is given for sudo commands to 4 hours?

A

Add the following line to ‘/etc/sudoers’

‘Defaults timestamp_timeout=240’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
62
Q

What is the best way to use pipes with sudo privileges? How could we use this method for reading the contents of ‘/etc/passwd’ and searching for the root user?

A

sudo sh -c “cat /etc/passwd | grep root”

This allows everything in quotes to be executed as root.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
63
Q

Which file stores passwords for user accounts along with other password details?

A

/etc/shadow

The second field (delimited by colons) stores the hashed password. If the field begins with an ‘!’ then login for the account is currently disabled.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
64
Q

Which command would delete user ‘lisa’ along with her home directory?

A

userdel -r lisa

The ‘-r’ option removes the user’s home directory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
65
Q

Which command would create a user ‘linda’ who is a member of the secondary groups ‘sales’ and ‘ops’ with ‘UID 1201’ and add a home directory to the user account as well.

A

useradd -m -u 1201 -G sales,ops linda

The ‘-m’ option creates the home directory. This overrides the ‘CREATE_HOME’ line in ‘/etc/login.defs’

The ‘-u’ option allows for a custom UID to be used. And the ‘-G’ option allows for additional groups to be specified.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
66
Q

Which configuration file is used to specify which files/directories are created by default in a user’s home directory?

A

/etc/skel

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
67
Q

How could you change the default shell of user ‘caroline’ to prevent login?

A

usermod caroline -s /sbin/nologin

The ‘-s’ option specifies the login shell for the user account.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
68
Q

Using the ‘passwd’ command, how could one set the password for user ‘linda’ to a minimal usage period of 30 days and an expiry after 90 days, with a warning generated 3 days before expiry?

A

passwd -n 30 -w 3 -x 90 linda

The ‘-n’ option specifies the minimum usage period. The ‘-w’ option specifies the number of days before the expiration date that a warning be sent out while ‘-x’ specifies the actual expiration date.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
69
Q

Which command would set the user account for ‘bob’ to expire on December 31st, 2025?

A

chage -E 2025-12-31 bob

The ‘-E’ option specifies the account expiration date.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
70
Q

Which command allows one to interactively set the password properties for the user ‘anna’ ?

A

chage anna

This will interactively prompt you for each change to be made.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
71
Q

Which command lists current password management settings for user ‘anna’ ?

A

chage -l

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
72
Q

What four files are used when constructing a user environment?

A

‘/etc/profile’ is used for default settings for all users when starting a login shell

‘/etc/bashrc’ is used to define defaults for all users when starting a subshell

’~/.profile’ or ‘~/.bash_profile’ specifies settings for one user applied when starting a login shell

’~/.bashrc’ specifies settings for one user applied when starting a subshell

These four files are read in the order they are listed upon login.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
73
Q

How would one set the default editor to ‘vim’ for the user ‘lisa’ ?

A

Add the following line to ‘/home/lisa/.bashrc’

‘export EDITOR=/usr/bin/vim’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
74
Q

Which file holds group information, such as the members for each group?

A

/etc/group

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
75
Q

Which command will list the users that are members of group ‘sales’ ?

A

lid -g sales

The ‘-g’ option specifies that a group will be the argument. If used without the ‘-g’ option, ‘lid’ will list groups to which the invoking user belongs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
76
Q

Which command creates new groups?

A

groupadd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
77
Q

Which command will remove the user ‘linda’ from the group ‘students’ ?

A

gpasswd -d linda students

The ‘gpasswd’ command allows one to administer the ‘/etc/group’ and ‘/etc/gshadow’ files. The ‘-d’ option stands for delete and allows one to specify a user to be removed from a group.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
78
Q

Which command will show all files on the machine that have the user ‘bob’ as their owner?

A

find / -user bob

This searches everything within the directory ‘/’ for files that are owned by user ‘bob’

The ‘find’ command can also use ‘-group’ to search for files owned by a specific group.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
79
Q

Which command will change ownership for the directory ‘/files’ and everything within it to the user ‘linda’ ?

A

chown -R linda /files

The ‘-R’ option tells the command to recursively set the permissions for everything within the directory as well as the directory itself.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
80
Q

Which command will change the group owner of the directory named ‘/photos’ and its contents to ‘artists’ ?

A

chown -R :artists /photos
chgrp -R artists /photos

The syntax for specifying users/groups with chown is:
‘chown user:group file’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
81
Q

Which command will list the groups a user belongs to?

A

groups

The first group in the list output is the current primary group for the user.

‘sudo lid “username” ‘ also works.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
82
Q

Which command can be used to temporarily change the primary group for the current user to ‘sales’ ?

A

newgrp sales

This will open a new shell, in which the new temporary primary group is set to ‘sales’ until the user logs out or uses the ‘exit’ command.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
83
Q

What are the numeric values of the read, write and execute permissions on Linux?

A

Read: 4
Write: 2
Execute: 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
84
Q

Which command would allow the owner of the file ‘/somefile’ to read, write and execute, the group owner to read and execute and all others to read and execute?

A

chmod 755 /somefile

This uses ‘chmod’ in absolute mode which replaces all current permissions with the ones given as an argument.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
85
Q

Which command will give write permissions to the group owner of ‘/home/somefile’ and take away read permissions for all other users?

A

chmod g+w,o-r /home/somefile

This uses ‘chmod’ in relative mode when permissions can be added/subtracted from the already existing configuration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
86
Q

Which command would give execute permissions to all three permission groups (users, groups, others) for every subdirectory inside ‘~/files’ in addition to the ‘~/files’ directory itself?

A

chmod -R a+X ~/files

The ‘a’ stands for all three permission groups. The ‘-R’ option recursively applies permissions to everything within the directory given. Lastly, the uppercase ‘X’ only sets execute permissions on the subdirectories rather than both the directories and the files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
87
Q

Suppose there is an executable file named ‘/usr/bin/action’ and it is owned by the root user. Which command can be used to allow any user to run the executable file but only as the owner (root).

A

chmod u+s /usr/bin/action

’s’ means both execute and SUID are set while an uppercase ‘S’ would mean only SUID is set.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
88
Q

Suppose there is a shared directory ‘/accounting’ that is owned by the ‘accounting’ group. Which command would make it so that every file/subdirectory created inside ‘/accounting’ inherits the group ownership?

A

chmod g+s /accounting

’s’ means both SGID and execute are set while an uppercase ‘S’ would mean only SGID is set.

If just SGID is set on a file, then users would execute that file as the group owner.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
88
Q

Suppose there is a shared directory ‘/accounting’ that is owned by the ‘accounting’ group. Which command would make it so that only users who own a file/directory within ‘/accounting’ are allowed to delete them?

A

chmod +T /accounting

This is known as the sticky bit. This prevents users from deleting files from other users.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
89
Q

Which command will list the umask that is set for the current user?

A

umask

The ‘umask’ is subtracted from the maximum permissions of 666 for a file and 777 for a directory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
90
Q

What steps would you take to change the default umask to 022 for every user?

A
  1. Create the ‘/etc/profile.d/umask.sh’ file.
  2. Add the line ‘umask 022’ and save the changes.
  3. On next login, the umask should be set to 022 for everyone.

A user-specific umask can be defined in the ‘~/.profile’ or ‘~/.bash_profile’ file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
91
Q

Which command would make the memory used for the data in file ‘/somefile’ be written over with 0s after deletion?

A

chattr +s /somefile

The ‘+s’ attribute overwrites the blocks where the file was stored with 0s after the file has been deleted. This makes sure that recovery of the file is not possible after it has been deleted.

Attributes set via ‘chattr’ do their work regardless of the user who accesses the file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
92
Q

Which command would make the file ‘/root/myfile’ immutable? This would prevent anyone from editing/deleting it, including the root user.

A

chattr +i /root/myfile

This attribute can be removed with ‘chattr -i’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
93
Q

Which command can be used to register a RHEL system?

A

subscription-manager register

This will prompt for the name of your Red Hat user account as well as your password, and after you enter these, your RHEL server will be registered.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
94
Q

Once registered, which command will subscribe the system and give access to updates for Red Hat products?

A

subscription-manager attach –auto

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
95
Q

Which directory stores the ‘.repo’ files that are used to configure the server to use specific repositories?

A

‘/etc/yum.repos.d’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
96
Q

What five parameters are commonly found in a ‘.repo’ repository client file?

A

[label]
name=
baseurl=
enabled=
gpgcheck=

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
97
Q

Suppose the contents of the RHEL 9 installation disk is copied to the ‘/repo’ directory. Which command would automatically create the repository client file for the BaseOS repository?

A

dnf config-manager –add-repo=file:///repo/BaseOS

Since the repository is installed locally, the ‘file://’ URI must be used. Ensure that the ‘gpgcheck’ parameter in the generated repository file is set to 0 to prevent dnf from doing GPG checks on incoming packages.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
98
Q

Which command will search through the package names and summaries for a provided keyword?

A

dnf search “keyword”
dnf search all “keyword”

The ‘dnf search all’ version of the command also searches through the large package descriptions in addition to the names/summaries.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
99
Q

Which command would look for the package containing the file ‘Containerfile’ ?

A

dnf whatprovides */Containerfile
dnf provides */Containerfile
dnf wp */Containerfile

All three of these commands provide the same output. The ‘*’ is used because these commands only look for full pathnames.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
100
Q

Which command will retrieve information on the ‘nmap’ package?

A

dnf info nmap

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
101
Q

How would one list all packages that are installed on the server?

A

dnf list installed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
102
Q

Which command will update the kernel?

A

dnf update kernel

Unlike other ‘dnf update’ commands, updating the kernel will still keep the old version of the kernel around. During the boot process, you can choose which kernel version to use.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
103
Q

Which command would show information about the packages available in the group ‘Container Management’ ?

A

dnf group info “Container Management”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
104
Q

Which command would list all available package groups, including hidden subgroups?

A

dnf group list hidden

‘dnf group list’ only shows environment groups and not all subgroups.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
105
Q

Which command would allow you to undo the second action performed by dnf?

A

dnf history undo 2

When using ‘dnf history’ all dnf commands that were used by the user are listed. ‘dnf history undo’ then allows users to undo these actions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
106
Q

Which command will show the repositories that the system is currently using?

A

dnf repolist

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
107
Q

Which command would show all of the available streams for the ‘maven’ module?

A

dnf module list maven

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
108
Q

Suppose you want to use the ‘maven’ module with stream 8.1. Which command would show the profiles available for that specific module/stream?

A

dnf module info maven:8.1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
109
Q

Which command would enable the 8.2 stream for the ‘maven’ module?

A

dnf module enable maven:8.2

By default, a specific module stream is enabled. This is the module stream that will automatically be used when installing packages. This can be changed with the ‘dnf module enable’ command.

After switching streams, it is a good idea to execute ‘dnf distro-sync’ to ensure that all dependent packages that are not in the module itself are updated as well.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
110
Q

Which command would find the name of the RPM package that the ‘/bin/ls’ command belongs to?

A

rpm -qf /bin/ls

The ‘-q’ option stands for query. This option tells the command to query the package database. The ‘-f’ option takes a filename as an argument and will find the specific RPM package a file belongs to.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
111
Q

Which command would query the specific RPM file ‘httpd- 2.4.6-19.el7.centos.x86_64.rpm’ to see whether it contains any scripts before installation?

A

rpm -qp –scripts httpd- 2.4.6-19.el7.centos.x86_64.rpm

The ‘-p’ option is used to query RPM packages instead of the local RPM package database. The ‘–scripts’ option uses the RPM database to show scripts that are used in the package.

When querying a package, you need to refer to the complete filename, including the version number and all other information. Additionally, the ‘rpm’ command can only perform this query on RPM packages on the local machine. (either they are already installed or downloaded)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
112
Q

Which command can be used to download the ‘zsh’ package from a repository to the current directory?

A

dnf download zsh

The ‘yumdownloader’ command from the ‘yum-utils’ package used to be used instead.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
113
Q

Which command can be used to query packages from the repositories before they have been installed?

A

repoquery

This command is included in the ‘dnf-utils’ RPM package.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
114
Q

Which command will simply list the current network settings?

A

ip a
ip a s
ip addr show

All three of the above commands will work. This command will list all network interfaces on the computer, along with some of their configuration details.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
115
Q

Which command would temporarily change the link state to UP for the ‘eno2’ interface?

A

ip link set dev eno2 up

Every configuration change made with the ‘ip’ command is non-persistent.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
116
Q

Which command will show the link state of all network interfaces along with current link statistics?

A

ip -s link show

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
117
Q

Which command will list routing table information?

A

ip route show

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
118
Q

Which command can list all TCP ports that are currently listening?

A

ss -lt

The ‘ss’ command stands for socket statistics. The ‘-l’ option specifies that only ‘Listening’ ports should be listed while the ‘-t’ option specifies that only TCP ports should be shown.

Another useful option is the ‘-n’ option which tells the command not to resolve service names but instead show actual numeric port numbers. For example, normally ‘ssh’ would be listed but the ‘-n’ option would show 22 instead.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
119
Q

Which command can show the status of the main network management service?

A

systemctl status NetworkManager

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
120
Q

Which command will list all connections?

A

nmcli con show

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
121
Q

Which command would create a new connection named ‘main-connection’ on interface ‘ens33’ that receives its IPv4 configuration dynamically via DHCP?

A

nmcli con add con-name main-connection type ethernet ifname ens33 ipv4.method auto

The ‘nmcli’ connection has great command-line completion to help in composing these longer commands. Just make sure the ‘bash-completion’ package is installed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
122
Q

Suppose you have a static connection named ‘static-connection’ and you want to add a second IP address ‘10.0.0.62/24’ to its IPv4 configuration. Which command will accomplish this?

A

nmcli con mod static-connection +ipv4.addresses 10.0.0.62/24

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
122
Q

Suppose you have a static connection named ‘static-connection’ and you wish to add a DNS server with the address ‘8.8.8.8’ to its configuration. Which command will accomplish this?

A

nmcli con mod static-connection ipv4.dns 8.8.8.8

Notice that while adding a network connection, you use ‘ip4’, but while modifying parameters for an existing connection, you often use ‘ipv4’ instead.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
122
Q

Suppose you created another network connection named ‘main-connection’ and you wish to change that to the active connection. Which command will accomplish this?

A

nmcli con up main-connection

123
Q

Which command will open a text user interface that allows you to create/edit network connections?

A

nmtui

After editing the connection, you need to deactivate it and activate it again.

124
Q

Which directory stores the ‘.nmconnection’ network configuration files on RHEL 9?

A

/etc/NetworkManager/system-connections

Older versions of RHEL used the ‘/etc/sysconfig/network-scripts’ directory. If the NetworkManager service finds legacy connection scripts in this directory, they will still be used.

125
Q

Which command will set the host name of the computer to ‘myhost.example.com’ ?

A

hostnamectl set-hostname myhost.example.com

You can also edit the ‘/etc/hostname’ file.

Additionally, you can simply execute ‘hostnamectl hostname myhost.example.com’

126
Q

Which file stores hostname resolution information?

A

/etc/hosts

127
Q

Which line could be added to ‘/etc/hosts’ to allow the name ‘server5.example.com’ to be resolved to the IP address ‘192.168.20.12’ ?

A

192.168.20.12 server5.example.com

128
Q

Which file stores the information for DNS name server resolution?

A

/etc/resolv.conf

Do not edit /etc/resolv.conf directly, as it will be overwritten the next time you restart NetworkManager.

129
Q

Which command can verify that host name resolution to ‘server2’ is working?

A

getent hosts server2

This command searches in both /etc/hosts and DNS to resolve the host- name that has been specified.

130
Q

Which character can be added to the end of a command to run it in the background?

A

&

For example: ‘sleep 3600 &’

131
Q

Which command will move the last job that was started in the background back as a foreground job?

A

fg

A specific job ID can be used to bring a specific command back to the foreground.

132
Q

Suppose you have a job running in the foreground that you wish to freeze and then send to the background. Which two steps will accomplish this?

A
  1. ‘Ctrl-Z’
  2. ‘bg’

‘Ctrl-Z’ will temporarily stop a job so that it can be managed while ‘bg’ will continue the job that has just been frozen using ‘Ctrl-Z’ in the background.

133
Q

Which command will list all jobs running from the current shell?

A

jobs

134
Q

What happens to a background process if its parent process is terminated?

A

The child process becomes a child of ‘systemd’

135
Q

What is an easy way to identify Kernel processes?

A

When listing all processes, the name of Kernel processes is in between [] brackets.

A system administrator cannot manage Kernel threads.

136
Q

Which command will list all processes along with hierarchical relationships between parent and child processes?

A

ps fax

137
Q

Which command is the best way to receive a short summary of the active processes?

A

ps aux

If used without arguments, ‘ps’ will show only those processes that have been started by the current user.

138
Q

Suppose you run the ‘dd if=/dev/zero of=/dev/null &’ command as a background process. Which two steps can be taken to lower the priority of this process to 10?

A
  1. ps aux | grep dd
  2. renice -n 10 -p 1234 (assuming 1234 is the PID from step 1)

The first step will find the PID for the specific process. The second step will lower the priority of the command. Regular users can only decrease the priority of a running process.

139
Q

Suppose you want to execute the command ‘dd if=/dev/zero of=/dev/null &’ with a priority of 5. How can you do this?

A

nice -n 5 dd if=/dev/zero of=/dev/null &

Do not set process priority to –20; it risks blocking other processes from getting served.

140
Q

Which command can show information about running processes in real time?

A

top

Using ‘r’ within the ‘top’ command is another way to renice priority values for processes.

141
Q

Suppose you have a process named ‘dd’ with a PID of 1370 and you wish to terminate it. How can you do this?

A

kill 1370
pkill dd

The ‘pkill’ command takes a process name rather than a PID.

When executed normally, the ‘kill’ command sends the ‘SIGTERM (15)’ signal to the process. If you wish to specify the ‘SIGKILL (9)’ signal, you could’ve executed ‘kill -9 1370’

142
Q

Suppose you have three ‘dd’ processes running in the background and you wish to terminate all of them simultaneously. How can you accomplish this?

A

killall dd

143
Q

Suppose you have a zombie process (process that has completed execution but is still listed in the process table) running underneath a parent process with the PID 2072. How can you eliminate this zombie process?

A

kill -SIGCHLD 2072

This will tell the parent process to remove its child processes. Now the zombie will get adopted by systemd, and after a few seconds it will be removed.

144
Q

How can you find the number of CPU cores in your system?

A

lscpu

‘lscpu’ will show various information about the CPU on the machine.

145
Q

Which command will show current load average statistics?

A

uptime

The load average is shown for the last 1, 5, and 15 minutes. The load average should not be higher than the number of CPU cores in your system.

146
Q

How can you verify that the service that provides a daemon that monitors system activity and provides performance profiles is running?

A

systemctl status tuned

147
Q

How can you show which ‘tuned’ profile is currently active?

A

tuned-adm active

‘tuned-adm list’ will show the profiles that are available on the server.

148
Q

Suppose you find from the results of the ‘tuned-adm recommend’ command that the recommended profile for your machine is ‘throughput-performance’. How can you change this to be your active profile?

A

tuned-adm profile throughput-performance

149
Q

Which directory contains default unit files that have been installed from RPM packages.

A

/usr/lib/systemd/system

You should never edit these files directly.

150
Q

Which directory contains custom unit files?

A

/etc/systemd/system

151
Q

Which command will list service units on the system?

A

systemctl -t service
systemctl list-units -t service

Both of the above commands will work. The ‘-t’ option is used to specify the unit file type.

152
Q

Which command will list available Systemd unit types?

A

systemctl -t help

153
Q

Which command will list both active and inactive service units?

A

systemctl list-units -t service –all

154
Q

How would you list all units that are required before the ‘vsftpd’ unit can be started?

A

systemctl list-dependencies vsftpd –reverse

155
Q

What are some of the common keywords that can be used in unit files to ensure accurate dependency management?

A

Requires: If this unit loads, units listed here will load also. If one of the other units is deactivated, this unit will also be deactivated.

Requisite: If the unit listed here is not already loaded, this unit will fail.

Wants: This unit wants to load the units that are listed here, but it will not fail if any of the listed units fail.

Before: This unit will start before the unit specified with Before.

After: This unit will start after the unit specified with After.

156
Q

For the current user, how could you make ‘vim’ the default editor for all commands?

A

Add the line ‘export EDITOR=”/usr/bin/vim”’ to the files ‘~/.bashrc’ and ‘ ~/.bash_profile’

’~/.bash_profile’ is executed for login shells.

The Systemd default editor can be set specifically by adding ‘export SYSTEMD_EDITOR=”/usr/bin/ vim”’ to the ‘~/.bashrc’ file.

157
Q

Suppose you wish to edit the ‘sshd.service’ via the ‘systemctl edit’ command. Which file will be created to contain these new configurations?

A

/etc/systemd/system/sshd.service.d/override.conf

All settings that are applied in this file overwrite any existing settings in the service file in ‘/usr/lib/systemd/system’.

158
Q

How could you list all available configuration options for the ‘httpd’ service unit file?

A

systemctl show httpd.service

159
Q

Suppose you want the ‘httpd’ service to always restart if it is terminated. You want this service to automatically restart 5 seconds after termination. How would you accomplish this?

A
  1. Use ‘systemctl edit httpd.service’ to edit the configuration.
  2. Add a ‘[Service]’ section that includes the ‘Restart=always’ and ‘RestartSec=5s’ lines.
  3. Enter ‘systemctl daemon-reload’ to ensure that Systemd picks up the new configuration.
160
Q

Which three sections are commonly found in Systemd service unit files?

A

‘[Unit]’ Describes the unit and defines dependencies.

‘[Service]’ Describes how to start and stop the service. Normally includes an ‘ExecStop’ or ‘ExecStart’ line.

‘[Install]’ Indicates in which target this unit has to be started.

161
Q

Suppose you have a Systemd service named ‘logrotate.service’ and you wish to schedule it to run at specific times. What would be the name of the Systemd unit file responsible for this scheduling?

A

logrotate.timer

The service unit defines how the service should be started, and the timer defines when it will be started. If you need a service to be started by a timer, you enable the timer, not the service.

162
Q

Timer unit files for Systemd use a [Timer] section to specify the scheduling details. What are some of the common options found in this section?

A

OnCalendar “Describes when the timer should execute.”

AccuracySec “Indicates a time window within which the timer should execute.”

Persistent “As a modifier to ‘OnCalendar=daily’, it would specify that the last execution time should be stored on disk, so that the next time it executes is exactly one day later.”

163
Q

When creating new cron jobs, which three locations can be used to store their configurations?

A

/etc/cron.d
/etc/cron.hourly /etc/cron.daily /etc/cron.weekly
/var/spool/cron

Jobs in ‘/var/spool/cron’ are created via the ‘crontab -e’ command after logging in as that user or via the ‘crontab -e -u “username”’ command as root.

The jobs in the ‘hourly/daily/weekly/monthly’ directories will run automatically due to anacron.

164
Q

Which files can be used to limit which users are allowed to schedule cron jobs?

A

/etc/cron.allow
/etc/cron.deny

If the cron.allow file exists, a user must be listed in it to be allowed to use cron. If the /etc/cron.deny file exists, a user must not be listed in it to be allowed to set up cron jobs. Both files should not exist on the same system at the same time.

165
Q

How would you schedule a cron job via ‘crontab -e’ that will execute the following command every weekday at 2 AM:

logger message from root

A
  1. Type ‘crontab -e’ to open a new file in ‘/var/spool/cron’
  2. Add the line ‘0 2 * * 1-5 logger message from root’
  3. Save the changes and exit the editor
166
Q

How would you schedule a cron job via the ‘timed directories’ that will, every hour, log a message with the date at time of execution?

A
  1. Create a file with any name in ‘/etc/cron.hourly’
  2. Add the line ‘logger Writing log at $(date)’
  3. Save the changes and exit the editor
  4. Add execute permissions to the file via ‘chmod +x’

If you fail to make it executable, it will not work.

167
Q

Which service is used to schedule a non-repeating job to run once at a specific time?

A

atd

‘atd’ is the name of the service while the command used to actually schedule a job is ‘at’

168
Q

How could you schedule a job that will run only once at 3:00 P.M. and log the message ‘this is a single scheduled message’ ?

A
  1. Execute ‘at 15:00’
  2. Type ‘logger this is a single scheduled message’
  3. Press ‘Ctrl-D’ to finish scheduling the command

The ‘atq’ command will list all of the ‘atd’ jobs that are currently scheduled. ‘atrm’ can be used to cancel a scheduled ‘atd’ job.

169
Q

Suppose you want to create a Systemd timer for ‘logrotate.service’ that will run the service once a day every day. How could you accomplish this?

A

Create the ‘logrotate.timer’ file in the ‘/etc/systemd/system’ directory and include the following:

[Unit]
Description=Daily rotation of log files Documentation=man:logrotate(8) man:logrotate.conf(5)

[Timer]
OnCalendar=daily
AccuracySec=1h
Persistent=true

[Install]
WantedBy=timers.target

170
Q

Which directory stores log files that are created by the ‘rsyslogd’ service?

A

/var/log

171
Q

Which command would allow you to view logs being added to the ‘/var/log/messages’ file in real time?

A

tail -f /var/log/messages

172
Q

Which directory stores log messages created by the ‘systemd-journald’ service?

A

/run/log/journal

This journal is cleared upon system reboot. To make the journal persistent between system restarts, you should create a directory ‘/var/log/journal’ and set the appropriate ownership settings.

173
Q

Which command lists kernel-related log messages?

A

dmesg
journalctl –dmesg

174
Q

Suppose you want to show all messages with a priority ‘error’ that have been written since yesterday. Which command would accomplish this?

A

journalctl –since yesterday -p err

The ‘-p’ option allows for filtering of messages with a specific priority level.

175
Q

Which file is used to configure settings (such as permanent storage/log rotation) for the ‘systemd-journald’ service?

A

/etc/systemd/journald.conf

176
Q

What four possible configurations of the ‘Storage’ option in ‘/etc/systemd/journald.conf’ are used to determine how the journal is stored after system reboot/shutdown.

A

Storage=auto “The journal will be written on disk if the directory ‘/var/log/journal’ exists.”

Storage=volatile “The journal will be stored only in the ‘/run/log/journal’ directory.”

Storage=persistent “The journal will be stored on disk in the directory ‘/var/log/journal’. This directory will be created automatically if it doesn’t exist.”

Storage=none “No data will be stored, but forwarding to other targets such as the kernel log buffer or syslog will still work.”

177
Q

What is the process for making the Systemd journal persistent?

A
  1. Open a root shell and type ‘mkdir /var/log/journal’
  2. Before ‘systemd-journald’ can write the journal to this directory, you have to set ownership. Type ‘chown root:systemd-journal /var/log/journal’ followed by ‘chmod 2755 /var/log/journal’
  3. Use ‘systemctl restart systemd-journald’ to reload the new ‘systemd- journald’ parameters.

‘systemctl restart systemd-journal-flush’ can also be used to ask the journal daemon to flush any log data stored in ‘/run/log/journal’ into ‘/var/log/journal’ if persistent storage is enabled.

178
Q

Which directories/files store the configuration settings for the ‘rsyslogd’ service?

A

/etc/rsyslog.conf
/etc/rsyslog.d

179
Q

Suppose you want to create a snap-in file in the ‘/etc/rsyslog.d’ directory to configure ‘rsyslog’ to log debug messages to the ‘/var/log/messages-debug’ file. How can you do this?

A
  1. Create a file in ‘/etc/rsyslog.d/’ with the ‘.conf’ extension.
  2. Add the following line ‘*.debug /var/log/messages-debug’ and save the file.
  3. Restart ‘rsyslogd’ with ‘systemctl restart rsyslog’

‘rsyslog’ rules follow the structure ‘facility priority destination’

180
Q

Suppose you want the Apache service to log all errors (only error messages) to the ‘/var/log/httpd-error.log’ file. What steps can be taken to accomplish this?

A
  1. Open the file ‘/etc/httpd/conf/httpd.conf’ in an editor
  2. Verify it contains the line ‘ErrorLog syslog:local1’
  3. Open the file ‘/etc/rsyslog.conf’ in an editor
  4. Ensure the file contains the line ‘local1.=error -/var/log/httpd-error.log’
  5. Execute ‘systemctl restart rsyslog’

Using an equals sign in between the facility and priority ensures that only error messages will be logged rather than both errors and every priority above it.

Additionally, including a dash in front of the destination file tells ‘rsyslog’ to buffer the log messages before immediately committing them to the file for a more efficient write.

181
Q

Which file is used to configure the logrotate service?

A

/etc/logrotate.conf

The ‘/etc/logrotate.d’ directory can also be used to configure logging for specific services.

182
Q

Which command will list all disk devices available on the system in a hierarchical format?

A

lsblk

183
Q

Which utilities can be used to create MBR and GPT partitions?

A

‘fdisk’ can create both MBR and GPT partitions
‘gdisk’ can create GPT partitions

184
Q

What are the steps to creating a new 1GiB primary MBR partition on the device ‘/dev/sdb’ ?

A
  1. Execute ‘fdisk /dev/sdb’
  2. Enter ‘n’ to create a new partition
  3. Press ‘p’ to choose a primary partition rather than extended
  4. For the last sector, type ‘+1G’ to make this a 1-GiB partition
  5. Choose the partition type. Linux (83) is the default.
  6. Enter ‘w’ to write the changes to the disk and exit ‘fdisk’
185
Q

Suppose your ‘/dev/sdb’ device already has three MBR partitions but you want to have more than four partitions on the device. What are the steps to creating a 1GiB logical partition on this device?

A
  1. Execute ‘fdisk /dev/sdb’
  2. Type ‘n’ to create a new partition
  3. Enter ‘e’ to create an extended partition
  4. Accept the default sectors for the extended partition (it should fill the rest of the device)
  5. Press ‘n’ to create a logical partition within the extended partition
  6. Accept the default first sector
  7. For the last sector, enter ‘+1G’
  8. Enter ‘w’ to write the changes and exit ‘fdisk’

An extended partition is used only for the purpose of creating logical partitions. You cannot create file systems directly on an extended partition.

186
Q

What are the steps to creating a new 1 GiB GPT partition on ‘/dev/sdc’ ?

A
  1. Execute ‘gdisk /dev/sdc’
  2. Type ‘n’ to create a new partition
  3. Enter the number for the partition (usually best to accept default)
  4. Specify the size by entering ‘+1G’
  5. Specify the type of the partition (8300 is for a Linux filesystem)
  6. Enter ‘w’ to write the changes and exit ‘gdisk’
187
Q

Suppose you have a newly created ‘/dev/sdc1’ partition and you wish to create an XFS filesystem on it. How can you do this?

A

mkfs.xfs /dev/sdc1

If you use ‘mkfs’ without any further specification of which file system you want to format, an Ext2 file system will be formatted.

188
Q

Suppose you have an XFS filesystem on ‘/dev/sdb2’. How would you label that filesystem ‘XFSone’ ?

A

xfs_admin -L XFSone /dev/sdb2

The ‘-L’ option is used to specify a label name.

189
Q

Suppose you have an Ext4 filesystem on ‘/dev/sdc2’. How would you label that filesystem ‘ext4one’ ?

A

tune2fs -L ext4one /dev/sdc2

The ‘-L’ option is used to specify a label name.

190
Q

Which command will show (formatted in Mebibytes) how much memory (RAM) and Swap space is being used out of all that is available?

A

free -m

The ‘-m’ option is used to specify mebibytes.

191
Q

What are the steps to creating/initializing a 1 GiB Swap partition on the ‘/dev/sdd’ device? (assume new partition is ‘/dev/sdd4’)

A
  1. Execute ‘fdisk /dev/sdd’ (also works with gdisk)
  2. Enter ‘n’ to create a new partition and then specify the size to be ‘+1G’
  3. Enter ‘t’ to change the type to either 82 (fdisk) or 8200 (gdisk)
  4. Enter ‘w’ to write changes and exit
  5. Use ‘mkswap /dev/sdd4’ to format the new partition as swap space
  6. Use ‘swapon /dev/sdd4’ to switch on the newly allocated swap space
  7. For the swap space to be mounted automatically, add the following to the ‘/etc/fstab’ file: ‘/dev/sdd4 none swap defaults 0 0’
192
Q

Which command can be used to list block device information such as UUIDs?

A

blkid

This command often only works when executed as root.

193
Q

What two commands can be used to verify that changes made to ‘/etc/fstab’ are working?

A

findmnt –verify
mount -a

‘mount -a’ will mount all file systems that have a line in ‘/etc/fstab’ and are not currently mounted.

‘findmnt –verify’ will simply alert you if the syntax in ‘/etc/fstab’ is incorrect.

194
Q

Suppose you want to automatically mount the XFS filesystem on ‘/dev/vda2’ on the ‘/data’ directory. What line should be added to ‘/etc/fstab’ to accomplish this?

A

/dev/vda2 /data xfs defaults 0 0

195
Q

How could you configure Systemd to automatically mount the Ext4 filesystem ‘/dev/sdc1’ device on to the ‘/exercise’ directory?

A

Create the ‘/etc/systemd/system/exercise.mount’ file and add the following:

[Unit]
Before=local-fs.target

[Mount]
What=/dev/sdc1
Where=/exercise
Type=ext4

[Install]
WantedBy=multi-user.target

196
Q

What are the three layers when it comes to creating logical volumes?

A
  1. Physical volumes
  2. Volume groups
  3. Logical volumes
197
Q

Suppose you want to create a physical volume ‘/dev/sda1’ from the ‘/dev/sda’ device. How can you accomplish this?

A
  1. Create a new partition of type ‘lvm’ via ‘fdisk’ (8e) or ‘gdisk’ (8e00) and specify the size
  2. Save the changes with ‘w’
  3. Execute ‘pvcreate /dev/sda1’ to mark the new partition as an LVM physical volume
198
Q

Which command shows a summary of the physical volumes and their attributes?

A

pvs

Using ‘pvdisplay’ on specific partitions can give more detailed information.

199
Q

Suppose you have a physical volume ‘/dev/sdb3’ and you want to create a volume group ‘vgdata’ and add the physical volume to this volume group. How can you do this?

A

vgcreate vgdata /dev/sdb3

200
Q

Which command shows a summary of the volume groups on the system?

A

vgs

Using ‘vgdisplay’ on specific groups can give more detailed information.

201
Q

Suppose you have a volume group named ‘vgdata’ and you want to create a logical volume named ‘lvdata’ in this group. This logical volume should be 5 GiB in size. How can you accomplish this?

A

lvcreate -n lvdata -L 5G vgdata

The ‘-n’ option is used to specify the name of the LVM logical volume while the ‘-L’ option is used to specify an absolute size.

The ‘-l’ option can be used for relative sizes. For example ‘-l 50%FREE’ would specify that half of the available space on the volume group should be used.

202
Q

Which command shows a summary of all logical volumes?

A

lvs

203
Q

Suppose you have a volume group named ‘vgdata’ and you want to add both the ‘/dev/sdn1’ and ‘/dev/sdv1’ physical volumes to the group. How can you do this?

A

vgextend vgdata /dev/sdn1 /dev/sdv1

204
Q

Suppose you have an LVM logical volume named ‘lvdata’ in the group ‘vgdata’ and you want to resize it so that both it and the filesystem residing on it are 20 GiB larger. How can you do this?

A

lvextend -r -L +20G /dev/vgdata/lvdata

The ‘-r’ option specifies that the filesystem should be resized along with the logical volume.

The ‘-l’ option can also be used to specify relative sizes.

The size of an XFS file system cannot be decreased; it can only be increased. If you need a file system that can be shrunk in size, use Ext4, not XFS.

205
Q

Suppose your volume group ‘vgdata’ is using two physical volumes, ‘/dev/sdd3’ and ‘/dev/sdd4’. You want to remove the ‘/dev/sdd4’ physical volume from the volume group. How can you prepare this physical volume so that it can be safely removed?

A

pvmove /dev/sdd4 /dev/sdd3

This will move all of the extents used on ‘/dev/sdd4’ to ‘/dev/sdd3’

206
Q

Assuming no extents on ‘/dev/sdd4’ are being used by the ‘vgdata’ volume group, how can you remove this physical volume from the volume group?

A

vgreduce vgdata /dev/sdd4

207
Q

What must be done to enable the use of Stratis on a RHEL machine?

A
  1. Install the Stratis software using ‘dnf’ by installing the ‘stratis-cli’ and ‘stratisd’ packages
  2. Start and enable the user-space daemon, using ‘systemctl enable –now stratisd’
208
Q

Which command would create a new Stratis pool name ‘mypool’ from the block device ‘/dev/sde’ ?

A

stratis pool create mypool /dev/sde

209
Q

Suppose you have a Stratis pool named ‘mypool’ and you wish to add the ‘/dev/vdb’ block device to the pool. Which command would do this?

A

stratis pool add-data mypool /dev/vdb

210
Q

How can you create a new filesystem named ‘myfilesystem’ on the Stratis pool ‘mypool’ ?

A

stratis fs create mypool myfilesystem

Stratis only supports XFS filesystems.

211
Q

Which command lists all Stratis filesystems?

A

stratis fs list

212
Q

Suppose you have a Stratis filesystem that you wish to have mounted automatically on the ‘/data’ directory when the system boots. How can you accomplish this?

A
  1. Execute ‘stratis fs list’ to find the Stratis volume UUID
  2. Add the following line to /etc/fstab:

UUID=xxx /data xfs defaults,x-systemd.requires=stratisd.service 0 0

The UUID for the filesystem must be used when mounting Stratis filesystems. Additionally, the mount option ‘x-systemd.requires=stratisd.service’ must be included to ensure that Systemd waits to activate this device until the stratisd service is loaded.

213
Q

Suppose you have a Stratis filesystem named ‘mystratisfs’ in a Stratis pool named ‘mypool’ and you wish to create a snapshot named ‘mysnapshot’. Which command would do this?

A

stratis filesystem snapshot mypool mystratisfs mysnapshot

This snapshot could then manually be mounted (by name) and then accessed.

214
Q

Which directory contains files with status information about the CPU, memory, mounts, and more?

A

/proc

215
Q

Which file contains information about the RHEL version the machine is using?

A

/etc/redhat- release

216
Q

What Systemd service is responsible for continuously monitoring plugging and unplugging of new hardware devices?

A

systemd-udevd

‘udevadm monitor’ can be executed to monitor events that are processed while activating new hardware devices.

217
Q

Which command lists all kernel modules that are currently being used, along with modules that are using this module?

A

lsmod

218
Q

Which command would load the vfat kernel module along with its dependencies?

A

modprobe vfat

‘modprobe -r’ can be used to unload a module along with its dependencies (if allowed)

219
Q

Which command will upgrade the Linux kernel to the latest version?

A

dnf upgrade kernel

The kernel files for the last four kernels that you have installed on your server will be kept in the ‘/boot’ directory.

220
Q

What are the four Systemd targets that can be used while booting?

A

emergency.target
rescue.target
multi-user.target
graphical.target

221
Q

Which command will list all Systemd targets that are currently loaded and active?

A

systemctl –type=target

222
Q

Which command will list all Systemd targets that exist on the computer?

A

systemctl -t target –all

223
Q

Suppose you are logged in to a terminal at your server and you need to switch to rescue mode. Which command can do this?

A

systemctl isolate rescue.target

After finishing in rescue mode, ‘systemctl isolate reboot.target’ can be used to restart the computer.

224
Q

Suppose you want to set the ‘graphical.target’ as the default target. Which command will do this?

A

systemctl set-default graphical.target

‘systemctl get-default’ will display the current default target

To set the graphical.target as the default target, you need to make sure that the ‘server with gui’ RPM package group is already installed via ‘dnf’

225
Q

Which file can be edited by the administrator to apply changes to the GRUB 2 configuration?

A

/etc/default/grub

Additionally, the ‘/etc/grub.d’ directory contains complicated shellcode that can be used to further configure GRUB 2.

226
Q

On a BIOS system, where is the main configuration file for GRUB 2 located?

A

/boot/grub2/grub.cfg

227
Q

On a UEFI system, where is the main configuration file for GRUB 2 located?

A

/boot/efi/EFI/redhat/grub.cfg

228
Q

In the ‘/etc/default/grub’ file, which boot options should be removed from the ‘GRUB_CMDLINE_LINUX’ line in order to see messages during boot?

A

‘rhgb’ and ‘quiet’

With these options enabled, you will not see any messages scrolling by during boot.

229
Q

Which parameter in ‘/etc/default/grub’ is used to configure how long the server will wait for you to access the GRUB 2 boot menu upon system boot?

A

GRUB_TIMEOUT

For example ‘GRUB_TIMEOUT=10’ would make the server wait for 10 seconds on the GRUB 2 boot menu before continuing the boot procedure.

230
Q

Suppose you are on a BIOS system and you made some changes to the boot configuration. How can you write these changes to GRUB 2?

A

grub2-mkconfig -o /boot/grub2/grub.cfg

The ‘-o’ option is used to specify the file where the output should be sent to. On a UEFI machine, this file should be ‘/boot/efi/EFI/redhat/grub.cfg’

231
Q

Suppose you are in the GRUB 2 boot menu and you wish to configure Linux to boot into emergency mode? What are the steps to accomplishing this?

A
  1. Enter ‘e’ to configure boot parameters for the kernel you wish to use
  2. Find the line that starts with ‘linux $(root)/vmlinuz’
  3. At the end of this line, add ‘systemd.unit=emergency.target’
  4. Enter ‘Ctrl-X’ to to boot
232
Q

What are the steps to restarting a RHEL 9 server from a rescue disk?

A
  1. Restart the server from the installation disk (for a VM, this is configured in VM boot settings)
  2. Enter the ‘Troubleshooting’ menu
  3. Select ‘Rescue a Red Hat Enterprise Linux System’
  4. When prompted about finding an installed Linux system, press ‘1’ to continue
  5. Type ‘chroot /mnt/sysimage’ to ensure that all path references to configuration files are correct
  6. When finished, type ‘exit’ to quit the ‘chroot’ environment and then enter ‘reboot’ to restart the server
233
Q

Sometimes the GRUB 2 boot loader can break. Suppose you are already in a rescue disk environment and you have already changed the root directory via the ‘chroot /mnt/sysimage’ command. How can you reinstall GRUB 2?

A

For a KVM virtual machine server, execute ‘grub2-install /dev/vda’

For a physical server or VMWare/Virtual Box server, execute ‘grub2-install /dev/sda’

234
Q

How can you repair the ‘initramfs’ if it is damaged?

A

Enter the rescue environment and execute the ‘dracut –force’ command.

During boot, you will know that you have a problem with the ‘initramfs’ because you’ll never see the root file system getting mounted on the root directory, nor will you see any Systemd units getting started.

235
Q

Suppose there is a problem with one of the filesystem mounts and the boot procedure ends with the message ‘Give root password for maintenance.’ What can you do to try and fix this?

A
  1. Enter the root password
  2. Type ‘mount -o remount,rw /’ to make sure the root file system is mounted and writable
  3. Analyze the ‘/etc/fstab’ file and fix it
236
Q

Suppose you can’t remember the root password for a RHEL 9 machine. What are the steps to resetting it?

A
  1. Enter the GRUB 2 menu and press ‘e’ on the relevant kernel
  2. Find the line that loads the kernel and add ‘init=/bin/bash’ to the end of it
  3. Once the root shell is opened, type ‘mount -o remount,rw /’ to get read/write access to the root filesystem
  4. Create a new root password with the ‘passwd’ command
  5. Execute ‘touch /.autorelabel’ to create this file in the root directory. This file is necessary for SELinux to correctly set the security labels upon reboot.
  6. Type ‘exec /usr/lib/systemd/systemd’ to replace ‘/bin/bash’ with ‘Systemd’ as the new PID 1.

‘exec’ must be used to start Systemd because ‘exec’ will replace the current process with the new process given, rather than starting the process as a child process to the current process.

237
Q

For a Bash shell script, what would be the shebang?

A

!/bin/bash

This tells the subshell how to interpret the commands.

238
Q

Which command will print to the console the exit status of the last command?

A

echo $?

239
Q

Suppose you have a script named ‘helloscript’ and it is not executable (was not given execute permissions with ‘chmod’). How can you execute this script?

A

bash helloscript

240
Q

In Bash, which special variable refers to all arguments that were used when starting the script?

A

$@

The ‘$@’ variable can be iterated over via a for loop in Bash:

for i in $@
do
echo $i
done

241
Q

What statement should be placed at the end of every Bash script?

A

exit 0

This statement will tell the parent shell that the command executed successfully.

242
Q

Which special variable in Bash is a counter that shows how many arguments were used when starting the script?

A

$#

243
Q

Suppose you want to write a simple Bash script that will take in one variable as ‘NAME’ and ‘echo’ it to the console. If no argument was given during the initial execution of the script, one should be requested inside the script. How can this be done?

A

!/bin/bash

if [ -z $1 ]; then
echo enter a name
read NAME
else
NAME=$1
fi

echo you have entered the text $NAME
exit 0

‘$1’ refers to the first argument given to the command. The line ‘if [ -z $1 ];’ checks whether $1 is empty; if so, it means that no argument was provided when starting this script. Notice that when you’re writing the test command with the square brackets, it is essential to include one space after the opening bracket and one space before the closing bracket; without these spaces, the command will not work.

244
Q

Suppose you are writing a Bash script and you want to test for the existence of the ‘myfile’ file. What two main options do you have for performing this test?

A

test -e myfile
[ -e myfile ]

Both of these syntaxes use the ‘test’ command.

245
Q

Suppose you are writing a Bash script and you want to execute the line ‘echo no argument provided’ only if the ‘$1’ variable has no value. How can you do this without using an if/else statement?

A

[ -z $1 ] && echo no argument provided

‘&&’ is the logical AND and will execute the second part of the statement only if the first part is true. ‘||’ is a logical OR and will execute the second part of the statement only if the first part is not true.

246
Q

How can you write a Bash script that will simply ‘echo’ the numbers 100 to 1 in descending order?

A

!/bin/bash

for (( COUNTER=100; COUNTER > 0; COUNTER– )); do
echo $COUNTER
done

exit 0

247
Q

Suppose you want to write a simple Bash script that will ‘ping’ each IP address in the range 192.168.122.120 - 192.168.122.125 and ‘echo’ a message when the ‘ping’ does not reach the host. Also make sure to suppress the standard output of the ‘ping’ command. How can you do this?

A

!/bin/bash

for i in {100..105}; do
ping -c 1 192.168.122.$i >/dev/null || echo ping was not successful
done

exit 0

In the above script, the ‘echo’ command is only being executed when the ‘ping’ is not successful.

248
Q

Suppose you want to write a simple Bash script that will take a process name as an argument and continuously check all running processes to see whether your provided process is still running. Redirect unnecessary command output to ‘/dev/null’. How can you do this?

A

!/bin/bash

while ps aux | grep $1 | grep -v grep >/dev/null
do
sleep 5
done

clear
echo your process has stopped
exit 0

The pipe to ‘grep -v grep’ is used to exclude lines containing the ‘grep’ command from the result.

249
Q

What are the differences between ‘while’ and ‘until’ loops in Bash?

A

A ‘while’ loop will continue to execute as long as the condition is true. An ‘until’ loop lasts until the condition is true (or while a condition is false).

250
Q

How can you write a script that takes in an argument and checks whether the argument given was ‘start’ ‘stop’ or ‘restart’? It should also have a default case as well.

A

!/bin/bash

case $1 in
start)
echo You chose to start.
;;
stop)
echo You chose to stop.
;;
restart)
echo You chose to restart.
;;
*)
echo Invalid input.
;;
esac

exit 0

251
Q

Suppose you have a server named ‘server1’ and you wish to only allow the users ‘lisa’ and ‘matthew’ to connect to it via SSH. How can you do this?

A
  1. Open the file ‘/etc/ssh/sshd_config’ in an editor
  2. Add the line ‘AllowUsers lisa matthew’ and save the changes

This will only allow the users ‘matthew’ and ‘lisa’ to connect to this server via SSH. Not even ‘root’ can remotely connect to this server with this setting (although ‘sudo -i’ and ‘su -‘ will both still work).

252
Q

How can you configure an SSH server to listen on port 2022 rather than the default port 22?

A
  1. Open the file ‘/etc/ssh/sshd_config’ in an editor
  2. Add the line ‘Port 2022’ and close the editor
  3. Execute ‘semanage port -a -t ssh_port_t -p tcp 2022’ to apply the correct SELinux label to port 2022
  4. Open the firewall for TCP port 2022 with the command ‘firewall-cmd –add-port=2022/tcp –permanent’
  5. Execute ‘firewall-cmd –reload’ to reload the new firewall configuration to runtime
  6. Restart ‘sshd’ via ‘systemctl restart sshd’
253
Q

How can you configure your SSH server to verify that the resolved hostname for the remote host maps back to the same IP address that they are using to connect to the server?

A

Ensure that the ‘UseDNS yes’ line is included in ‘/etc/ssh/sshd_config’

This will make the SSH server first perform a reverse DNS lookup on the IP address to find a hostname. The server will then perform a forward DNS lookup on that hostname to see if it matches the original IP address.

This option being set to ‘yes’ usually involves a significant performance penalty.

254
Q

How can you allow up to 25 sessions to be simultaneously connected to the SSH server from one IP address?

A

Ensure that the ‘MaxSessions’ line in ‘/etc/ssh/sshd_config’ is set to ‘MaxSessions 25’

255
Q

Suppose you want the SSH server to send packets to the client 60 seconds after no activity has been detected. It should do this 10 times before killing the connection. How can you accomplish this?

A
  1. On the server, open the ‘/etc/ssh/sshd_config’ file in an editor
  2. Find the ‘ClientAliveInterval’ option and set it to 60
  3. Find the ‘ClientAliveCountMax’ parameter and set it to 10
  4. Save the changes and exit the file. Restart the sshd service.

There are also client-side counterparts to these options, named ‘ServerAliveInternal’ and ‘ServerAliveCountMax’

256
Q

Which option in ‘/etc/ssh/ssh_config’ can be set to completely disable password-based authentication via SSH?

A

PasswordAuthentication no

257
Q

Suppose you use a passphrase when initiating an SSH session. What steps can you take to not have to enter the passphrase for each new connection?

A
  1. Type ‘ssh-agent /bin/bash’ to start the agent for the current (Bash) shell
  2. Type ‘ssh-add’ to add the passphrase for the current user’s private key (you’ll be prompted to enter the passphrase you set during key generation). The key is now cached.
  3. Connect to the remote server. Notice that there is no longer a need to enter the passphrase

If you log out or close the shell, the ssh-agent will terminate, and the passphrase will be required again the next time you try to use the private key.

258
Q

Which command will install all relevant packages for running an Apache web server?

A

dnf group install “Basic Web Server”

259
Q

Suppose you are working with a non-graphical RHEL installation. Which command will install a software that will allow you to work with web content from the command line?

A

dnf install curl

260
Q

What is the main configuration file for Apache?

A

/etc/httpd/conf/httpd.conf

261
Q

In the main configuration file for Apache, which parameter specifies the default location where the Apache web server will look for its contents?

A

DocumentRoot

A common default ‘DocumentRoot’ for Apache is ‘DocumentRoot “/var/www/html”’. Apache will by default look for a file named ‘index.html’.

262
Q

How can you start the Apache web service?

A

systemctl enable –now httpd

263
Q

In the main configuration file for Apache, which parameter defines the default directory where Apache will look for its configuration files?

A

ServerRoot

By default, the ‘/etc/httpd’ directory is used for this purpose.

264
Q

Which directory can be used for drop-in Apache configuration files?

A

/etc/httpd/conf.d

265
Q

Although not an RHCSA objective, what are the steps to configuring multiple Apache virtual hosts on one machine? Let’s assume the IP address for the Apache server is 192.168.4.210 and let’s use the names ‘account.example.com’ and ‘sales.example.com’ for the two websites.

A
  1. Add lines to the ‘/etc/hosts’ file that make it possible to resolve the names of the virtual host you are going to create to the IP address of the virtual machine. It should look like this:

192.168.4.210 account.example.com account
192.168.4.210 sales.example.com sales

  1. On the Apache server, open a root shell and add the following to the ‘/etc/httpd/conf/httpd.conf’ file:

<Directory /www/docs>
Require all granted
AllowOverride None
</Directory>

  1. On the Apache server, open a root shell and create a configuration file with the name ‘account.example.com.conf’ in the ‘/etc/httpd/conf.d’ directory. Give this file the following content:

<VirtualHost *:80>
ServerAdmin webmaster@account.example.com
DocumentRoot /www/docs/account.example.com
ServerName account.example.com
ErrorLog logs/account.example.com-error_log
CustomLog logs/account.example.com-access_log common
</VirtualHost>

  1. Close the configuration file, and from the root shell type ‘mkdir -p /www/docs/account.example.com’
  2. Create a file with the name ‘index.html’ in the account document root.
  3. Now back on the root shell, create the ‘/etc/httpd/conf.d/sales.example.com.conf’ and use the same format as the ‘account.example.com.conf’ file. Then create the ‘/www/docs/sales.example.com’ document root, and create a file
    ‘index.html’ in it.
  4. For the purpose of this exercise only, switch off SELinux using ‘setenforce 0’
  5. Restart the Apache web server with ‘systemctl restart httpd’
266
Q

Which command can be used to determine whether SELinux is currently in enforcing or permissive mode?

A

getenforce

The ‘sestatus -v’ command also works.

267
Q

How can you make RHEL 9 boot with SELinux in disabled mode?

A

Add ‘selinux=0’ to the ‘/etc/default/grub’ file (to the line that starts the Linux kernel) and then write those changes with ‘grub2-mkconfig -o /boot/grub2/grub.cfg’

268
Q

If you don’t want SELinux to be disabled, how can you configure SELinux to start in ‘enforcing’ or ‘permissive’ mode by default?

A

Add the line ‘SELINUX=enforcing’ or ‘SELINUX=permissive’ to the ‘/etc/sysconfig/selinux’ file.

In ‘permissive’ mode, SELinux will not deny any permissions but it will still log to the ‘/var/log/audit/audit.log’ file.

269
Q

How can you list SELinux context labels for all files/directories (including hidden ones) in the ‘/etc’ directory?

A

ls -aZ

The ‘-Z’ option shows context label settings. Many commands support the ‘-Z’ option, including ‘ss’ and ‘ps’

270
Q

The ‘semanage’ command does not always come with a RHEL installation. Which command can help you figure out which RPM provides it?

A

dnf whatprovides */semanage

271
Q

Of what three parts does every SELinux context label consist?

A

User:Role:Type

272
Q

Suppose you’ve configured an alternate ‘DocumentRoot’ named ‘/website’ for the Apache web server. Which commands will set the appropriate SELinux context type to the ‘/website’ directory and then apply the policy settings to the filesystem?

A

semanage fcontext -a -t httpd_sys_content_t “/website(/.*)?”
restorecon -R -v /website

For the ‘semanage fcontext’ command, the ‘-a’ option is used to add a context type while the ‘-t’ option specifies that we are changing the context type rather than the user or role. For ‘restorecon’ the ‘-R’ option is used to relabel files/directories recursively while the ‘-v’ option specifies that the command should output the changes that are made.

273
Q

The best way to find the appropriate SELinux context type for a service is via the man pages. Which command will install the RPM package that contains SELinux related man pages?

A

dnf install selinux-policy-doc

Make sure to execute ‘mandb’ to update the man pages with the new SELinux content.

274
Q

Suppose you need to set the appropriate SELinux context type for a new Apache document root but you don’t remember what context type is required for this scenario. How can you figure out which context type is required.

A

Execute ‘man -k _selinux | grep http’ to find the man pages that document SELinux settings for Apache.

You can also examine the default environment for clues. For example, you can use ‘ls -Z /var/www’ to look at the context type used for the default document root.

275
Q

What are the two methods for relabeling SELinux context labels for the entire filesystem?

A
  1. Execute ‘restorecon -Rv /’
  2. Create the ‘/.autorelabel’ file and then reboot the system.
276
Q

Suppose you have configured Apache by editing ‘/etc/httpd/conf/httpd.conf’ to listen on port 82 rather than the default port 80. How can you appropriately update the SELinux context label for port 82?

A

semanage port -a -t http_port_t -p tcp 82

The ‘-p’ option is used to specify the port when using the ‘semanage port’ command.

277
Q

Which command will list all SELinux booleans on a system?

A

getsebool -a

‘grep’ can be used here to filter for specific services such as ‘http’ or ‘ftp’

278
Q

Suppose you want anonymous writes to be configured for your FTP server. How can you configure this via SELinux booleans?

A

setsebool -P ftpd_anon_write on

The ‘-P’ option specifies that the changes should be permanent rather than only applied to the runtime. ‘ftpd_anon_write’ is the specific Boolean that enables/disables anonymous writes for the FTP server.

279
Q

What file stores SELinux logs?

A

/var/log/audit/audit.log

280
Q

Which command will retrieve only SELinux logs from ‘/var/log/audit/audit.log’ ?

A

grep AVC /var/log/audit/audit.log

SELinux messages are logged with ‘type=AVC’ in the audit log.

281
Q

The ‘sealert’ command is used to provide more simplified SELinux log messages. How can this command be installed?

A

dnf install setroubleshoot-server

Make sure to reboot the server after installing ‘sealert’ to ensure that all processes that are involved are restarted correctly.

Now, the next time an SELinux message is written to the audit log, an easier-to-understand message is written to the systemd journal.

282
Q

How can you read the ‘sealert’ messages that are written to the systemd journal?

A

journalctl | grep sealert

Running the command suggested by ‘sealert’ will query the SELinux event database and often give suggestions on how to fix the problem.

283
Q

Which directories store XML files that define Firewalld services?

A

/usr/lib/firewalld/services

The ‘/etc/ firewalld/services’ directory stores custom service XML files.

284
Q

Which command will show all Firewalld services available on the system?

A

firewall-cmd –get-services

When working with Firewalld, the right services need to be added to the right zones. Also, the firewall configuration can be enhanced with more specific settings if the zones are not robust enough.

285
Q

Which command will show the current default zone being used by the firewall?

A

firewall-cmd –get-default-zone

If an incoming packet does not belong to a specific zone, the packet is handled by the settings in the default zone.

‘firewall-cmd –get-zones’ will list all zones available to Firewalld.

286
Q

Which command will show which services are in the current zone?

A

firewall-cmd –list-services

287
Q

Which command will show an overview of the current firewall configuration?

A

firewall-cmd –list-all

288
Q

Like many things on RHEL, the Firewalld service has both a runtime firewall configuration and a permanent/on-disk configuration. Which command will reload the on-disk configuration into the runtime configuration?

A

firewall-cmd –reload

The ‘firewall-cmd –runtime-to-permanent’ command can be used to make the current runtime configuration the permanent configuration.

289
Q

Which command would add the ‘vnc-server’ service to the permanent firewall configuration?

A

firewall-cmd –add-service=vnc-server –permanent

290
Q

Suppose you want your server to allow traffic through TCP port 2020. Which command will add this rule to the permanent firewall configuration?

A

firewall-cmd –add-port=2020/tcp –permanent

291
Q

On an NFS server, which file defines NFS shares?

A

/etc/exports

292
Q

Suppose there is an NFS server named ‘datashare’ that you wish to use. Which command can be used to find out which NFS shares are available?

A

showmount -e datashare

The ‘showmount’ command may not work if the the ‘mountd’ and ‘rpc-bind’ services are not added to the NFS server firewall configuration.

293
Q

What command will install the packages necessary to enable an NFS server?

A

dnf install nfs-utils

Make sure to also enable the NFS service with ‘systemctl enable –now nfs-server’

294
Q

Suppose you are configuring an NFS server and you want to create an NFS share for the ‘/nfsdata’ directory. What line can you add to the ‘/etc/exports’ file to export this folder?

A

/nfsdata *(rw,no_root_squash)

In this line, the ‘*’ is used to specify that this export is available to all hosts. The ‘rw’ option gives read-write access to every remote host. Lastly, the ‘no_root_squash’ option allows root users to retain their root-level privileges on the NFS server.

Without the ‘no_root_squash’ option, if a remote user connects as the root user (uid 0), their access is mapped to the ‘nfsnobody’ user (usually with uid 65534) on the server.

295
Q

Which three services must be added to the permanent firewall configuration on an NFS server? Give the three separate commands.

A

firewall-cmd –add-service nfs –permanent
firewall-cmd –add-service rpc-bind –permanent
firewall-cmd –add-service mountd –permanent

Do not forget to reload the firewall with ‘firewall-cmd –reload’

296
Q

Suppose you are on ‘Desktop1’ and you wish to mount an NFS share from ‘server2’ on to your local ‘/mnt’ directory. How can you accomplish this via a root mount?

A

mount server2.example.com:/ /mnt

In a root mount, you just mount the root directory of the NFS server, and under your local mount point you’ll only see the shares to which you have access.

297
Q

How could you configure the ‘/nfsdata’ directory from the NFS server ‘server1’ to automatically be mounted on the local ‘/datashare’ directory?

A

Add the following line to the ‘/etc/fstab’ file:

server1:/nfsdata /datashare nfs sync 0 0

The third column contains the NFS file system type. The ‘sync’ option ensures that modified files are committed to the remote file system immediately and are not placed in write buffers first (which would increase the risk of data getting lost).

298
Q

In order to work with ‘autofs’ and Automount, which command will install the tools necessary to configure these services?

A

dnf install autofs

299
Q

How could you configure the ‘/nfsdata’ directory from ‘server2’ to automatically mount on the ‘/nfsdata/files’ directory on ‘server1’ via Automount?

A
  1. Ensure the ‘autofs’ RPM package is installed on ‘server1’
  2. Ensure the ‘/nfsdata’ directory is currently being exported on ‘server2’
  3. Type ‘vim /etc/auto.master’
  4. Add the line ‘/nfsdata /etc/auto.nfsdata’ and exit the editor
  5. Type ‘vim /etc/auto.nfsdata’
  6. Add the line ‘files -rw server2:/nfsdata’ and close the editor
  7. Run ‘systemctl enable –now autofs’
300
Q

Suppose you want to configure wildcard mounts on ‘server1’ so that when a user accesses their home directory, it is automatically mounted from the ‘/users’ directory on ‘server2’ onto the corresponding ‘/home’ directory. How can you do this?

A
  1. Add this line to ‘/etc/auto.master’:

/home /etc/auto.users

  1. Then, add this line to ‘/etc/auto.users’:
  • -rw server2:/users/&
  1. Restart the ‘autofs’ service with ‘systemctl restart autofs’
301
Q

Suppose you want to change the Apache configuration via the ‘httpd.service’ file. Which command will allow you to safely edit this configuration?

A

systemctl edit httpd.service

This will automatically create the ‘/etc/systemd/system/httpd.service.d/override.conf’ file.

302
Q

What file that holds installation settings/parameters can be automatically created during system installation? This can then be used to install RHEL on other systems with identical settings.

A

/root/anaconda-ks.cfg

This is a Kickstart file.

303
Q

How can you check whether the CPU is capable of virtualization?

A

grep -E “svm|vmx” /proc/cpuinfo

‘vmx’ is the virtualization extension used on Intel CPUs while ‘svm’ is the the extension used on AMD CPUs.

304
Q

How can you install the group of packages that allows your RHEL machine to be a virtualization host?

A

dnf group install “Virtualization Host”

305
Q

Which command can check if the prospective virtualization host meets all required conditions?

A

virt-host-validate

306
Q

Suppose you want to install a virtual machine on your host via the Cockpit web console. Which URL can you use to access the Cockpit console in a web browser?

A

https://localhost:9090

307
Q

How can you configure Cockpit so that you can use it in the web console/browser?

A
  1. Execute ‘dnf install cockpit-machines’
  2. Execute ‘systemctl enable –now cockpit.socket’
308
Q

Which command will install the package that enables you to install a virtual machine on your RHEL 9 host?

A

dnf install virt-install

309
Q

How can you install a virtual machine on your RHEL 9 host with the following configuration?

Name: testvm
RAM: 2048 Megabytes
CPU: 2 CPUs
Disk Size: 20 Gigabytes
OS: Linux
Installation Source: /rhel9.iso

A

virt-install –name testvm –memory 2048 –vcpus 2 –disk size 20 –os-type linux –cdrom /rhel9.iso

310
Q

Suppose you are creating a Kickstart file and you want the installer to prompt for the root password during installation. How can you make this happen?

A

Simply omit the line that sets the root password from the Kickstart file.