Essential Linux Hardening: Disable Root Login, Enforce Password Policies, and Secure Services
This guide walks through six practical Linux hardening steps—including disabling root password login, enforcing complex password rules with expiration, restricting sudo access, shutting down FTP, setting file ownership and permissions, and managing command history—to improve system security.
Link: https://www.cnblogs.com/zjdxr-up/p/16704040.html
1. Disable root password login
Edit /etc/ssh/sshd_config and set PermitRootLogin to false to prevent root from logging in via password.
2. Enforce Linux password complexity and expiration
Requirements:
Passwords must contain at least three character classes and be longer than 15 characters.
Set expiration for manually added user passwords using chage.
View a user’s password aging information: chage -l test Set password expiration (in days) for a user:
chage -M number-of-days username3. Verify sudo permissions
The sudo mechanism is configured via /etc/sudoers. By default only the root account has sudo rights. To maintain security, avoid adding other users to the sudoers file unless absolutely necessary.
4. Disable FTP service
Check for running FTP processes: ps -ef | grep ftp Terminate the FTP process (replace pid with the actual process ID):
kill -9 pid5. Set file ownership and permissions
Assign ownership recursively: chown -R test:test /opt/test/ Set read/write/execute permissions (example: read‑only for owner):
chmod 400 /opt/test/6. Manage command history
Linux records command history via the history command. By default it stores up to 1000 lines; the limit can be adjusted in /etc/profile (e.g., set to 20).
After completing security configurations, clear the history to remove traces of the commands used:
echo > $HOME/.bash_historySigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
