Skip to main content
⚡ OpenDevDocs
Linux
linuxlinuxGuideIntermediate

Linux SSH Configuration & Hardening

Generate Ed25519 SSH keypairs, configure ~/.ssh/config, manage authorized_keys, and harden sshd_config against unauthorized access.

Verified: 2026-09-30
Tested on:linux Ubuntu 24.04 / Debian 12
Platforms:
linuxmacos
#linux#ssh#security#devops#authentication

1. Generating Modern SSH Keypairs (Ed25519)

[!NOTE] Modern cryptographic standards recommend Ed25519 over legacy RSA keys because Ed25519 offers stronger security with faster signature computation and compact key lengths.

# Generate Ed25519 keypair with an email label
ssh-keygen -t ed25519 -C "admin@example.com" -f ~/.ssh/id_ed25519

This produces two files:

  • ~/.ssh/id_ed25519: Private Key (Never share, permissions 600).
  • ~/.ssh/id_ed25519.pub: Public Key (Copied to remote servers, permissions 644).

2. Copying Public Key to Remote Server

# Automated copy to remote server's ~/.ssh/authorized_keys
ssh-copy-id -i ~/.ssh/id_ed25519.pub deployer@192.0.2.10

3. Simplifying Connections with ~/.ssh/config

Configure aliases and key mappings so you can connect via ssh production:

# ~/.ssh/config
Host production
    HostName 192.0.2.10
    User deployer
    Port 22
    IdentityFile ~/.ssh/id_ed25519
    ServerAliveInterval 60

Connect:

ssh production

4. Server-Side SSH Hardening (/etc/ssh/sshd_config)

To protect your Linux server from automated brute-force attacks:

# /etc/ssh/sshd_config

# Disable root direct SSH login
PermitRootLogin no

# Disable insecure password authentication (Keys ONLY)
PasswordAuthentication no
PermitEmptyPasswords no

# Use modern cryptographic algorithms
PubkeyAuthentication yes

Test syntax and restart SSH daemon:

sudo sshd -t && sudo systemctl restart sshd

On this page