Mastering Linux Security and Hardening
local graph
Mastering Linux Security and Hardening
Section titled “Mastering Linux Security and Hardening”chapter_01
Section titled “chapter_01”node-book_mastering-linux-security-and-hardening_chapter-01-running-linux-in-a-virtual-environment — Running Linux in a Virtual Environment
chapter_02
Section titled “chapter_02”node-book_mastering-linux-security-and-hardening_chapter-02-securing-administrative-user-accounts — Securing Administrative User Accounts
chapter_03
Section titled “chapter_03”node-book_mastering-linux-security-and-hardening_chapter-03-securing-normal-user-accounts — Securing Normal User Accounts
chapter_04
Section titled “chapter_04”node-book_mastering-linux-security-and-hardening_chapter-04-securing-your-server-with-a-firewall-part-1 — Securing Your Server with a Firewall – Part 1
chapter_05
Section titled “chapter_05”node-book_mastering-linux-security-and-hardening_chapter-05-securing-your-server-with-a-firewall-part-2 — Securing Your Server with a Firewall – Part 2
chapter_06
Section titled “chapter_06”node-book_mastering-linux-security-and-hardening_chapter-06-encryption-technologies — Encryption Technologies
chapter_07
Section titled “chapter_07”node-book_mastering-linux-security-and-hardening_chapter-07-ssh-hardening — SSH Hardening
chapter_08
Section titled “chapter_08”node-book_mastering-linux-security-and-hardening_chapter-08-mastering-discretionary-access-control — Mastering Discretionary Access Control
chapter_09
Section titled “chapter_09”node-book_mastering-linux-security-and-hardening_chapter-09-access-control-lists-and-shared-directory-management — Access Control Lists and Shared Directory Management
chapter_10
Section titled “chapter_10”node-book_mastering-linux-security-and-hardening_chapter-10-implementing-mandatory-access-control-with-selinux-and-apparmor — Implementing Mandatory Access Control with SELinux and AppArmor
chapter_11
Section titled “chapter_11”node-book_mastering-linux-security-and-hardening_chapter-11-kernel-hardening-and-process-isolation — Kernel Hardening and Process Isolation
chapter_12
Section titled “chapter_12”node-book_mastering-linux-security-and-hardening_chapter-12-scanning-auditing-and-hardening — Scanning, Auditing, and Hardening
chapter_13
Section titled “chapter_13”node-book_mastering-linux-security-and-hardening_chapter-13-logging-and-log-security — Logging and Log Security
chapter_14
Section titled “chapter_14”node-book_mastering-linux-security-and-hardening_chapter-14-vulnerability-scanning-and-intrusion-detection — Vulnerability Scanning and Intrusion Detection
chapter_15
Section titled “chapter_15”node-book_mastering-linux-security-and-hardening_chapter-15-prevent-unwanted-programs-from-running — Prevent Unwanted Programs from Running
chapter_16
Section titled “chapter_16”node-book_mastering-linux-security-and-hardening_chapter-16-security-tips-and-tricks-for-the-busy-bee — Security Tips and Tricks for the Busy Bee
Who this book is for
Section titled “Who this book is for”This book is aimed at Linux administrators in general, whether or not they specialize in Linux security. The techniques that we present can be used on either Linux servers or on Linux workstations.
We assume that our target audience has had some hands-on experience with the Linux command line and has basic knowledge of the Linux essentials.
What this book covers
Section titled “What this book covers”Chapter 1, Running Linux in a Virtual Environment, gives an overview of the IT security landscape, and will inform the reader why learning Linux security would be a good career move. We’ll also show how to set up a virtual lab environment for the hands-on labs.
Chapter 2, Securing Administrative User Accounts, covers the dangers of always using the root user account, and introduces the benefits of using sudo instead.
Chapter 3, Securing Normal User Accounts, covers how to lock down normal user accounts, and ensure that the users use good-quality passwords.
Chapter 4, Securing Your Server with a Firewall – Part 1, involves working with the various types of firewall utilities.
Chapter 5, Securing Your Server with a Firewall – Part 2, continues the discussion about working with the various types of firewall utilities.
Chapter 6, Encryption Technologies, makes sure that important information—both at rest and in transit—are safeguarded with proper encryption.
Chapter 7, SSH Hardening, covers how to safeguard data in transit. The default Secure Shell configuration is anything but secure, and could lead to a security breach if left as is. This chapter shows how to fix that.
Chapter 8, Mastering Discretionary Access Control, covers how to set ownership and permissions on files and directories. We’ll also cover what SUID and SGID can do for us, and the security implications of using them. We’ll wrap things up by covering extended file attributes.
Chapter 9, Access Control Lists and Shared Directory Management, explains that normal Linux file and directory permissions settings aren’t very granular. With Access Control Lists, we can allow only a certain person to access a file, or we can allow multiple people to access a file with different permissions for each person. We’re also going to put what we’ve learned together in order to manage a shared directory for a group.
Chapter 10, Implementing Mandatory Access Control with SELinux and AppArmor, talks about SELinux, which is a Mandatory Access Control technology that is included with Red Hat-type Linux distributions. We’ll give a brief introduction here on how to use SELinux to prevent intruders from compromising a system. We’ll also give a brief introduction to AppArmor, which is another Mandatory Access Control technology that is included with Ubuntu and SUSE-type Linux distributions.
Chapter 11, Kernel Hardening and Process Isolation, covers how to tweak the Linux kernel to make it even more secure against certain types of attacks. It also covers some process isolation techniques to help prevent attackers from exploiting a Linux system.
Chapter 12, Scanning, Auditing, and Hardening, talks about how viruses that are a big problem for Windows users aren’t yet a huge problem for Linux users. If your organization has Windows clients that access Linux file servers, then this section is for you. You can use auditd to audit accesses to files, directories, or system calls on a Linux system. It won’t prevent security breaches, but it will let you know if some unauthorized person is trying to access a sensitive resource. SCAP, the Security Content Application Protocol, is a compliance framework that’s promulgated by the National Institute of Standards and Technology. OpenSCAP, the open source implementation, can be used to apply a hardening policy to a Linux computer.
Chapter 13, Logging and Log Security, gives you the basics about ryslog and journald, the two most prevalent logging systems that come with Linux-based operating systems. We’ll show you a cool way to make log reviews easier, and how to set up a secure central log server. We’ll do all of this just with the packages that come in your normal Linux distribution’s repositories.
Chapter 14, Vulnerability Scanning and Intrusion Detection, explains how to scan our systems to see if we’ve missed anything in our security configurations. We’ll also take a quick look at an intrusion detection system.
Chapter 15, Prevent Unwanted Programs from Running, explains how to use fapolicyd and partition mounting options to prevent untrusted programs from running on your system.
Chapter 16, Security Tips and Tricks for the Busy Bee, explains that since you’re dealing with security, we know that you’re a busy bee. This chapter introduces you to some quick tips and tricks to help make the job easier.
To get the most out of this book
Section titled “To get the most out of this book”- A working knowledge of basic Linux commands and how to navigate through the Linux filesystem.
- A basic knowledge about tools such as
lessandgrep. - Familiarity with command-line editing tools, such as vim or nano.
- A basic knowledge of how to control
systemdservices withsystemctlcommands.
For hardware, you don’t need anything fancy. All you need is a machine that’s capable of running 64-bit virtual machines. So, you can use any host machine that runs with almost any modern CPU from either Intel or AMD. (There are a couple of exceptions, though. First, some Intel Core i3 and Core i5 CPUs lack the required hardware acceleration to run virtual machines. Also, AlmaLinux 9, which we’ll be using, won’t run on the first generation of x86_64 CPUs. So, if you have an x86_64 machine that was made prior to 2010, AlmaLinux 9 won’t run on it.) For memory, I’d recommend using a host machine with at least 8 GB.
You can run any of the three major desktop operating systems on your machine, because the virtualization software that we’ll be using comes in flavors for Windows, macOS, and Linux.
Download the example code files
Section titled “Download the example code files”Conventions used
Section titled “Conventions used”There are a number of text conventions used throughout this book.
CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. For example: “open Firefox and navigate to https://localhost:9392 ”
A block of code is set as follows:
HTTP TRACK method is active, suggesting the host is vulnerable to XSTCookie wordpress_test_cookie created without the httponly flagAny command-line input or output is written as follows:
sudo apt updatesudo apt install podmanBold: Indicates a new term, an important word, or words that you see on the screen. For instance, words in menus or dialog boxes appear in the text like this. For example: “Set one to Bridged mode and leave the other in NAT mode.”
Warnings or important notes appear like this.
Tips and tricks appear like this.