Repository: trimstray/the-practical-linux-hardening-guide
Branch: master
Commit: 7b05a843c952
Files: 8
Total size: 22.8 KB
Directory structure:
gitextract_rt72ltgf/
├── .github/
│ ├── CODE_OF_CONDUCT.md
│ ├── CONTRIBUTING.md
│ └── FUNDING.yml
├── LICENSE.md
├── README.md
├── docs/
│ ├── _config.yml
│ └── index.md
└── lib/
└── .gitkeep
================================================
FILE CONTENTS
================================================
================================================
FILE: .github/CODE_OF_CONDUCT.md
================================================
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at trimstray@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
================================================
FILE: .github/CONTRIBUTING.md
================================================
# Contributing
> _A real community, however, exists only when its members interact in a meaningful way that deepens their understanding of each other and leads to learning._
If you would like to support this project, have an interesting idea how to improve the operation of this tool, or if you found some errors - fork this, add your fixes, and add a pull request of your branch to the **master branch**.
## Using the issue tracker
The [issue tracker](https://github.com/trimstray/the-practical-linux-hardening-guide/issues) is
the preferred channel for bug reports, features requests and submitting pull requests, but please respect the following restrictions:
* Please **do not** use the issue tracker for personal support requests (use
[Stack Overflow](https://stackoverflow.com) or IRC)
* Please **do not** derail or troll issues. Keep the discussion on topic and
respect the opinions of others
## Signature of commit
Moving forward all commits to this project must include a "signed-off-by" line indicating the name and email address of the contributor signing off on the change. To enable signatures add the following lines to `.git/hooks/prepare-commit-msg` :
```
SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/- signed-off-by: \1/p')
grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
```
## Pull requests
When creating a pull request, please heed the following:
- Base your code on the latest master branch to avoid manual merges
- Code review may ensue in order to help shape your proposal
- Explain the problem and your proposed solution
================================================
FILE: .github/FUNDING.yml
================================================
open_collective: trimstray
github: trimstray
================================================
FILE: LICENSE.md
================================================
MIT License
Copyright (c) 2017 trimstray
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
<h2 align="center"><code>The Practical Linux Hardening Guide</code></h2>
<br>
<p align="center">
<a href="https://github.com/trimstray/the-practical-linux-hardening-guide">
<img src="https://github.com/trimstray/the-practical-linux-hardening-guide/blob/master/static/img/main_preview.jpg" alt="Master">
</a>
</p>
<br>
<p align="center">"<i>Did you know all your doors were locked?</i>" - Riddick (The Chronicles of Riddick)</p>
<br>
<p align="center">
<a href="https://github.com/trimstray/the-practical-linux-hardening-guide/pulls">
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?longCache=true" alt="Pull Requests">
</a>
<a href="LICENSE.md">
<img src="https://img.shields.io/badge/License-MIT-lightgrey.svg?longCache=true" alt="MIT License">
</a>
</p>
<br>
****
# Table of Contents
- **[Introduction](#introduction)**
- [Prologue](#prologue)
- [The Importance of Hardening Linux](#the-importance-of-hardening-linux)
- [How to Harden Linux](#how-to-harden-linux)
- [Which Distribution Should be Used](#which-distribution-should-be-used)
- [How to Read This Guide](#how-to-read-this-guide)
- [Okay. Let's start, 3, 2, 1... STOP!](#okay-lets-start-3-2-1-stop)
- **[Policy Compliance](#policy-compliance)**
- [Center of Internet Security (CIS)](#center-of-internet-security-cis)
- [Security Technical Implementation Guide (STIG)](#security-technical-implementation-guide-stig)
- [National Institute of Standards and Technology (NIST)](#national-institute-of-standards-and-technology-nist)
- [Payment Card Industry Data Security Standard (PCI-DSS)](#payment-card-industry-data-security-standard-pci-dss)
- **[Security Content Automation Protocol (SCAP)](#security-content-automation-protocol-scap)**
- [SCAP Security Guide](#scap-security-guide)
- [OpenSCAP Base](#openscap-base)
- [SCAP Workbench](#scap-workbench)
- **[DevSec Hardening Framework](#devsec-hardening-framework)**
- **[Contributing & Support](#contributing--support)**
- **[License](#license)**
## Introduction
### Prologue
**[The Practical Linux Hardening Guide](https://trimstray.github.io/the-practical-linux-hardening-guide/)** provides a high-level overview of hardening GNU/Linux systems. It is not an official standard or handbook but it _touches_ and _uses_ industry standards.
This guide also provides you with _practical step-by-step instructions_ for building your own hardened systems and services. One of the main goals is to create a single document covering _internal_ and _external_ threats.
A few rules for this project:
- useful, simple, and not tiring
- include a lot of security tips from the C2S/CIS
- contains also non-related rules with C2S/CIS
- based on a minimal [RHEL7](https://www.redhat.com/en/technologies/linux-platforms/enterprise-linux) and [CentOS 7](https://www.centos.org/) installations
- it's not exhaustive about Linux hardening
- some hardening rules/descriptions can be done better
- you can think of it as a checklist
The Practical Linux Hardening Guide use following [OpenSCAP](https://www.open-scap.org/) configurations:
- [U.S. Government Commercial Cloud Services (C2S) baseline inspired by CIS v2.1.1](https://static.open-scap.org/ssg-guides/ssg-rhel7-guide-C2S.html)
> C2S for Red Hat Enterprise Linux 7 v0.1.43.
- [Red Hat Enterprise Linux 7 Security Technical Implementation Guide (STIG)](https://www.stigviewer.com/stig/red_hat_enterprise_linux_7/)
> The requirements are derived from the (NIST) 800-53 and related documents.
Please also remember:
> This guide contains my comments that may differ from certain industry principles. If you are not sure what to do please see **[Policy Compliance](#policy-compliance)**.
### The Importance of Hardening Linux
Simply speaking, hardening is the process of making a system more secure. Out of the box, Linux servers don’t come "hardened" (e.g. with the attack surface minimized). It’s up to you to prepare for each eventuality and set up systems to notify you of any suspicious activity in the future.
The process of hardening servers involves both IT ops. and security teams and require changes to the default configuration according to industry benchmarks.
Also for me, hardening is the fine art of doing the right things, even if they don't always look to have a big impact. It's always a balance between ease of use and protection.
You need to harden your system to protect your assets as much as possible. Why is it important? Please read a great, short article that [explains the hardening process](https://linux-audit.com/linux-server-hardening-most-important-steps-to-secure-systems/) step by step by [Michael Boelen](https://michaelboelen.com/).
### How to Harden Linux
In my opinion, you should drop all non-industry policies, articles, manuals, and others especially on production environments and standalone home servers. These lists exist to give a false sense of security and aren't based on authority standards.
<p align="center">
<a href="https://github.com/trimstray/the-practical-linux-hardening-guide">
<img src="https://github.com/trimstray/the-practical-linux-hardening-guide/blob/master/static/img/meme_01.png" alt="Master">
</a>
</p>
There are a lot of great GNU/Linux hardening policies available to provide safer operating systems compatible with security protocols. For me, CIS and the STIGs compliances are about the best prescriptive guides - but of course you can choose a different one (e.g. PCI-DSS, DISA).
> Most of all you should use [Security Benchmarks/Policies](#policy-compliance) which describe consensus best practices for the secure configuration of target systems.
Configuring your systems in compliance eliminates the most common vulnerabilities. For example, CIS has been shown to eliminate 80-95% of known vulnerabilities.
On the other hand, these standards are complicated checklists (often for newbies, difficult to implement). In my opinion, ideally, real world implementation is automated via something like OpenSCAP.
> You should use a rational approach because more is not better. Each environment is different, so even though security rules should all work in theory, sometimes things will not work as expected.
Hardening is not a simple process. Here are general rules following common best practices:
- never use root account for anything that does not require it
- only `sudo` individual commands
- never set a server to run as root (except for initialization time) and ensure that it exits all unnecessary privileges before accepting requests
- secure your firewall the best you can and forbid all unnecessary access
- do not install unnecessary or unstable software
### Which Distribution Should be Used
This guide is tested on **Red Hat Enterprise Linux 7** and **CentOS 7** distributions because these are:
- free (CentOS) and open source
- enterprise-class
- stable and reliable
- with great community support
- built on coherent snapshots of old packages
Both distributions allow the use of **[certified tools](#scap-security-guide)** which can parse and evaluate each component of the SCAP standard.
If you use another distribution - no problem, this guide is also for you.
### How to Read This Guide
Here is the structure of the chapters:
```
Chapter - e.g. Core Layer
|
|-- Subsection - e.g. Maintaining Software
| \
| |-- Rationale
| |-- Solution (+ policies)
| |-- Comments
| |-- Useful resources
|
|-- Subsection - e.g. Accounts and Access
| \
| |-- Rationale
| |-- Solution (+ policies)
| |-- Comments
| |-- Useful resources
```
Levels of understanding:
- _Chapter_ and _subsection_ offers a general overview
- _Rationale_ tells you the reasoning behind the changes
- _Solution_ and _policies_ are always compliant with the standard and on this basis, make changes
- _Comments_ helps you figure out what you can change or add to the _solution_
- _Useful resources_ provide deeper understanding
If you do not have the time to read hundreds of articles (just like me) this multipurpose handbook may be useful. This handbook does not get into all aspects of GNU/Linux hardening. I tried to put external resources in many places in this handbook in order to dispel any suspicion that may exist.
I did my best to make this guid a single and consistent (but now I know that is really hard). It's organized in an order that makes logical sense to me.
Do not treat this hardening guide as revealed knowledge. You should take a scientific approach when reading this document. If you have any doubts and disagree with me, please point out my mistakes. You should to discover cause and effect relationships by asking questions, carefully gathering and examining the evidence, and seeing if all the available information can be combined in to a logical answer.
I create this handbook for one more reason. Rather than starting from scratch in, I putting together a plan for answering your questions to help you find the best way to do things and ensure that you don't repeat my mistakes from the past.
So, what's most important:
- ask a questions about something that you observe
- do background research
- do tests with an experiments
- analyze and draw conclusions
- communicate results (for us!)
### Okay. Let's start, 3, 2, 1... STOP!
Making major changes to your systems can be risky.
The most important rule of system hardening that reasonable admins follow is:
> **`A production environment is the real instance of the app so make your changes on the dev/test!`**
The second most important rule is:
> **`Don’t do anything that will affect the availability of the service or your system.`**
The third rule is:
> **`Make backups of the entire virtual machine and important components.`**
And the last rule is:
> **`Think about what you actually do with your server.`**
## Policy Compliance
### Center of Internet Security (CIS)
The Center of Internet Security (CIS) is a nonprofit organization focused on improving public and private sector cybersecurity readiness and response.
Please see **[CIS Benchmarks](https://www.cisecurity.org/cis-benchmarks/)**.
### Security Technical Implementation Guide (STIG)
A Security Technical Implementation Guide (STIG) is a cybersecurity methodology for standardizing security protocols within networks, servers, computers, and logical designs to enhance overall security.
Please see **[Stigviewer](https://www.stigviewer.com/stigs)** to explore all stigs.
### National Institute of Standards and Technology (NIST)
The National Institute of Standards and Technology (NIST) is a physical sciences laboratory and a non-regulatory agency of the United States Department of Commerce.
Please see **[National Checklist Program (NCP)](https://nvd.nist.gov/ncp/repository)**.
### Payment Card Industry Data Security Standard (PCI-DSS)
Payment Card Industry Data Security Standard (PCI-DSS) compliance is a requirement for any business that stores, processes, or transmits cardholder data.
In accordance with PCI-DSS requirements, establish a formal policy and supporting procedures for developing configuration standards for system components that are consistent with industry-accepted hardening standards like:
- Center of Internet Security (CIS)
- International Organization for Standardization (ISO)
- SysAdmin, Audit, Network, and Security (SANS) Institute
- National Institute of Standards and Technology (NIST)
## Security Content Automation Protocol (SCAP)
Security Content Automation Protocol (SCAP) provides a mechanism to check configurations, vulnerability management and evaluate policy compliance for a variety of systems.
One of the most popular implementations of SCAP is OpenSCAP and it is very helpful for vulnerability assessment and as a hardening helper. OpenSCAP can easily handle the SCAP standards and generate neat, HTML-based reports.
Please see **[SCAP Security Policies](https://www.open-scap.org/security-policies/)**, **[OpenSCAP User Manual](https://static.open-scap.org/openscap-1.2/oscap_user_manual.html)**, and **[OpenSCAP Static](https://static.open-scap.org/)**.
### SCAP Security Guide
The auditing system settings with SCAP Security Guide project contains guidance for settings for Red Hat/CentOS and it's validated by NIST.
You should inspect the security content of your system with `oscap info` module:
```bash
# For RHEL:
oscap info /usr/share/xml/scap/ssg/content/ssg-rhel7-ds.xml
# For CentOS:
oscap info /usr/share/xml/scap/ssg/content/ssg-centos7-ds.xml
```
### OpenSCAP Base
The OpenSCAP scanner will only provide meaningful results if the content you want it to process is correct and up to date. The `oscap` tool scans your system, validates security compliance content, and generates reports and guides based on these scans.
Official [OpenSCAP Base](https://www.open-scap.org/tools/openscap-base/) documentation says:
> _The command-line tool, called `oscap`, offers a multi-purpose tool designed to format content into documents or scan the system based on this content. Whether you want to evaluate DISA STIGs, NIST‘s USGCB, or Red Hat’s Security Response Team’s content, all are supported by OpenSCAP._
Before use, please read **[Using OSCAP](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/security_guide/sect-using_oscap)** documentation.
```bash
# Installation:
yum install openscap-scanner
# Make a RHEL7 machine e.g. PCI-DSS compliant:
oscap xccdf eval --report report.html --profile xccdf_org.ssgproject.content_profile_pci-dss /usr/share/xml/scap/ssg/content/ssg-rhel7-ds.xml
# Make a CentOS machine e.g. PCI-DSS compliant:
oscap xccdf eval --report report.html --profile xccdf_org.ssgproject.content_profile_pci-dss /usr/share/xml/scap/ssg/content/ssg-centos7-ds.xml
```
### SCAP Workbench
SCAP Workbench is a utility that offers an easy way to perform common `oscap` tasks on local or remote systems.
Before use, please read **[Using SCAP Workbench](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/security_guide/sect-using_scap_workbench)** documentation.
```bash
# Installation:
yum install scap-security-guide scap-workbench
```
## DevSec Hardening Framework
> _Security + DevOps: Automatic Server Hardening._
This project covers some of the things in this guide which can be automated (e.g. setting of grub password or enforcing the permissions of the common directories). Its a good start if you want to make changes and see how it works from the level of automation tools.
Project: **[DevSec Hardening Framework](https://dev-sec.io)** and :octocat: GitHub repository: **[dev-sec](https://github.com/dev-sec/)**.
Thanks [@artem-sidorenko](https://github.com/artem-sidorenko)!
## Contributing & Support
If you find something which doesn't make sense, or something doesn't seem right, please make a pull request and please add valid and well-reasoned explanations about your changes or comments.
Before adding a pull request, please see the **[contributing guidelines](.github/CONTRIBUTING.md)**.
If this project is useful and important for you or if you really like _The Practical Linux Hardening Guide_, you can bring **positive energy** by giving some **good words** or **supporting this project**. Thank you!
## License
For license information, please see [LICENSE](https://github.com/trimstray/the-practical-linux-hardening-guide/blob/master/LICENSE.md).
---
<h4><p align="center">:beginner: To start please go to the <a href="https://github.com/trimstray/the-practical-linux-hardening-guide/wiki">Wiki</a>.</p></h4>
================================================
FILE: docs/_config.yml
================================================
theme: jekyll-theme-minimal
title: The Practical Linux Hardening Guide
logo: /assets/img/logo.png
================================================
FILE: docs/index.md
================================================
---
layout: default
---
## About Project
**[The Practical Linux Hardening Guide](https://github.com/trimstray/the-practical-linux-hardening-guide/wiki)** provides a high-level overview of hardening GNU/Linux systems. It is not an official standard or handbook but it _touches_ and _uses_ industry standards.
This guide also provides you with _practical step-by-step instructions_ for building your own hardened systems and services. One of the main goals is to create a single document covering _internal_ and _external_ threats.
The Practical Linux Hardening Guide use following [OpenSCAP](https://www.open-scap.org/) configurations:
- [U.S. Government Commercial Cloud Services (C2S) baseline inspired by CIS v2.1.1](https://static.open-scap.org/ssg-guides/ssg-rhel7-guide-C2S.html)
> C2S for Red Hat Enterprise Linux 7 v0.1.43.
- [Red Hat Enterprise Linux 7 Security Technical Implementation Guide (STIG)](https://www.stigviewer.com/stig/red_hat_enterprise_linux_7/)
> The requirements are derived from the (NIST) 800-53 and related documents.
## About Me
I'm a System and (tiny) Network Administrator. Also Security Enthusiast.
For the most part, I manage environments based on GNU/Linux and BSD systems.
The postings on this domain are my own and don't necessarily represent my employer’s positions, strategies or opinions.
## Contact
If you wish to contact me:
- hit me on [Twitter](https://twitter.com/trimstray), [Keybase](https://keybase.io/trimstray) or [Github](https://github.com/trimstray)
- via e-mail (base64): `dHJpbXN0cmF5QGdtYWlsLmNvbQo=`
================================================
FILE: lib/.gitkeep
================================================
gitextract_rt72ltgf/
├── .github/
│ ├── CODE_OF_CONDUCT.md
│ ├── CONTRIBUTING.md
│ └── FUNDING.yml
├── LICENSE.md
├── README.md
├── docs/
│ ├── _config.yml
│ └── index.md
└── lib/
└── .gitkeep
Condensed preview — 8 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (24K chars).
[
{
"path": ".github/CODE_OF_CONDUCT.md",
"chars": 3216,
"preview": "# Contributor Covenant Code of Conduct\n\n## Our Pledge\n\nIn the interest of fostering an open and welcoming environment, w"
},
{
"path": ".github/CONTRIBUTING.md",
"chars": 1570,
"preview": "# Contributing\n\n > _A real community, however, exists only when its members interact in a meaningful way that deepens t"
},
{
"path": ".github/FUNDING.yml",
"chars": 45,
"preview": "open_collective: trimstray\ngithub: trimstray\n"
},
{
"path": "LICENSE.md",
"chars": 1066,
"preview": "MIT License\n\nCopyright (c) 2017 trimstray\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\n"
},
{
"path": "README.md",
"chars": 15732,
"preview": "<h2 align=\"center\"><code>The Practical Linux Hardening Guide</code></h2>\n\n<br>\n\n<p align=\"center\">\n <a href=\"https://gi"
},
{
"path": "docs/_config.yml",
"chars": 100,
"preview": "theme: jekyll-theme-minimal\n\ntitle: The Practical Linux Hardening Guide\n\nlogo: /assets/img/logo.png\n"
},
{
"path": "docs/index.md",
"chars": 1576,
"preview": "---\nlayout: default\n---\n\n## About Project\n\n**[The Practical Linux Hardening Guide](https://github.com/trimstray/the-prac"
},
{
"path": "lib/.gitkeep",
"chars": 0,
"preview": ""
}
]
About this extraction
This page contains the full source code of the trimstray/the-practical-linux-hardening-guide GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 8 files (22.8 KB), approximately 5.5k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.