Overview
The configurations in this section are considered dangerous for various reasons:- They can lock you out of your system if misconfigured
- They may break critical system functionality
- They require deep system knowledge to troubleshoot
- Recovery from mistakes can be difficult or impossible without physical access
- Fully understand what each configuration does
- Have tested in a non-production environment
- Have a recovery plan (physical access, backup system, etc.)
- Can afford downtime if something goes wrong
Covered Topics
This section includes:Kernel sysctl Hardening
Advanced kernel parameter tuning for security
Password Protect GRUB
Prevent unauthorized boot modifications
Disable Root Login
Lock the root account completely
Change Default umask
Modify default file permissions
Password Protect GRUB
Why
If a bad actor has physical access to your server, they could use GRUB to gain unauthorized access to your system.Why Not
If you forget the password, you’ll have to go through password recovery procedures, which can be complex and time-consuming.Configuration Steps
1. Create a Password Hash
Create a PBKDF2 hash of your password:2. Create GRUB Password File
Copy everything afterPBKDF2 hash of your password is, starting from and including grub.pbkdf2.sha512...
Create the file /etc/grub.d/01_password:
3. Make the File Executable
4. Backup GRUB Configuration
5. Allow Unrestricted Boot for Default Entry
Modify/etc/grub.d/10_linux to allow the default Debian install to boot without a password while keeping everything else restricted:
6. Update GRUB
This configuration auto-boots the default OS without a password but requires a password to access GRUB menu options or boot alternate entries.
Disable Root Login
Why
If you have sudo configured properly, then the root account will mostly never need to log in directly.Why Not
You may encounter this error during boot failures:Alternatives
- Use
--forceoption for sulogin: Some distributions already include this workaround - Set a complex root password: Store it in a secured, non-digital format for emergency use
Some distributions (e.g., Ubuntu) disable root login by default, so you may not need this step.
How to Disable Root Login
How to Re-enable Root (if needed)
Change Default umask
Why
umask controls the default permissions of files and folders when they are created. Insecure default permissions give other accounts potentially unauthorized access to your data. Security goals:- For non-root accounts: No need for other accounts to have any access by default
- For root account: No need for the primary group or other accounts to have any access by default
Why Not
Understanding umask
umask works by subtracting permissions from the default:- Default file permissions:
0666(rw-rw-rw-) - Default directory permissions:
0777(rwxrwxrwx)
| umask | Files Created | Directories Created | Description |
|---|---|---|---|
0022 | 644 (rw-r—r—) | 755 (rwxr-xr-x) | Default on most systems |
0027 | 640 (rw-r-----) | 750 (rwxr-x---) | Recommended for non-root |
0077 | 600 (rw-------) | 700 (rwx------) | Recommended for root |
Recommended Configuration
For Non-Root Users
Add to/etc/profile or ~/.bashrc:
For Root User
Add to/root/.bashrc:
Testing umask Changes
After changing umask, test file creation:Existing files are not affected by umask changes. Only newly created files will use the new default permissions.
Orphaned Software
Why Remove Orphaned Packages
Orphaned packages are installed but no longer required by any other packages. They:- Consume disk space
- May contain security vulnerabilities
- Clutter your system
- Can cause conflicts
Finding Orphaned Packages
Debian/Ubuntu
Using deborphan
Configuration File Cleanup
Remove configuration files from removed packages:Recovery Procedures
If You Lock Yourself Out
- Boot into recovery mode (hold Shift during boot to access GRUB)
- Use a live USB/CD to chroot into your system
- Contact your hosting provider if on a VPS/cloud server for console access
If Root is Locked and Needed
- Boot into single-user mode
- Unlock root account:
passwd -u root - Fix the issue
- Re-lock root account:
passwd -l root
If GRUB Password is Lost
- Boot from live media
- Mount your root partition
- Remove or edit
/etc/grub.d/01_password - Regenerate GRUB config:
update-grub - Create a new password following the steps above
Best Practices
Test First
Always test dangerous configurations in a non-production environment
Document Everything
Keep detailed notes of all changes and passwords (securely)
Have a Recovery Plan
Ensure you have alternative access methods before locking down
Take Backups
Backup critical files and configurations before making changes
Additional Resources
Remember: Security is about finding the right balance between protection and usability. Don’t implement security measures you don’t understand or can’t support.