Essential Linux Hardening: Disable Root Login, Secure SSH, and Manage Permissions
This guide walks you through six key Linux hardening steps—including disabling root password login, enforcing key complexity and expiration, restricting sudo access, shutting down FTP, setting proper file ownership and permissions, and managing command history—to improve system security.
1. Disable root password login
Modify /etc/ssh/sshd_config and set PermitRootLogin to false.
2. Linux user key complexity and expiration
a. Password must contain three character types and be longer than 15 characters.
b. Set expiration for manually added user keys.
Use chage to view and set key expiration.
View expiration for user test: chage -l test Set expiration (days) for a user: chage -M number-of-days username The -M option defines the maximum number of days before the password expires.
3. Check sudo permissions
The sudo command elevates privileges. Its configuration file is /etc/sudoers. By default only root has sudo rights; to improve security, avoid adding other users to /etc/sudoers.
4. Disable FTP
Check FTP processes: ps -ef | grep ftp Terminate FTP process:
kill -9 pid5. Set file ownership and permissions
Change file owner: chown -R test:test /opt/test/ Set read/write/execute permissions:
chmod 400 /opt/test/6. Manage command history
Command history can be viewed with history. By default it records 1000 lines; the limit can be set in /etc/profile (e.g., to 20).
After securing settings, clear the history:
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.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
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.
