Linux Systems Auditing
local graph
Chapter 7 — Linux Systems Auditing
Section titled “Chapter 7 — Linux Systems Auditing”Linux, the open-source operating system known for its stability, security, and flexibility, has become a critical component of modern IT infrastructures. You will find a lot of great detailed books on Linux that will review its many variations and applications. From powering servers and cloud platforms to running embedded systems and Internet of Things (IoT) devices, Linux distributions play a vital role in supporting the digital operations of organizations across various industries. We are going to focus on the parts that matter to you as an auditor. As an IT auditor, auditing Linux systems is essential to ensure an organization’s IT environment’s security, compliance, and overall health.
This chapter provides a guide to auditing Linux systems, focusing on the most common security configurations, user access management, firewall and network security, package management, and automation. Whether you are new to Linux auditing or looking to expand your skills, this chapter will provide you with the knowledge and practical expertise needed to effectively assess and secure Linux endpoint systems. You will learn how to audit and harden essential security configurations, such as Secure Shell (SSH) settings, password policies, Pluggable Authentication Modules (PAM) configurations, system logging, file permissions, and kernel security parameters.
User access management is another aspect of Linux auditing, and this chapter will guide you through the process of effectively managing user accounts, groups, and privileges. We will use a readily available Debian distribution to demonstrate the methods. You will learn how to implement the principle of least privilege, audit sudo configurations, and mitigate risks related to user access control.
The following topics will be covered in this chapter:
- Introduction to Linux
- Security configurations that are common in Linux distributions
- Managing user access and privileges in Linux
- Auditing firewall and network security with Uncomplicated Firewall (
ufw) andiptables
Whether you are an aspiring IT auditor or an experienced professional looking to expand your Linux auditing skills, this chapter will provide you with the foundation needed to confidently navigate the security landscape of Linux systems and contribute to the overall security and compliance of an organization’s IT infrastructure.
Introduction to Linux
Section titled “Introduction to Linux”Linux is a free and open-source operating system that has gained significant popularity since its creation by Linus Torvalds in 1991. Based on the Unix operating system, Linux is known for its stability, security, and flexibility. Linux is widely used in various computing environments in commercial and private applications.
One of the great features of Linux is its modular design, which allows organizations to modify the entire operating system to fit different applications. The unique customization has led to the development of numerous Linux distributions, or “distros,” each with its own unique set of features, user interfaces, and package management systems.
Some of the most popular Linux distributions include the following:
- Red Hat Enterprise Linux (RHEL): RHEL is the leading Linux distribution used for servers in enterprise environments. Known for its robustness, security features, and professional support services, RHEL is widely adopted by organizations for critical applications and services.
- Kali Linux: A Debian-based distribution designed for digital forensics and penetration testing. It is known for its wide array of security and hacking tools. Throughout this chapter, we will primarily focus on commands and configurations relevant to most Linux distributions that can be executed in the freely available copy of Kali.
- Debian: Known for its stability and extensive package repository, Debian is the foundation for many other distributions and the one we will use to demonstrate commands throughout this chapter.
- Ubuntu: Built on top of Debian, Ubuntu is user friendly and has a large community of users and developers.
- CentOS: A community-driven, enterprise-class distribution that is functionally compatible with RHEL.
- Fedora: A community-supported distribution sponsored by Red Hat, focusing on innovation and cutting-edge technologies.
The preceding list is certainly not exhaustive (I see you, Kali Linux!. These distributions and many others offer users a wide range of choices based on their specific requirements, skill levels, and intended use cases. Kali Linux is an essential distribution for auditors and security professionals due to its free availability, specialized digital forensics, and penetration testing tools. In this chapter, while our primary focus will be on showing general Linux auditing approaches, we will also touch upon how Kali Linux can be utilized for security assessments and vulnerability testing.
Linux has become increasingly prevalent in enterprise environments due to its robustness, scalability, and cost effectiveness. Many organizations rely on Linux to power their mission-critical applications and infrastructure, which makes the auditing process even more important.
Linux plays an important role in cloud computing and virtualization environments. Many cloud platforms, such as Amazon Web Services (AWS), Google Cloud Platform (GCP), and Microsoft Azure, use Linux as the underlying operating system for their services. Linux’s lightweight nature and ability to efficiently allocate resources make it well-suited for running multiple virtual machines on a single physical server, helping with cost savings and increased flexibility for organizations.
Linux is also widely used in embedded systems and internet of things (IoT) devices. The small footprint of Linux and its customizability make it an excellent choice for embedded applications. Many smart devices, such as routers, smart TVs, and industrial control systems, run on Linux-based operating systems such as Android, Raspbian, or the Yocto Project.
As Linux continues to expand its role in enterprise environments, ensuring the security and compliance of Linux systems becomes increasingly important. Regular auditing helps organizations identify and mitigate potential vulnerabilities, maintain the integrity of their systems, and meet regulatory and industry standards.
Auditing Linux systems generally involves assessing the security controls, configurations, and practices in place to protect sensitive data and maintain the systems’ confidentiality, integrity, and availability. Organizations can ensure that their Linux systems adhere to security best practices and comply with relevant regulations and standards by conducting regular audits, such as the Payment Card Industry Data Security Standard (PCI DSS) or the Health Insurance Portability and Accountability Act (HIPAA).
Just like many of the audits we have discussed throughout this book, many industries have specific regulatory and compliance requirements that organizations must adhere to. Auditing Linux systems helps ensure the necessary security controls and processes are in place to meet these standards.
In the following sections, we will look into the various aspects of auditing Linux systems, including security configurations, user access management, firewall and network security, package management, and automation. Organizations can effectively secure and maintain their Linux environments by understanding and implementing these best practices.
Security configurations that are common in Linux distributions
Section titled “Security configurations that are common in Linux distributions”Let’s get into some hands-on auditing. We will use a Debian distro to illustrate some of these commands and give you a feel for what to expect during an audit. You always want to research the type of distro an organization uses and then follow the commands and file structures used by that build. Ensuring the security of Linux systems requires careful configuration and hardening of various components. This section will cover common security configurations that should be audited and implemented across different Linux distributions to minimize vulnerabilities and enhance overall system security.
Auditing SSH configurations
Section titled “Auditing SSH configurations”First up, let’s look at auditing and hardening the SSH configurations. SSH is a widely used protocol for remote access and administration of Linux systems. You can check all the items mentioned throughout this chapter in either the GUI or the terminal. I’ll alternate between examples to give you both perspectives. Properly configuring and securing SSH is needed to prevent unauthorized access and protect sensitive data. We will start by reviewing the SSH configuration file (/etc/ssh/sshd_config).
The SSH daemon configuration file, located at /etc/ssh/sshd_config, contains various settings that control the behavior of the SSH server. Figure 7*.1* shows how to navigate to this file via the terminal. You can see in the figure that the sshd_config file is listed. Auditors should review this file to ensure that best practices are followed, such as the following:
- Disabling root login
- Setting a firm password policy
- Configuring idle timeout values
- Limiting access to specific users or groups

Figure 7.1 – SSH configuration
To minimize the risk of unauthorized root access, industry best practice recommends disabling direct root login via SSH. Instead, users should log in with their individual accounts and use sudo for privileged operations. You might also consider implementing key-based authentication instead of password-based authentication, providing an extra security layer. Figure 7*.2* shows the contents of an unedited default SSH file. You can see where port 22 is listed as the default. Remember to always confirm with the organization you are auditing before changing any system configurations.

Figure 7.2 – SSH config default file
By default, SSH listens on port 22. Changing the default port can help reduce the SSH service’s visibility to potential attackers. Limiting SSH access to specific IP addresses or subnets using firewall rules or Transmission Control Protocol (TCP) Wrappers can further improve security by preventing unauthorized connection attempts.
Strong password policies are another major way to protect user accounts from unauthorized access. Auditors should assess the current password policies and ensure they align with the organization’s policies and industry best practices.
Linux distributions provide various mechanisms to enforce password complexity and expiration settings. Auditors should review the PAM configuration files, such as /etc/pam.d/common-password or /etc/pam.d/system-auth, to verify the following:
- Minimum password length is enforced
- Password complexity requirements (e.g., a mix of uppercase, lowercase, numbers, and special characters) are in place
- Password expiration and change frequency are set appropriately
PAM modules can be used to implement and enforce password policies consistently across the system. Auditors should ensure that the appropriate PAM modules, such as pam_cracklib or pam_pwquality, are configured correctly in the PAM configuration files. The organization will define what “correct” looks like in these files, however, the Linux man page offers some guidance on possible settings.
You can access the man page in the Linux terminal by typing “ man ” and the command you want to review. If you are unable to load a Linux distribution to explore some of the capabilities then you can look at man pages online. https://linux.die.net/man/5/pam.d is a great source of information about the pam.d files. Going back to our exploration of what “configured correctly” means, we can see on the man page there are a few examples.
Here is an example configuration that enforces strong password policies using the pam_cracklib and pam_unix modules:
# These lines stack two password type modules. In this# example,theuser is given 3 opportunities to enter a# strong password. The"use_authtok" argument ensures# that the pam_unix module does not prompt for# a password, but instead uses the one provided# by pam_cracklib.passwd password required pam_cracklib.so retry=3 minlen=12 difok=3vpasswd password required pam_unix.so use_authtokExplanation of the configuration
Section titled “Explanation of the configuration”Let’s review what the configuration means to an organization’s systems:
pam_cracklib.so retry=3 minlen=12 difok=3:This line configures thepam_cracklibmodule to enforce password complexity requirements:retry=3: This allows the user three attempts to enter a strong passwordminlen=12: This sets the minimum password length to 12 charactersdifok=3:This requires at least three different character types (e.g., uppercase, lowercase, digits, special characters)
pam_unix.so use_authtok: This line ensures that thepam_unixmodule uses the password provided bypam_cracklibwithout prompting the user again
Auditors should verify that these or similar configurations are present in the relevant PAM configuration files (e.g., /etc/pam.d/common-password) and are tailored to meet the organization’s security policies. Organizations might define password length, age, and complexity differently.
Account lockout policies should be implemented to prevent brute-force attacks and enforce password security. Forced entry attack protection can be achieved through PAM modules such as pam_tally2 or pam_faillock, which lock an account after a specified number of failed login attempts. The pam_pwhistory module can maintain a password history and prevent users from reusing recent passwords. Let’s take a look at an example from the man page on some of the configuration elements for each of these commands.
Example configurations for account lockout and password history
Section titled “Example configurations for account lockout and password history”Account lockout and password history policies will most certainly vary across different organizations. Let’s focus on how to audit and confirm the settings and how to read the output:
pam_tally2: To configure account lockout policies usingpam_tally2, the following lines can be added to the PAM configuration files. This setup ensures that accounts are temporarily locked after a specified number of failed login attempts, mitigating the risk of brute-force attacks:Let’s break down each setting in the preceding# The following lines lock an account after 5 failed login # attempts.auth required pam_tally2.so deny=5 onerr=fail unlock_time=600account required pam_tally2.sopam_tally2command:deny=5: This locks the account after five failed login attemptsonerr=fail: This locks the account if there is an error in counting attemptsunlock_time=600: This unlocks the account after 600 seconds (10 minutes)
pam_faillock: Similarly,pam_faillockcan be used to enforce account lockout policies with additional options for auditing failed attempts. The following configuration demonstrates how to set these policies, which help to monitor and control failed login attempts more granularly:Let’s review each setting in the preceding# The following lines lock an account after 5 failed login # attempts..auth required pam_faillock.so preauth audit silent deny=5 unlock_time=600auth [default=die] pam_faillock.so authfail audit deny=5 unlock_time=600account required pam_faillock.sopam_faillocksetting:deny=5: This locks the account after five failed login attemptsunlock_time=600: This unlocks the account after 600 seconds (10 minutes)preauth audit silent: This records authentication attempts without informing the userauthfail audit: This audits failed authentication attempts
pam_pwhistory: To enforce password history policies, thepam_pwhistorymodule is configured. Setting the password history ensures that users cannot reuse a set number of previous passwords, enhancing overall password security. The following configuration specifies how to set up the module for tracking password history:The following part in the PAM configuration file specifies the policy on password reuse:# The following line keeps a history of the last 5 passwords.password required pam_pwhistory.so remember=5remember=5: This prevents the reuse of the last five passwords
Auditors should verify that these or similar configurations are present in the relevant PAM configuration files (e.g., /etc/pam.d/common-auth and /etc/pam.d/common-password) and are tailored to meet the organization’s security policies.
Reviewing and configuring PAM
Section titled “Reviewing and configuring PAM”PAM is a flexible framework that allows system administrators to configure authentication and authorization policies on Linux systems. Auditors should review PAM configuration files to ensure that appropriate modules are used and configured securely.
PAM configuration files are typically located in the /etc/pam.d/ directory. Each file corresponds to a specific service or application, such as login, sshd, or sudo. These files define the authentication and authorization rules for the respective services.
Auditors should review the PAM configuration files to verify the following:
- The required PAM modules are included and properly configured.
- Authentication mechanisms, such as password, public key, or smart card authentication, are set up correctly. (Review the organization’s policy for the setup specifications.)
- Access control restrictions, such as account and session management, are in place.
PAM offers various modules that can enhance the security of the authentication process, for example:
pam_faildelayintroduces a delay after failed login attempts to prevent brute-force attackspam_wheelrestricts access to the su command to members of a specific grouppam_accessallows or denies access based on user, host, or service-specific rules
Auditors should consider implementing these modules where appropriate to strengthen authentication security per the organization’s policies.
Checking and configuring system logging and auditing
Section titled “Checking and configuring system logging and auditing”System logging and auditing are other essential items for monitoring and investigating security events on Linux systems. Auditors should ensure that logging and auditing are properly configured and that relevant logs are collected and preserved. Let’s take a look at how to check that on a Linux system.
Linux systems store various log files in the /var/log directory. Auditors should regularly review these log files, particularly the following:
/var/log/auth.log or /var/log/secure: Authentication and authorization events./var/log/syslog: General system messages./var/log/apt/history.log: Package installation and update history (Debian-based systems). Figure 7*.3* shows some of the default system items you might find in this file.
Figure 7.3 – Reviewing a history log file
/var/log/yum.log: Package installation and update history (Red-Hat-based systems).
An auditor can also run grep queries on each of these files in the /var/log/ directory to check for any successful or failed logins that might be an indicator of compromise. grep is a terminal command available in Linux distributions to search for strings, or numbers, inside a file. Let’s do some grep commands on the /var/log/auth.log file to see whether we can find some failed and successful logins.
To demonstrate these indications, we have set up a parallels virtual machine using a Debian distro and injected some logins for the logs. Figure 7*.4* shows what you might find if a user puts in a bad password. Note that we can also see that this was a root-level user. If there were several failed logins, then that might be cause for concern of a potential attack.
In Figure 7*.4*, we are using the sudo grep 'failure' /var/log/auth.log command and we can see there is indeed a failed login for the parallels root user. We can also find other information such as what machine they used (ubuntu-linux—22-04-02-desktop) and what date/time they put in the bad password.

Figure 7.4 – Failed login
Just like a failed login, we can also check to see when there is a successful login. Figure 7*.5* shows how to use a similar grep command used in Figure 7*.4* to find successful logins.

Figure 7.5 – Successful login
An auditor might want to check successful logins to ensure only authorized users are logging in with accounts assigned to that user.
rsyslog is a popular logging daemon used on many Linux distributions. Auditors should verify that rsyslog is configured to collect and forward logs to a centralized logging server. A centralized logging server allows for easier analysis and correlation of log data across multiple systems.
The Linux Auditing System (auditd) provides a way to track security-relevant events on the system. Auditors should ensure that auditd is installed and properly configured. Key configuration files to review include the following:
/etc/audit/auditd.conf: Theauditddaemon configuration/etc/audit/rules.d/: The directory containing audit rules
Auditors should also regularly review the audit logs, typically stored in /var/log/audit/, to identify suspicious activities or policy violations. Just like the other log reviews we have discussed, the auditor is looking for anomalies based on the organization’s policies. You must review them first before digging into the logs.
Assessing and securing file system permissions
Section titled “Assessing and securing file system permissions”File system permissions play a vital role in maintaining the security and integrity of Linux systems. Auditors should assess file and directory permissions to ensure that the principle of least privilege is followed and that sensitive files are adequately protected. See Chapter 4, Next-Generation Firewall Auditing, for a refresher on the principles of least privilege.
Linux uses a combination of file ownership and permissions to control access to files and directories. One of the great things about Linux is that each file and directory has a clear trail of ownership for individual owners, groups, and others. Auditors should understand the different permission levels (read, write, execute) and how they apply to files and directories.
The ls command can be used to list file and directory permissions. For example, ls -l displays the permissions, ownership, and other details of files and directories. Auditors can also use the find command to search for files and directories with specific permissions. For instance, find / -perm -4000 finds all files with the Set User ID (SUID) permission set, which is indicated by the 4000 value. Setting the SUID is significant because it allows a user to execute a file with the same permissions as the file owner. Figure 7*.6* shows how we might review the permissions for an Audit Results.xml file in a Kali Linux distro.

Figure 7.6 – Linux permissions
Figure 7*.6* shows the output of the ls -l command in a terminal. Here’s what can be assessed from the output:
-rw-r--r--: These are the file permissions for'Audit Results.xml'. The user (owner) has read and write permissions (rw-), and both the group and others have read-only permissions (r--).1: This is the number of hard links to the file, which is one in this case.Simpson Simpson: The owner and group of the file are listed next.129 Apr 8 17:35: The size of the file, the date, and the time are also listed.'Audit Results.xml': The name of the file is displayed with spaces in the filename enclosed in single quotes, a common way to show file names with spaces in terminal outputs.
The principle of least privilege tells us that users should only have the minimum permissions necessary to perform their tasks. Auditors should ensure that file and directory permissions are set appropriately and that users do not have excessive permissions. Some best practices include the following:
- Removing unnecessary SUID and Set Group ID (SGID) permissions
- Restricting access to sensitive files and directories
- Ensuring that world-writable directories are avoided or carefully controlled
Once the auditor has reviewed some of the common security configuration files, they should verify that these permissions are properly applied and enforced throughout the system. Error checking includes checking critical files in directories such as /etc, /var, and user home directories to ensure there are no misconfigurations or vulnerabilities.
Analyzing and hardening kernel security parameters
Section titled “Analyzing and hardening kernel security parameters”The Linux kernel provides various security parameters that can be tuned to enhance the system’s overall security. Auditors should review and, if necessary, modify these parameters to align with best practices and the organization’s security requirements.
Kernel security parameters are typically set in the /etc/sysctl.conf file or in files located in the /etc/sysctl.d/ directory. Auditors should review these files to ensure appropriate security settings are in place. Some important parameters to consider include the following:
kernel.exec-shield: This enables memory protection to prevent buffer overflow attackskernel.randomize_va_space: This enables address space layout randomization (ASLR)net.ipv4.conf.all.rp_filter: This enables source address verification to prevent IP spoofing
You can review how RHEL explains setting up kernel.exec-shield here to limit writing to system memory in some instances: https://www.stigviewer.com/stig/red_hat_enterprise_linux_6/2020-09-03/finding/V-217910.
ASLR is a security mechanism that randomizes the memory layout of a process, making it harder for attackers to predict memory addresses and exploit vulnerabilities. Auditors should verify that ASLR is enabled by checking the value of kernel.randomize_va_space (a value of 0 indicates no randomization, a value of 1 shows a conservative level of randomization and a value of 2 indicates full randomization). To confirm kernel.randomize_va_space, run the following command:
sudo sysctl kernel.randomize_va_spaceThe output will list the randomization following the name. The auditor will see something similar to this output if the level of randomization is set to the most conservative level (i.e., the security of the system is set to the highest level):
kernel.randomize_va_space = 2Kernel parameters can also set resource limits and tune network settings for improved security. For example:
fs.suid_dumpable: This disables core dumps for SUID programs to prevent sensitive information leakagenet.ipv4.icmp_echo_ignore_broadcasts: This ignores Internet Control Message Protocol (ICMP) echo requests to broadcast addresses to prevent Smurf attacksnet.ipv4.tcp_syncookies: This enables SYN cookies to protect against SYN flood attacks
Auditors should review and configure these parameters based on the organization’s security needs and best practices. Hardening the Linux configuration files is a big step to locking down the system but can have serious impacts on operations. Regular audits and timely configuration adjustments are essential to maintain a robust and secure Linux environment.
Managing user access and privileges in Linux
Section titled “Managing user access and privileges in Linux”We just looked at some of the ways to examine user permissions with the read/write/execute permissions in the Audit Results.xml example. Effective management of user access and privileges is essential for maintaining the security and integrity of Linux systems. This section will cover the key aspects of user and group management, auditing and managing sudo privileges, implementing the principle of least privilege, and identifying and mitigating risks related to user access control.
Understanding user and group management in Linux
Section titled “Understanding user and group management in Linux”Linux uses a combination of users and groups to control access to system resources and files. Each user has a unique user ID (UID) and belongs to one or more groups. Groups are used to organize users and grant them specific permissions and privileges.
Auditors should be familiar with the tools and processes used to create and modify user accounts on Linux systems. The useradd command is used to create new user accounts, while usermod is used to modify existing accounts. Important options to consider when creating or modifying user accounts include the following:
- Setting the user’s home directory and login shell
- Specifying the user’s group memberships
- Defining password expiration and aging policies
Auditors should also be familiar with basic commands to modify password files such as change, which allows you to modify the password age on a system.
Auditors should ensure that user accounts are created with appropriate home directories, login shells, and group memberships based on the user’s role and requirements. They should also review password expiration and aging policies to ensure they align with the organization’s security policies. Always follow the organization’s policies!
Linux uses groups to assign permissions and privileges to multiple users doing a similar task. We often see this for role-based access control (RBAC) security models. The groupadd command creates new groups, while groupmod modifies existing groups. Users can be added to or removed from groups using the usermod command.
Auditors should regularly review user and group configurations to ensure they align with the organization’s security policies and best practices. Some key areas to audit include are as follows:
- Identifying and removing unused or outdated user accounts
- Ensuring that users are assigned to the appropriate groups based on their roles and responsibilities
- Verifying that group permissions are set correctly and not overly permissive
Let’s take a look at an easy way to see what user and group accounts exist and what groups they are a member of that would be of particular interest during an audit. Following each main bullet is some insight into how an auditor would use this information:
- List all user accounts:
cut -d: -f1 /etc/passwd.- Review the list and identify any unused, outdated, or suspicious user accounts.
- Check user account details:
grep "johndoe" /etc/passwd.- Replace
johndoewith the username you want to review. This command displays the user’s details, including their home directory, login shell, and user ID.
- Replace
- List all groups:
getent group.- Review the list of groups and their respective members.
- Check group membership for a specific user:
groups johndoe.- Replace
johndoewith the username you want to review. This command displays the groups the user belongs to.
- Replace
- Check group permissions:
ls -l /etc/group.- Review the group file permissions to ensure they are set correctly (usually
-rw-r--r--or644).
- Review the group file permissions to ensure they are set correctly (usually
- Check sudo privileges:
sudo -l -U johndoe.- Replace
johndoewith the username you want to review. This command lists the sudo privileges granted to the user.
- Replace
- Review the sudoers configuration:
sudo visudo.- Check the
sudoersfile for any overly permissive or incorrect sudo configurations.
- Check the
- Remove unused or outdated user accounts:
sudo userdel -r johndoe.- Replace
johndoewith the username you want to remove. The-roption removes the user’s home directory as well.
- Replace
As you can see, managing user permissions in Linux is not much different than any other operating system. A savvy reader might have noticed that some group permissions can be managed using numbers instead of “read/write/execute” style settings. Linux number permissions offer a wonderful level of flexibility for administrators to apply permissions. Linux offers many topics that we could fill multiple books with, however, you can learn more about some of the specific details of each number here: https://www.ricmedia.com/tutorials/linux-file-permissions-tutorial You just need to understand the specific commands to verify the accounts are configured correctly.
Auditing and managing sudo privileges
Section titled “Auditing and managing sudo privileges”Sudo is a powerful tool that allows users to execute commands with elevated privileges. Auditors should pay close attention to sudo configurations and usage to prevent privilege abuse and unauthorized access. You certainly need to ensure the organization is protecting any elevated privileged accounts and their passwords.
The visudo command is the preferred way in Linux to edit the sudo configuration file (/etc/sudoers). If you try and open the file without the visuod command, you will get a warning. Figure 7*.7* shows the GUI version of where to locate this important file.

Figure 7.7 – The subdoers folder
Auditors should review the sudoers file to ensure the following:
- Only trusted users are granted sudo access
- Users should only be granted the bare minimum privileges needed to perform their tasks
- Sudo access is limited to specific commands or command categories
Figure 7*.8* shows how to safely edit the sudoers file using visudo. You will be prompted for a sudo password. You can see the warning we discussed earlier at the top of the file to use visudo.

Figure 7.8 – Using visudo
Sudo logs provide valuable information about the usage of sudo privileges. Auditors should regularly review sudo logs, typically stored in /var/log/auth.log or /var/log/secure, to identify suspicious or unauthorized sudo usage. Tools such as sudoreplay can be used to replay and analyze sudo sessions.
The principle of least privilege should be applied when granting sudo access to users. Auditors should ensure that users are only granted the specific privileges they need to perform their duties and that sudo access is regularly reviewed and adjusted as user roles and responsibilities change.
Implementing the principle of least privilege
Section titled “Implementing the principle of least privilege”The principle of least privilege is a fundamental security concept that users should only have the minimum permissions necessary to perform their tasks. Auditors should work with system administrators to implement this principle across the organization’s Linux systems.
User permissions and access levels should be determined based on job roles and responsibilities. Auditors should collaborate with management and system administrators to define clear roles and associated permissions. This helps ensure that users have access to the resources they need while minimizing the risk of unauthorized access or misuse.
User permissions and access levels should be regularly reviewed to identify and revoke any unnecessary or outdated privileges. Auditors should establish a process for periodic access reviews and ensure that permissions are promptly adjusted when user roles or responsibilities change.
Access control lists (ACLs) provide a more granular way to control access to files and directories than traditional Unix permissions. ACLs allow administrators to define permissions for specific users and groups in addition to the standard owner, group, and other permissions. Auditors should consider recommending using ACLs where more fine-grained access control is required.
Identifying and mitigating risks related to user access control
Section titled “Identifying and mitigating risks related to user access control”Auditors should be proactive in identifying and mitigating risks related to user access control. Some common risks and mitigation strategies include the following:
- Inactive or dormant user accounts pose a security risk as attackers can target them. Auditors should regularly review user account activity and work with system administrators to disable or remove accounts that have been inactive for a specified period.
- Implementing monitoring and alerting mechanisms can help detect suspicious user activities, such as multiple failed login attempts or access to sensitive files and directories. Auditors should ensure that appropriate monitoring tools and processes are in place and that alerts are promptly investigated and addressed.
- Multi-factor authentication (MFA) provides an additional layer of security by requiring users to provide two or more forms of identification when accessing critical systems or resources. Auditors should recommend the implementation of MFA for high-risk systems and user accounts to reduce the risk of unauthorized access.
Now that we have a better understanding of user controls and access groups, let’s look at a case study example. The following case study will demonstrate how these principles can be put into practice to identify and remediate excessive user privileges, highlighting the critical role of IT auditors in maintaining system security and preventing data breaches.
Case study – identifying and remediating excessive user privileges
Section titled “Case study – identifying and remediating excessive user privileges”To illustrate the importance of auditing and managing user access and privileges, let’s review a case study.
In this scenario, an organization has recently experienced a data breach due to an attacker gaining unauthorized access to a critical system using a compromised user account. The objectives of the audit are to identify any user accounts with excessive privileges, determine the root cause of the breach, and recommend remediation steps to prevent future incidents.
Let’s take a look at a step-by-step audit process using Debian (look for the specific commands throughout this chapter):
- Review the
sudoersconfiguration file (/etc/sudoers) to identify users with overly broad sudo privileges. - Analyze user group memberships to ensure users are only assigned to groups relevant to their job roles.
- Review file and directory permissions to identify any world-writable or world-executable files that could be exploited by an attacker.
- Investigate the compromised user account to determine how the attacker gained access (e.g., weak password, phishing attack, etc.).
- Review system logs (
/var/log/auth.log,/var/log/syslog) to trace the attacker’s activities and identify any additional compromised accounts or systems.
Based on the audit findings, you recommend the following remediation steps should be taken:
- Remove excessive sudo privileges from user accounts and implement a more granular sudo configuration based on the principle of least privilege.
- Adjust user group memberships to ensure users can only access the resources necessary for their job roles.
- Secure file and directory permissions to prevent unauthorized access or modification.
- Implement a strong password policy and educate users on best practices for creating and managing passwords.
- Deploy MFA for critical systems and user accounts to prevent unauthorized access even if a password is compromised.
- Regularly monitor system logs and user activities to detect and promptly respond to suspicious or unauthorized actions.
Thanks to your thorough audit of users and their permissions, the network is safe for one more day! Organizations can significantly reduce the risk of unauthorized access, privilege abuse, and data breaches by conducting thorough audits and implementing effective user access and privilege management practices. Regular audits and continuous monitoring are essential for maintaining a secure and compliant Linux environment.
Having explored the critical aspects of managing user access and privileges in Linux systems, we now turn our attention to another crucial element of Linux security: network protection. While user access control forms an essential internal security layer, firewalls serve as the first line of defense against external threats. Let’s examine how to audit and configure these vital network security controls.
Auditing firewall and network security with ufw and iptables
Section titled “Auditing firewall and network security with ufw and iptables”In our final section, we are going to build on some of the information we covered in Chapter 4, Next-Generation Firewall Auditing. Firewalls and network security controls are essential components of a comprehensive Linux security strategy. In this section, we will focus on auditing and configuring firewalls using ufw and iptables, two popular firewall management tools in Linux.
As we established in Chapter 4, Next-Generation Firewall Auditing, the main purpose of a firewall is to create a barrier between trusted internal and untrusted external networks, such as the internet.
Linux uses a built-in firewall called Netfilter. iptables is how administrators configure Netfilter. It allows administrators to define rules for accepting, rejecting, or modifying network traffic based on criteria such as source and destination IP addresses, ports, and protocols.
ufw, on the other hand, is a simplified frontend for managing iptables rules. It provides an easy-to-use command-line interface and a more user-friendly syntax for defining firewall rules. ufw abstracts the complexity of iptables and is suitable for users who prefer a simpler firewall management experience.
To install ufw on a Debian-based system, use the following command:
sudo apt install ufwOnce installed, you can enable ufw with the following command:
sudo ufw enableThis command will activate the firewall and apply the default rules, which block all incoming traffic and allow all outgoing traffic.
Auditing and configuring ufw rules
Section titled “Auditing and configuring ufw rules”To view the current status of ufw and the configured rules, use the following command:
sudo ufw status verboseThis command will display the firewall status (active or inactive) and a list of the current rules, including their action (allow or deny), source and destination IP addresses, and ports.
ufw allows you to easily add or remove rules for specific services and ports. For example, to allow incoming SSH traffic on port 22 (or a custom port you set to increase security, as we discussed earlier), use the following command:
sudo ufw allow sshTo allow incoming HTTP traffic on port 80, use the following command:
sudo ufw allow httpSimilarly, to remove a rule, use the delete keyword followed by the rule specification.
For example, to remove the SSH rule, use the following command:
sudo ufw delete allow sshufw provides logging and debugging options to help troubleshoot firewall issues. To enable logging, use the following command:
sudo ufw logging onYou will see a confirmation similar to Logging enabled, which will log firewall events to the / var/log/ufw.log file.
Auditing and configuring iptables rules
Section titled “Auditing and configuring iptables rules”Now, we need to examine the current iptables rules and chains. To view the current iptables rules and chains, use the following command:
sudo iptables -L -v -nFigure 7*.9* shows the command in action. The command will display the rules in the filter table, the default table for handling packet filtering.

Figure 7.9 – iptables
The output will show the rule specifications, including the action (ACCEPT, DROP, or REJECT), source and destination IP addresses, and ports. In a production firewall, the output in Figure 7*.9* would reflect actual IP addresses important to your audit.
iptables rules are defined using a specific syntax that includes the table, chain, and rule specification. For example, to allow incoming SSH traffic on port 22, use the following command:
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPTThe (-A) command appends a rule to the INPUT chain, specifying the TCP protocol (-p tcp), destination port 22 (--dport 22), and the ACCEPT action (- j ACCEPT).
To remove a rule, use the -D option followed by the chain and rule specification, similar to how we used the delete commands in the ufw section:
sudo iptables -D INPUT -p tcp --dport 22 -j ACCEPTiptables rules are not persistent by default and will be lost upon reboot. To save the current iptables configuration, use the iptables-save command:
sudo iptables-save > /etc/iptables.rulesThis command will save the rules to the / etc/iptables.rules file.
To restore the saved configuration on system startup, add the following line to the / etc/network/if-pre-up.d/iptables file:
iptables-restore < /etc/iptables.rulesMake sure to make the file executable with chmod + x /etc/network/if-pre-up.d/iptables.
Securing network services and ports
Section titled “Securing network services and ports”Finally, we need to take a look at the network side of things. Auditors should identify and disable any unnecessary network services to reduce the system’s attack surface. Use the ss command to list all listening ports and associated services:
sudo ss -tulpnReview the output and determine which services are not needed for the system’s intended purpose. Always follow the organization’s guidance on this part as well. You might have a best practice that says a port should be open or closed but if the organization wants it the opposite, then document the item as a finding and continue with your review.
If directed by the organization, then you can disable the unnecessary services using the right management commands (e.g., systemctl disable for system-managed services).
Whenever possible, ensure that secure protocols are used for network communication. For example, SSH can be configured to use strong encryption algorithms and disable insecure protocols such as telnet.
In the SSH configuration file (/etc/ssh/sshd_config), set the following options:
Protocol 2PermitRootLogin noPasswordAuthentication noThese settings enforce SSH protocol version 2, disable root login, and disable password authentication in favor of key-based authentication.
Network segmentation and isolation help contain the impact of a security breach by limiting the lateral movement of attackers. Auditors should recommend implementing network segmentation using VLANs, firewalls, and ACLs to separate critical systems and sensitive data from other network segments no matter what type of operating system is in use.
Summary
Section titled “Summary”This chapter provided a glimpse into auditing Linux systems, focusing on key aspects of security and compliance in modern IT infrastructures. We explored some Linux distributions that a new auditor can build at low-to-no cost to begin practicing audit skills, their enterprise significance, and the importance of rigorous auditing.
In the next chapter, we will begin investigating how to audit wireless access points and storage technology.