1What is the primary function of a network firewall?
Configuring Network Security: Configure the firewall
Easy
A.To store user passwords securely
B.To monitor CPU usage
C.To manage software packages
D.To filter network traffic based on a set of rules
Correct Answer: To filter network traffic based on a set of rules
Explanation:
A firewall acts as a security barrier, filtering incoming and outgoing network traffic according to predefined security rules to protect a network from unauthorized access.
Incorrect! Try again.
2Which of the following commands is commonly used to manage the firewalld service on a Linux system?
Configuring Network Security: Configure the firewall
Easy
A.firewall-cmd
B.ufw-tool
C.iptables-config
D.net-config
Correct Answer: firewall-cmd
Explanation:
firewall-cmd is the primary command-line tool used to interact with and configure the firewalld daemon, which manages the system's firewall rules.
Incorrect! Try again.
3What is the main purpose of a network analysis tool like tcpdump?
A.To capture and display network packets in real-time
B.To check the available disk space
C.To edit text files
D.To install new software applications
Correct Answer: To capture and display network packets in real-time
Explanation:
tcpdump is a command-line packet analyzer that allows a system administrator to capture and inspect the data packets being transmitted or received over a network.
Incorrect! Try again.
4Which command is commonly used to display active network connections, open ports, and routing tables on a Linux system?
The ss (socket statistics) command is a utility used to investigate network sockets and is the modern replacement for the older netstat command.
Incorrect! Try again.
5Which of the following is a fundamental step in hardening a Linux system?
Managing Linux Security: Harden a Linux system
Easy
A.Granting all users root privileges
B.Using 'password' as the root password
C.Never updating system software
D.Disabling unused services and ports
Correct Answer: Disabling unused services and ports
Explanation:
Hardening involves reducing the system's attack surface. Disabling services that are not needed means there are fewer potential entry points for an attacker to exploit.
Incorrect! Try again.
6Why is it critical to regularly apply software updates to a server?
Managing Linux Security: Harden a Linux system
Easy
A.To free up hard drive space
B.To make the system run slower
C.To patch known security vulnerabilities
D.To get the newest desktop wallpaper
Correct Answer: To patch known security vulnerabilities
Explanation:
Software updates frequently contain patches for security flaws that have been discovered. Applying them is a crucial proactive measure to protect the system from known exploits.
Incorrect! Try again.
7What is the primary purpose of an SSL/TLS certificate on a web server?
Managing Linux Security: Manage certificates
Easy
A.To manage user accounts
B.To store website content
C.To increase the server's processing speed
D.To encrypt the communication between a web server and a browser
Correct Answer: To encrypt the communication between a web server and a browser
Explanation:
An SSL/TLS certificate enables HTTPS, which encrypts data in transit, ensuring that information like login credentials and credit card numbers are transmitted securely.
Incorrect! Try again.
8What is the role of a Certificate Authority (CA)?
Managing Linux Security: Manage certificates
Easy
A.To issue and digitally sign trusted SSL/TLS certificates
B.To host websites for free
C.To develop web browsers
D.To provide internet connectivity
Correct Answer: To issue and digitally sign trusted SSL/TLS certificates
Explanation:
A Certificate Authority is a trusted entity that verifies the identity of organizations and domains, then issues digital certificates that browsers can trust to establish secure connections.
Incorrect! Try again.
9Authentication is the process of:
Managing Linux Security: Understand authentication
Easy
A.Granting permissions to a user
B.Encrypting a hard drive
C.Recording user activity in a log file
D.Verifying the identity of a user or process
Correct Answer: Verifying the identity of a user or process
Explanation:
Authentication is the security step where a system confirms that a user is who they claim to be, typically by checking credentials like a username and password.
Incorrect! Try again.
10In a modern Linux system, where are the hashed user passwords stored?
Managing Linux Security: Understand authentication
Easy
A./etc/group
B./etc/shadow
C./etc/hosts
D./etc/passwd
Correct Answer: /etc/shadow
Explanation:
For security reasons, the encrypted (hashed) passwords are not stored in the world-readable /etc/passwd file but in the /etc/shadow file, which can only be read by the root user.
Incorrect! Try again.
11What is the main goal of Mandatory Access Control (MAC) systems like SELinux?
Managing Linux Security: Configure SELinux or AppArmor
Easy
A.To confine programs to a limited set of actions and resources
B.To manage software package installations
C.To automatically set strong user passwords
D.To make the command line look better
Correct Answer: To confine programs to a limited set of actions and resources
Explanation:
SELinux and AppArmor enforce a strict security policy that limits what processes can do, thereby containing the potential damage if a service is compromised.
Incorrect! Try again.
12If SELinux is in permissive mode, what will it do when a policy violation occurs?
Managing Linux Security: Configure SELinux or AppArmor
Easy
A.Allow the action but log the violation
B.Completely ignore the action and not log anything
C.Block the action and log the violation
D.Shut down the system
Correct Answer: Allow the action but log the violation
Explanation:
In permissive mode, SELinux does not enforce the security policy (it doesn't block actions), but it still logs warnings. This is useful for testing policies before enforcing them.
Incorrect! Try again.
13What is the purpose of the #!/bin/bash line at the beginning of a script?
The hash or pound symbol (#) is used for single-line comments in bash scripting. The interpreter ignores any text on the line following this character.
Incorrect! Try again.
16Which of the following lines correctly declares a variable named my_var and assigns it the value 10 in bash?
Implementing Simple Scripts: Use shell script elements
Easy
A.my_var := 10
B.my_var=10
C.set my_var = 10
D.let my_var = 10
Correct Answer: my_var=10
Explanation:
In bash, variable assignment is done with the VARIABLE_NAME=value syntax. It is important that there are no spaces around the equals (=) sign.
Incorrect! Try again.
17How would you print the value of a variable named USERNAME to the terminal?
Implementing Simple Scripts: Use shell script elements
Easy
A.print USERNAME
B.echo $USERNAME
C.echo USERNAME
D.cat $USERNAME
Correct Answer: echo $USERNAME
Explanation:
The echo command is used to display text. To access the value stored in a variable, you must prefix its name with a dollar sign ($).
Incorrect! Try again.
18In a bash script, what does the special variable $1 represent?
Implementing Simple Scripts: Use shell script elements
Easy
A.The first argument passed to the script from the command line
B.The total number of arguments
C.The process ID of the script
D.The name of the script
Correct Answer: The first argument passed to the script from the command line
Explanation:
Positional parameters are special variables that hold the arguments passed to a script. 2 the second, and so on.
Incorrect! Try again.
19Which set of keywords is used to define a conditional if-then-else block in bash?
Implementing Simple Scripts: Implement scripts with logical controls
Easy
A.if, then, otherwise, close
B.if, then, else, endif
C.if, then, else, fi
D.if, do, otherwise, end
Correct Answer: if, then, else, fi
Explanation:
A bash conditional block starts with if, executes code after then, provides an alternative with else, and is terminated by fi (if spelled backwards).
Incorrect! Try again.
20What is the primary purpose of a for loop in a script?
Implementing Simple Scripts: Implement scripts with logical controls
Easy
A.To check if a condition is true or false one time
B.To end the script immediately
C.To define a new command
D.To iterate over a list of items and execute commands for each item
Correct Answer: To iterate over a list of items and execute commands for each item
Explanation:
A for loop is a control flow statement that allows a block of code to be repeatedly executed for each element in a sequence or list.
Incorrect! Try again.
21A system administrator needs to configure firewalld on a RHEL server to allow incoming HTTPS traffic, but only from the 10.10.20.0/24 subnet. Which command correctly and permanently implements this policy?
Configuring Network Security: Configure the firewall
Medium
To create a rule that combines a source address with a specific service in firewalld, a 'rich rule' is required. The --add-rich-rule flag allows for complex rule creation. The --permanent flag ensures the rule persists after a reboot. The other options are either syntactically incorrect for firewalld or use a different tool (iptables).
Incorrect! Try again.
22Using iptables, you need to block all outgoing TCP traffic from your server to the IP address 203.0.113.50 on port 8080. Which command will accomplish this?
Configuring Network Security: Configure the firewall
Medium
A.iptables -A FORWARD -p tcp -d 203.0.113.50 --dport 8080 -j DROP
B.iptables -A INPUT -p tcp -d 203.0.113.50 --dport 8080 -j DROP
C.iptables -A OUTPUT -p tcp -d 203.0.113.50 --dport 8080 -j DROP
Correct Answer: iptables -A OUTPUT -p tcp -d 203.0.113.50 --dport 8080 -j DROP
Explanation:
The OUTPUT chain is used for packets originating from the local server. -d 203.0.113.50 specifies the destination IP, --dport 8080 specifies the destination port, and -j DROP silently discards the matching packets. The INPUT chain is for incoming traffic, and FORWARD is for traffic being routed through the server.
Incorrect! Try again.
23You want to capture all DNS query traffic (both TCP and UDP) leaving your server's eth0 interface and save it to a file named dns_traffic.pcap for later analysis with Wireshark. Which tcpdump command is most appropriate?
Configuring Network Security: Monitor network traffic
Medium
A.tcpdump -i eth0 -o dns_traffic.pcap 'udp port 53'
The -i eth0 flag specifies the interface. The -w dns_traffic.pcap flag writes the raw packet data to a file in pcap format. The filter expression 'port 53' correctly captures traffic where either the source or destination port is 53, which is used for DNS over both UDP and TCP.
Incorrect! Try again.
24While investigating active network connections using the ss command, you see the following line of output: tcp LISTEN 0 128 *:ssh *:* users:(("sshd",pid=1234,fd=3))
What does this line indicate?
Configuring Network Security: Monitor network traffic
Medium
A.The SSH daemon (sshd) has established an outbound connection from this server.
B.There are 128 active SSH connections to the server.
C.A user is actively connected via SSH from any IP address.
D.The SSH service, with process ID 1234, is listening for incoming connections on all network interfaces.
Correct Answer: The SSH service, with process ID 1234, is listening for incoming connections on all network interfaces.
Explanation:
LISTEN state means the socket is waiting for an incoming connection. *:ssh indicates it is listening on the standard SSH port (22) on all available network interfaces (*). The users:(("sshd",pid=1234,...)) part explicitly identifies the process name and its PID that owns this listening socket.
Incorrect! Try again.
25What is the primary security benefit of setting PermitRootLogin no in the /etc/ssh/sshd_config file?
Managing Linux Security: Harden a Linux system
Medium
A.It encrypts the root user's password in the /etc/shadow file.
B.It forces attackers to guess both a valid username and a password, increasing brute-force difficulty.
C.It completely disables the root account on the system.
D.It prevents all users from using the sudo command.
Correct Answer: It forces attackers to guess both a valid username and a password, increasing brute-force difficulty.
Explanation:
By disabling direct root login via SSH, an attacker can no longer target the universally known 'root' username. They must first discover a valid non-privileged username and then guess its password. This increases the complexity of a brute-force attack. It also promotes better administrative practice by forcing admins to log in as a regular user and elevate privileges using sudo or su, which provides a clearer audit trail.
Incorrect! Try again.
26A system administrator wants to find all files on the system that have either the SUID or SGID permission bit set, as these can sometimes represent a security risk. Which find command is the correct way to search for these files?
Managing Linux Security: Harden a Linux system
Medium
The find command's -perm argument can be used with a leading slash (in some versions) or hyphen to match 'any' of the bits. -perm -4000 finds files with the SUID bit set, and -perm -2000 finds files with the SGID bit set. The -o operator acts as a logical OR. The command searches for any file (-type f) where either the SUID bit OR the SGID bit is set.
Incorrect! Try again.
27You are hardening a public-facing web server. Which of the following actions is a crucial step to limit the system's attack surface?
Managing Linux Security: Harden a Linux system
Medium
A.Uninstalling all unnecessary services and packages (e.g., compilers, X11, printing services).
B.Configuring daily backups to a remote location.
C.Increasing the size of the swap partition.
D.Setting a complex root password.
Correct Answer: Uninstalling all unnecessary services and packages (e.g., compilers, X11, printing services).
Explanation:
Limiting the attack surface means reducing the number of potential entry points for an attacker. Every installed package and running service is a potential source of vulnerabilities. By removing software that is not absolutely essential for the server's function (like compilers, graphical interfaces, or other services), you reduce the number of potential vulnerabilities that could be exploited.
Incorrect! Try again.
28You need to generate a new 2048-bit RSA private key and an associated Certificate Signing Request (CSR) for www.example.com. Which openssl command accomplishes both tasks in a single step?
Managing Linux Security: Manage certificates
Medium
The openssl req command is used for managing CSRs. The -new flag indicates a new request. The -newkey rsa:2048 option instructs OpenSSL to generate a new 2048-bit RSA private key on the fly. -nodes means 'no DES', so the private key will not be encrypted with a passphrase. -keyout and -out specify the output files for the key and CSR, respectively.
Incorrect! Try again.
29A Certificate Authority (CA) has issued you a signed server certificate (server.crt) and an intermediate certificate (intermediate.crt). To avoid browser trust warnings, how should you configure these in a web server like Nginx or Apache?
Managing Linux Security: Manage certificates
Medium
A.Configure the server to only use server.crt, as the intermediate is handled by the client.
B.Concatenate the intermediate certificate and the server certificate into a single file, and point the web server's certificate directive to this combined file.
C.Place both files in the same directory and the web server will automatically find and serve the intermediate.
D.Configure the server with server.crt and use a separate directive to specify the path to intermediate.crt.
Correct Answer: Configure the server with server.crt and use a separate directive to specify the path to intermediate.crt.
Explanation:
While concatenating files works for many servers (and was the older method), modern web servers like Apache (SSLCertificateChainFile or inside the main cert file) and Nginx (ssl_certificate) are designed to handle certificate chains correctly. The standard practice is to configure the server certificate and the intermediate/chain certificate(s) so the server can present the full chain of trust to the client. The most common modern approach is to have one file for the server certificate and another for the rest of the chain (intermediate + root), or to concatenate them in order: server cert first, then intermediate(s).
Incorrect! Try again.
30In a PAM (Pluggable Authentication Modules) configuration file, what is the behavior of the required control flag?
Managing Linux Security: Understand authentication
Medium
A.If the module succeeds, authentication is immediately successful and no other modules are checked.
B.The module's success is optional; failure does not cause the overall authentication to fail.
C.The module must succeed for the overall authentication to succeed, but all other modules in the stack are still executed regardless of the result.
D.If the module fails, authentication immediately fails and an error is returned to the application without processing other modules.
Correct Answer: The module must succeed for the overall authentication to succeed, but all other modules in the stack are still executed regardless of the result.
Explanation:
The required flag indicates that the module's success is necessary for the final outcome. However, even if a required module fails, PAM continues to process the rest of the modules in the stack. This prevents an attacker from discovering which specific module failed, as the final failure is only reported after all modules have run. This contrasts with requisite, which fails immediately.
Incorrect! Try again.
31A user has correctly placed their SSH public key in ~/.ssh/authorized_keys on a server. However, they are still being prompted for a password when they try to connect. The SSH server logs show no specific errors. What is the most likely cause of this issue?
Managing Linux Security: Understand authentication
Medium
A.The server's clock is out of sync with the client's clock.
B.The user's home directory (~) or their ~/.ssh directory has incorrect, overly permissive file permissions.
C.The server's /etc/ssh/sshd_config has PasswordAuthentication no set.
D.The client-side SSH agent is not running.
Correct Answer: The user's home directory (~) or their ~/.ssh directory has incorrect, overly permissive file permissions.
Explanation:
For security reasons, the SSH daemon (sshd) is very strict about permissions. It will ignore the authorized_keys file if the user's home directory, the .ssh directory, or the authorized_keys file itself is writable by other users. The typical required permissions are 700 or 755 for the home directory, 700 for ~/.ssh, and 600 for ~/.ssh/authorized_keys.
Incorrect! Try again.
32An Apache web server (httpd) running on a system with SELinux in enforcing mode cannot access content located in /srv/www. Audit logs show AVC denial errors related to httpd_t trying to access files labeled default_t. What are the correct commands to permanently relabel the directory and its contents for web server access?
Managing Linux Security: Configure SELinux or AppArmor
Medium
A.chcon -R -t httpd_sys_content_t /srv/www
B.semanage fcontext -a -t httpd_sys_content_t "/srv/www(/.*)?" && restorecon -Rv /srv/www
C.audit2allow -a -M httpd_custom && semodule -i httpd_custom.pp
The correct and permanent way to fix this is to update the SELinux file context policy. semanage fcontext adds a new rule defining that /srv/www and all files/directories under it ((/.*)?) should have the httpd_sys_content_t type. Then, restorecon -Rv applies this new policy rule to the existing filesystem, changing the labels on the files and directories.
Incorrect! Try again.
33A newly installed application is being blocked by AppArmor. You want to temporarily allow the application to run while logging all policy violations so you can build a correct profile. Which command should you use to place the application's profile into complain/learning mode?
Managing Linux Security: Configure SELinux or AppArmor
Medium
The aa-complain command is used to switch an AppArmor profile from the default 'enforce' mode to 'complain' mode. In complain mode, policy violations are logged in the system audit logs, but the actions are not blocked. This is a crucial step for generating or debugging a security profile without disrupting service.
Incorrect! Try again.
34After reviewing /var/log/audit/audit.log, you find SELinux AVC denial messages. You want to understand these denials in a human-readable format and see a suggestion for a local policy module to allow the action. Which command pipeline is best suited for this initial analysis?
Managing Linux Security: Configure SELinux or AppArmor
Medium
grep AVC filters the audit log to show only the SELinux denial messages. Piping this output to audit2allow (without the -M flag) will analyze the denials and print a human-readable explanation along with a sample allow rule that could be added to a custom policy module. This is the standard first step in troubleshooting SELinux denials.
Incorrect! Try again.
35What is the primary function of the #!/bin/bash line (shebang) at the very beginning of a shell script?
Implementing Simple Scripts: Understand bash scripting basics
Medium
A.It is a comment that tells the user which shell the script was written for.
B.It is an instruction to the kernel's program loader, specifying the interpreter that should be used to execute the script's contents.
C.It loads the user's .bashrc profile before executing the rest of the script.
D.It sets the BASH_VERSION environment variable for the script's execution environment.
Correct Answer: It is an instruction to the kernel's program loader, specifying the interpreter that should be used to execute the script's contents.
Explanation:
When you try to execute a file directly (e.g., ./myscript.sh), the kernel examines the first few bytes. If it sees the #! characters (the shebang), it treats the rest of the line as the absolute path to an interpreter program. The kernel then invokes that interpreter (/bin/bash in this case) and passes the script file as an argument to it. It is not just a comment; it is a critical directive for direct execution.
Incorrect! Try again.
36Which of the following lines in a bash script will correctly count the number of files (excluding directories) in the current directory and store the result in a variable named file_count?
Implementing Simple Scripts: Understand bash scripting basics
Medium
A.file_count='ls -l | grep "^-" | wc -l'
B.set file_count = $(ls | wc -l)
C.let file_count = ls -f
D.file_count=$(find . -maxdepth 1 -type f | wc -l)
This is the most robust method. find . -maxdepth 1 -type f reliably lists only files (-type f) in the current directory (.) without recursing (-maxdepth 1). The output is then piped to wc -l to count the lines. The entire command is enclosed in $() (command substitution) to capture its output and assign it to the file_count variable. The ls based options are prone to errors with filenames containing spaces or special characters.
Incorrect! Try again.
37What will be the output of the following shell script when executed as ./script.sh alpha beta gamma?
bash
#!/bin/bash
echo "Total arguments: $#"
echo "The third argument is: $3"
shift 2
echo "The first argument now is: $1"
Implementing Simple Scripts: Use shell script elements
Medium
A.Total arguments: 3
The third argument is: gamma
The first argument now is: gamma
B.Total arguments: 3
The third argument is: $3
The first argument now is: $1
C.Total arguments: 3
The third argument is: gamma
The first argument now is: alpha
D.Total arguments: 4
The third argument is: gamma
The first argument now is: beta
Correct Answer: Total arguments: 3
The third argument is: gamma
The first argument now is: gamma
Explanation:
Initially, 3 is gamma. The shift 2 command discards the first two positional parameters (alpha and beta). After the shift, the list of positional parameters becomes just gamma. Therefore, the new # would now be 1.
Incorrect! Try again.
38You are writing a script that needs to prompt the user for a password and store it in a variable named PASSWD without echoing the typed characters to the terminal. Which command achieves this?
Implementing Simple Scripts: Use shell script elements
Medium
The read command is used for user input. The -p option displays a prompt string without a trailing newline. The -s option stands for 'silent' mode, which prevents the user's input from being displayed on the screen. The final argument, PASSWD, is the name of the variable where the input will be stored.
Incorrect! Try again.
39Consider the following script, which is intended to check the status of a service and restart it if it is not running. What logical control is missing for the script to function correctly?
bash
#!/bin/bash
SERVICE_NAME="httpd"
# Missing logic here
if [ $STATUS -ne 0 ]; then
echo "Service $SERVICE_NAME is not running. Restarting..."
systemctl restart $SERVICE_NAME
fi
Implementing Simple Scripts: Implement scripts with logical controls
Medium
A.A for loop to iterate through all services.
B.A case statement to handle different service names.
C.A command to capture the exit status of the service check into the STATUS variable, such as systemctl is-active --quiet ?
D.An echo $STATUS command to display the status to the user.
Correct Answer: A command to capture the exit status of the service check into the STATUS variable, such as systemctl is-active --quiet ?
Explanation:
The script checks the value of the STATUS variable but never assigns a value to it. To make the logic work, you must first execute a command that checks the service and then capture its exit code. systemctl is-active --quiet ? then captures this exit code into the STATUS variable for the if statement to evaluate.
Incorrect! Try again.
40You need to write a script that processes every file with a .log extension in the /var/log/app directory. Which for loop syntax is the most appropriate and common way to achieve this in bash?
Implementing Simple Scripts: Implement scripts with logical controls
Medium
A.for i in $(ls /var/log/app/*.log); do
# commands
done
B.for (i in /var/log/app/*.log); do
# commands
done
C.for i in /var/log/app/*.log; do
# commands
done
D.ls /var/log/app/*.log | while read i; do
# commands
done
Correct Answer: for i in /var/log/app/*.log; do
# commands
done
Explanation:
Using globbing (*.log) directly in the for loop is the standard, safest, and most efficient way to iterate over filenames in bash. The shell expands /var/log/app/*.log into a list of matching file paths, and the for loop assigns each path to the variable i in turn. Using ls inside command substitution ($(ls ...)), is problematic as it will fail if filenames contain spaces or special characters.
Incorrect! Try again.
41A system administrator needs to configure iptables on a Linux router (forwarding enabled) to allow established web traffic from an internal network (192.168.1.0/24) to the internet, while also redirecting incoming traffic on port 80 of the router's external interface (eth0) to an internal web server at 192.168.1.50. Which combination of rules most accurately and securely accomplishes this?
Which of the following represents the minimal and correct set of rules required?
Configuring Network Security: Configure the firewall
Hard
A.Only rules 1, 3, and 4 are required; rule 2 is insecure as it doesn't check connection state.
B.Only rules 1 and 4 are required; forwarding rules are not needed with NAT.
C.Rules 1, 2, 3, and 4 are all required.
D.Only rules 1, 2, and 4 are required; rule 3 is redundant if the default FORWARD policy is ACCEPT.
Correct Answer: Rules 1, 2, 3, and 4 are all required.
Explanation:
This is a complex firewalling scenario. Rule 1 (DNAT) is needed for port forwarding. Rule 4 (MASQUERADE/SNAT) is needed for internal clients to access the internet. Critically, traffic for both scenarios must be allowed through the FORWARD chain. Rule 2 allows the new forwarded traffic from the internet to the web server. Rule 3 allows the return traffic from the internal network's internet browsing. Without all four rules (assuming a default DROP policy on the FORWARD chain, which is best practice), the configuration will fail in one of the two requirements. Rule 2 is not insecure because it's highly specific to the destination IP and port; combining it with state matching (-m state --state NEW) would be even better, but it's necessary to allow the initial packet of the DNAT'd connection.
Incorrect! Try again.
42An administrator sees the following AVC denial in /var/log/audit/audit.log:
They want to create a local SELinux policy module to allow this specific action permanently and in a targeted way. What is the most appropriate sequence of commands to achieve this?
Managing Linux Security: Configure SELinux or AppArmor
Hard
The correct procedure for creating a custom policy module from an audit log denial is to pipe the relevant log entry into audit2allow. The -M flag creates a Type Enforcement (.te) file and compiles it into a policy package (.pp). The semodule -i command then installs this package. setsebool is for toggling existing booleans, not fixing this specific context issue. chcon would set the context, but the denial shows var_t, implying the directory is not in a standard web content location, and the change would not survive a filesystem relabel. restorecon is used to restore default contexts, which wouldn't help if the application genuinely needs to write to a location with a non-standard context.
This question tests the precedence and short-circuiting behavior of && (AND) and || (OR) operators in bash. && has higher precedence than ||. The expression is evaluated as (check_service && restart_service) || notify_admin.
check_service is executed and returns an exit code of 1 (failure).
Because the left side of the && failed, the right side (restart_service) is not executed (short-circuiting).
The result of the (check_service && restart_service) group is failure (exit code 1).
Because the left side of the || failed, the right side (notify_admin) is executed.
notify_admin runs and echoes its message. The final output is from check_service and notify_admin.
Incorrect! Try again.
44A security analyst needs to use tcpdump to capture packets on interface eth0 that match a very specific and complex profile for identifying a potential slow-scan attack. The criteria are: packets must be TCP, must have only the SYN flag set (no other flags like ACK), must originate from the 10.0.0.0/8 network, and must be destined for port 443. Which tcpdump filter expression is the most precise and correct way to capture only these specific packets?
Configuring Network Security: Monitor network traffic
Hard
A.tcpdump -i eth0 'tcp and src net 10.0.0.0/8 and dst port 443 and tcp-syn'
B.tcpdump -i eth0 'ip proto \tcp and src net 10.0.0.0/8 and port 443'
C.tcpdump -i eth0 'tcp[tcpflags] & (tcp-syn) != 0 and src net 10.0.0.0/8 and dst port 443'
D.tcpdump -i eth0 'src net 10.0.0.0/8 and dst port 443 and tcp[13] == 2'
Correct Answer: tcpdump -i eth0 'src net 10.0.0.0/8 and dst port 443 and tcp[13] == 2'
Explanation:
This question requires deep knowledge of tcpdump filter syntax, specifically for TCP flags. The TCP flags are in the 13th byte of the TCP header (offset 0). A value of 2 (binary 00000010) means that only the SYN flag is set. The other options are flawed:
The tcp[tcpflags] & (tcp-syn) != 0 expression is true if the SYN flag is set, but it doesn't exclude packets that also have other flags set (like SYN/ACK).
The tcp-syn keyword is not a valid primitive in tcpdump filter expressions.
The last option is too broad; ip proto \tcp is redundant with tcp, and it doesn't filter for the SYN flag at all.
Incorrect! Try again.
45A system is configured with the following /etc/pam.d/sshd stack for authentication:
A user, testuser, exists in SSSD (LDAP) but provides the wrong password during an SSH attempt. What is the immediate outcome of this authentication attempt from PAM's perspective?
Managing Linux Security: Understand authentication
Hard
A.The pam_sss.so module returns an 'ignore' status, and control passes to pam_deny.so which causes the failure.
B.The pam_sss.so module fails, and then pam_deny.so is processed, which also fails, and sshd denies access.
C.The authentication immediately fails and control is returned to the application (sshd) without processing pam_deny.so.
D.The authentication is marked as failed by pam_sss.so, but PAM continues to pam_deny.so, after which failure is reported.
Correct Answer: The authentication immediately fails and control is returned to the application (sshd) without processing pam_deny.so.
Explanation:
This question tests the understanding of PAM control flags, specifically requisite. The requisite flag means that if the module (in this case pam_sss.so) fails, the entire authentication process for this stack type (auth) fails immediately. Control is returned to the calling application (sshd) without processing any subsequent modules in the stack. In contrast, required would allow subsequent modules to be processed before ultimately returning failure. Therefore, pam_deny.so will not even be evaluated.
Incorrect! Try again.
46An administrator is debugging a TLS connection to https://secure.example.com using openssl s_client -connect secure.example.com:443. The command output includes the following line at the end of the certificate chain verification section:
verify return code: 21 (unable to verify the first certificate)
Assuming the server's own certificate and the root CA certificate are correct and trusted, what is the most likely cause of this specific error?
Managing Linux Security: Manage certificates
Hard
A.The client's system clock is skewed, causing the certificate to appear not yet valid or expired.
B.The server is not presenting the necessary intermediate CA certificate in the TLS handshake.
C.The server's private key does not match its public certificate.
D.The server certificate's Common Name (CN) does not match secure.example.com.
Correct Answer: The server is not presenting the necessary intermediate CA certificate in the TLS handshake.
Explanation:
The verify return code: 21 is a very specific OpenSSL error. It means that the client could not find an issuer certificate for the first certificate it was presented with (the server's leaf certificate). In a typical chain (Root -> Intermediate -> Server), this happens when the server is configured to send only its own certificate but not the intermediate certificate. The client cannot bridge the gap in the chain of trust from the server certificate to a trusted root CA in its trust store. A clock skew would be code 9 or 10, a hostname mismatch would be a different error (e.g., code 62), and a key mismatch would likely prevent the server from starting or completing the handshake at all.
Incorrect! Try again.
47Consider the following two Bash script snippets intending to process a file line by line:
Snippet A:
bash
count=0
cat file.txt | while read line; do
((count++))
done
echo "A: $count"
Snippet B:
bash
count=0
while read line; do
((count++))
done < file.txt
echo "B: $count"
If file.txt contains 10 lines, what will be the output?
Implementing Simple Scripts: Use shell script elements
Hard
A.A: 10
B: 10
B.A: 0
B: 10
C.A: 10
B: 0
D.A: 0
B: 0
Correct Answer: A: 0
B: 10
Explanation:
This question highlights a critical concept of subshells and variable scope in bash. In Snippet A, the while loop is on the right side of a pipe (|). This causes the loop to be executed in a subshell. Any variable modifications made inside that subshell (like incrementing count) are lost when the subshell exits. Therefore, the echo in the parent shell still sees count as 0. In Snippet B, input redirection (< file.txt) is used. This does not create a subshell for the while loop. The loop runs in the current shell's context, so the modifications to the count variable persist, and the final echo correctly prints 10.
Incorrect! Try again.
48To mitigate TCP SYN flood attacks, a sysadmin modifies /etc/sysctl.conf. Which set of parameters provides the most robust defense by enabling a non-state-based cookie mechanism and optimizing the handling of incoming SYN packets?
Managing Linux Security: Harden a Linux system
Hard
A.All three parameters (tcp_max_syn_backlog, tcp_synack_retries, tcp_syncookies) are essential and work together.
B.Only net.ipv4.tcp_max_syn_backlog is necessary to increase the queue size for legitimate connections.
C.Only net.ipv4.tcp_syncookies = 1 is necessary; the others are for performance tuning, not security.
D.Setting net.ipv4.tcp_synack_retries = 0 would be more effective as it stops retransmissions.
Correct Answer: All three parameters (tcp_max_syn_backlog, tcp_synack_retries, tcp_syncookies) are essential and work together.
Explanation:
A robust defense against SYN floods involves a multi-faceted approach. net.ipv4.tcp_syncookies = 1 is the core of the defense, as it allows the server to handle SYN requests without filling up the SYN backlog (by encoding connection info into the SYN-ACK sequence number). However, it's only activated when the backlog is full. Therefore, net.ipv4.tcp_max_syn_backlog must be increased from its default to handle larger bursts of legitimate traffic before syncookies are needed. net.ipv4.tcp_synack_retries reduces the number of times the server tries to re-send a SYN-ACK, which frees up resources faster when dealing with spoofed source IPs that will never respond. All three work in concert for an effective mitigation strategy.
Incorrect! Try again.
49A sysadmin wants to use firewalld to allow inbound SSH traffic from the 192.168.100.0/24 subnet but log and drop SSH traffic from all other sources, with log messages prefixed with "SSH-REJECT". Which single firewalld rich rule, when added to the public zone, accomplishes this entire objective most efficiently?
Configuring Network Security: Configure the firewall
Hard
A.rule family="ipv4" source address="!192.168.100.0/24" service name="ssh" log prefix="SSH-REJECT" level="info" reject
B.rule family="ipv4" source address="192.168.100.0/24" service name="ssh" accept; rule family="ipv4" service name="ssh" log prefix="SSH-REJECT" level="info"; rule family="ipv4" service name="ssh" reject
C.rule family="ipv4" source address="192.168.100.0/24" service name="ssh" accept
D.rule family="ipv4" not source address="192.168.100.0/24" service name="ssh" drop
This question requires understanding the syntax and logic of firewalld rich rules. The goal is to perform multiple actions based on a single condition. The correct option uses an inverted source address match (!192.168.100.0/24) to target all other traffic. Crucially, it combines the log and reject actions into a single rule. This is the most efficient method. The first option uses three separate rules, which is less efficient and harder to manage. The third option only implements the accept part of the requirement. The fourth option drops the packets silently without logging, failing to meet the logging requirement.
Incorrect! Try again.
50A script process.sh is written as follows:
bash
#!/bin/bash
for arg in "$@"
do
echo "Processing: $arg"
done
It is executed with the command: ./process.sh "first arg" "second" "third arg with spaces"
What is the exact output?
Implementing Simple Scripts: Understand bash scripting basics
Hard
A.Processing: first arg second third arg with spaces
B.Processing: first
Processing: arg
Processing: second
Processing: third
Processing: arg
Processing: with
Processing: spaces
C.Processing: "first arg"
Processing: "second"
Processing: "third arg with spaces"
D.Processing: first arg
Processing: second
Processing: third arg with spaces
Correct Answer: Processing: first arg
Processing: second
Processing: third arg with spaces
Explanation:
This question tests the critical difference between @, and more specifically, the behavior of "@" expands to a separate, properly quoted string for each positional parameter. This means that arguments containing spaces ("first arg" and "third arg with spaces") are treated as single arguments by the for loop. If the script had used *", all arguments would have been expanded into a single string ("first arg second third arg with spaces"), and the loop would have executed only once.
Incorrect! Try again.
51An administrator is creating an AppArmor profile for a custom application located at /usr/local/bin/myapp. The application needs to read its configuration from /etc/myapp/config.conf and write logs to /var/log/myapp.log. According to the principle of least privilege, which of the following profile snippets is both correct and most secure?
Managing Linux Security: Configure SELinux or AppArmor
Hard
owner /etc/myapp/config.conf r,
owner /var/log/myapp.log a,
}
Explanation:
The most secure and correct profile follows several AppArmor best practices. It starts with the profile keyword. It includes <abstractions/base> for common system file access. Most importantly, it uses the owner keyword to ensure the application can only access these files if it has the necessary DAC (user/group) permissions. For the log file, it uses a (append) mode instead of w (write), which is more secure for logging as it prevents truncation or overwriting of the entire file. The other options are less secure: Option A lacks the base abstraction and uses w instead of a. Option B uses overly broad wildcards (** and *) and grants an unnecessary and powerful capability (dac_override). Option D only allows execution (ux) and is incomplete.
Incorrect! Try again.
52What is the primary security advantage that OCSP Stapling (TLS Certificate Status Request extension) offers over a client performing its own OCSP validation, and what is a critical operational dependency for it to work?
Managing Linux Security: Manage certificates
Hard
A.Advantage: It works even if the CA's OCSP responder is offline. Dependency: The client must explicitly trust the web server's stapled response.
B.Advantage: It uses a stronger cryptographic algorithm than standard OCSP. Dependency: The client's browser must support the OCSP Stapling extension.
C.Advantage: It prevents the Certificate Authority (CA) from seeing which clients are visiting which sites. Dependency: The web server must be able to periodically connect to the CA's OCSP responder.
D.Advantage: It reduces latency for the client. Dependency: The web server must have a direct connection to the client.
Correct Answer: Advantage: It prevents the Certificate Authority (CA) from seeing which clients are visiting which sites. Dependency: The web server must be able to periodically connect to the CA's OCSP responder.
Explanation:
This is a nuanced question about modern certificate validation techniques. The primary security advantage of OCSP stapling is privacy. In a standard OCSP check, the client contacts the CA directly, revealing the client's IP and the site they are visiting to the CA. With OCSP stapling, the web server makes this request periodically and 'staples' the signed, timestamped response to the TLS handshake. This means the CA only sees requests from the web server, not from every individual client. The critical dependency for this system is that the web server itself must have network connectivity to the CA's OCSP responder to fetch and cache these responses.
Incorrect! Try again.
53You are debugging a bash script and find this line:
[[ -f "(stat -c %s "file"
The script author claims this is a safe way to process files larger than 1KB. Under which edge-case condition would this line of code produce an error and potentially terminate the script (if set -e is active)?
Implementing Simple Scripts: Implement scripts with logical controls
Hard
A.When the variable $file is an empty string.
B.When the file $file does not exist.
C.When the file $file is exactly 1024 bytes.
D.When the file $file contains a space in its name.
Correct Answer: When the variable $file is an empty string.
Explanation:
This question tests understanding of shell command execution and short-circuiting in edge cases. The use of && ensures that the stat command is only run if the file exists (-f "file is an empty string, the first test [[ -f "" ]] evaluates to false. The stat command is not executed due to short-circuiting. But the problem lies in what happens if the logic were different or if a command wasn't inside [[ ]]. The real killer is that stat -c %s "" would be executed if the first check was different (e.g. [[ -n "file is empty. The stat command stat -c %s "" will error out with 'stat: cannot stat '': No such file or directory', causing a non-zero exit code.
Incorrect! Try again.
54What is the key difference in behavior and variable scope when using process substitution (<(command)) versus a traditional pipe (|) to feed a while read loop in Bash?
bash
# Method 1: Pipe
command | while read var; do ...; done
# Method 2: Process Substitution
while read var; do ...; done < <(command)
Implementing Simple Scripts: Use shell script elements
Hard
A.The pipe method is faster, but the process substitution method allows variables set inside the loop to be accessible after the loop finishes.
B.The pipe method executes the while loop in a subshell, isolating its variables, while the process substitution method executes the loop in the current shell, preserving variable scope.
C.There is no functional difference; both execute the loop in a subshell.
D.The process substitution method executes the command in a subshell, while the pipe method executes both the command and the while loop in separate subshells.
Correct Answer: The pipe method executes the while loop in a subshell, isolating its variables, while the process substitution method executes the loop in the current shell, preserving variable scope.
Explanation:
This is a classic advanced scripting problem. When you use a pipe (command | while ...), Bash creates a subshell for the command on the right side of the pipe. Any variables created or modified inside that while loop exist only within that subshell and are lost when the loop terminates. In contrast, when using process substitution (while ... < <(command)), the command runs in a subshell, but its output is connected to the while loop via a named pipe or a file descriptor. The while loop itself runs in the current shell context. This means any variables modified inside the loop will retain their values after the loop has finished, which is a common requirement in complex scripts.
Incorrect! Try again.
55A company uses SSSD to integrate their Linux servers with an Active Directory domain. A user reports they can log in via SSH using their password, but SSH key-based authentication fails. The user's public key is correctly placed in the altSecurityIdentities attribute in Active Directory. Which configuration directive in /etc/sssd/sssd.conf is most likely missing or misconfigured, preventing SSSD from retrieving the user's public key?
Managing Linux Security: Understand authentication
Hard
This is a highly specific configuration issue that requires knowledge of SSSD's integration with AD for SSH. While id_provider = ad, auth_provider = ad, and ldap_schema = ad are necessary for basic integration and password authentication, they do not tell SSSD where to look for SSH public keys. To enable SSH public key retrieval from Active Directory, you must explicitly tell SSSD which AD attribute stores the keys. The ldap_user_ssh_public_key option is used for this purpose. Since the keys are in altSecurityIdentities, this line must be present and correct in the [domain/...] section of sssd.conf for key-based authentication to function through SSSD.
Incorrect! Try again.
56An administrator is setting up a stateful iptables firewall on a server that must act as a passive-mode FTP server. They have a rule iptables -A INPUT -p tcp --dport 21 -m state --state NEW,ESTABLISHED -j ACCEPT. However, clients can connect and authenticate but cannot get directory listings or transfer files. Which of the following is the most likely missing component for a secure and functional configuration?
Configuring Network Security: Configure the firewall
Hard
A.Loading the nf_conntrack_ftp kernel module via modprobe.
B.Both loading the nf_conntrack_ftp module and adding a rule to accept RELATED state traffic.
C.A rule to accept RELATED state traffic: iptables -A INPUT -m state --state RELATED -j ACCEPT.
D.A rule to accept traffic on TCP ports 1024-65535: iptables -A INPUT -p tcp --dport 1024:65535 -j ACCEPT.
Correct Answer: Both loading the nf_conntrack_ftp module and adding a rule to accept RELATED state traffic.
Explanation:
Passive FTP is tricky for stateful firewalls. The client establishes a control connection on port 21. For data transfer (like a directory listing), the server tells the client to connect to a new, high-numbered port. From the firewall's perspective, this incoming connection on a random high port is NEW and would normally be blocked. The nf_conntrack_ftp kernel module (also known as ip_conntrack_ftp) is a connection tracking helper that inspects the FTP control connection. It identifies the port the server offers for the data connection and dynamically marks the subsequent incoming connection on that port as RELATED to the existing control connection. Therefore, two things are required: 1) the helper module must be loaded, and 2) an iptables rule must exist to explicitly ACCEPT traffic whose state is RELATED.
Incorrect! Try again.
57When hardening /etc/fstab for security, which combination of mount options for a separate /tmp partition provides the most comprehensive protection against common local attacks, such as executing downloaded scripts or using SUID binaries?
Managing Linux Security: Harden a Linux system
Hard
A.ro,noatime
B.noexec,nosuid,nodev
C.usrquota,grpquota,acl
D.defaults,rw
Correct Answer: noexec,nosuid,nodev
Explanation:
This combination provides layered security for a world-writable directory like /tmp. noexec prevents any binary files stored there from being executed directly. nosuid prevents any SUID/SGID bits on files from taking effect, which stops a common privilege escalation vector. nodev prevents the creation of character or block special device files, which could be used to access system hardware. ro (read-only) would break /tmp's functionality. defaults is a standard baseline, not a hardening measure. Quotas and ACLs are for resource management and permissions, not for preventing execution-based attacks.
Incorrect! Try again.
58Given the following script using Bash's extended globbing features:
bash
#!/bin/bash
shopt -s extglob
filename="report.txt"
case $filename in .@(log|txt)) echo "Text or Log File";;
!(report.)) echo "Not a Report File";; .pdf) echo "PDF File";; ) echo "Unknown";;
esac
What is the output of this script?
Implementing Simple Scripts: Use shell script elements
Hard
A.Not a Report File
B.Text or Log File
C.The script will produce a syntax error.
D.Unknown
Correct Answer: Text or Log File
Explanation:
This question tests knowledge of advanced Bash features (extglob) and the order of evaluation in case statements. The case statement evaluates patterns sequentially and stops at the first match.
The first pattern is *.@(log|txt). The @(...) pattern matches exactly one of the given sub-patterns. Since filename is "report.txt", it matches *.txt.
Because a match is found, the script executes echo "Text or Log File" and exits the case block.
It never evaluates the second pattern !(report.*), which means "match anything except files starting with 'report.'". Even though "report.txt" would not match this second pattern, it's irrelevant because the first pattern already matched.
Incorrect! Try again.
59A web application running under the httpd_t SELinux context needs to send email, but SELinux is blocking the connection to the local mail transfer agent (MTA). The administrator knows there is an SELinux boolean for this. What is the correct command to persistently allow this action, and why is this method superior to writing a custom policy module in this specific scenario?
Managing Linux Security: Configure SELinux or AppArmor
Hard
A.setsebool httpd_can_sendmail 1 - It's superior because it's simpler and may not survive a reboot.
B.audit2allow -a -M httpd_sendmail; semodule -i httpd_sendmail.pp - It's superior because it is more specific to the exact denial.
C.setsebool -P httpd_can_sendmail on - It's superior because it uses a pre-defined, tested, and supported policy interface, making it less error-prone and more maintainable than a custom module.
D.semanage boolean -m --on httpd_can_sendmail - It's superior because it only affects one service without requiring a policy recompile.
Correct Answer: setsebool -P httpd_can_sendmail on - It's superior because it uses a pre-defined, tested, and supported policy interface, making it less error-prone and more maintainable than a custom module.
Explanation:
For common, expected application behaviors like a web server sending mail, the SELinux reference policy provides tunable booleans. The correct boolean is httpd_can_sendmail. The command to set it persistently across reboots is setsebool -P httpd_can_sendmail on. This method is superior to creating a custom policy with audit2allow because it's an intended, built-in feature of the policy. It's maintained by the policy packagers, less likely to break on system updates, and clearly signals the admin's intent. Creating a custom policy for such a common task is overkill and creates a maintenance burden. semanage boolean can also work but setsebool -P is the more common and direct tool for this task.
Incorrect! Try again.
60A bash script is designed to perform a cleanup operation on exit, even if an error occurs. Consider this script:
bash
#!/bin/bash
set -e
trap 'echo "Cleanup trap fired"' EXIT
main() {
echo "Main function started"
(
# Start of subshell
trap 'echo "Subshell trap fired"' EXIT
echo "Inside subshell"
exit 5
echo "This is never printed"
)
echo "Main function finished"
}
main
What is the final output when this script is executed?
Implementing Simple Scripts: Implement scripts with logical controls
Hard
A.Main function started
Inside subshell
Cleanup trap fired
B.Main function started
Inside subshell
Subshell trap fired
Cleanup trap fired
C.Main function started
Inside subshell
Subshell trap fired
Main function finished
Cleanup trap fired
D.Main function started
Inside subshell
Subshell trap fired
Correct Answer: Main function started
Inside subshell
Subshell trap fired
Main function finished
Cleanup trap fired
Explanation:
This question tests a deep understanding of trap, subshells, and the exit command.
The main script sets a trap on EXIT.
main() is called, printing "Main function started".
A subshell is created with (...).
Inside the subshell, a newtrap on EXIT is set. This trap is local to the subshell.
"Inside subshell" is printed.
The exit 5 command is executed. Crucially, exit inside a subshell only terminates the subshell, not the parent script.
As the subshell exits, its local EXIT trap fires, printing "Subshell trap fired".
Control returns to the parent script, right after the subshell block. The set -e option is not triggered because the subshell's exit is just a command completion to the parent.
The parent script continues, printing "Main function finished".
The main function finishes, and the script reaches its end. As the main script exits, its EXIT trap fires, printing "Cleanup trap fired".