Security Hardening ubuntudebiancentos intermediate

SSH Hardening

Disable password login, allow key auth only

Overview

Disable password login, allow key auth only

Commands

This will disable SSH password login (key-only). Make sure your SSH key is set up! Continue?

sudo sed -i "s/^#\?PasswordAuthentication.*/PasswordAuthentication no/" /etc/ssh/sshd_config
sudo sed -i "s/^#\?PermitRootLogin.*/PermitRootLogin prohibit-password/" /etc/ssh/sshd_config
sudo systemctl restart sshd

Use Cases

Essential for production server security initialization.

Prerequisites

⚠️ SSH public key must be configured first, otherwise you will be unable to log in after execution!

  • Generate SSH Key Pair