Operations 4 min read

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.

Raymond Ops
Raymond Ops
Raymond Ops
Essential Linux Hardening: Disable Root Login, Secure SSH, and Manage Permissions

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 pid

5. 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_history
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

linuxPermissionsSSHHardening
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.