Repository navigation
SSH Keys Authentication
Comprehensive guide to SSH key management and secure authentication.
SSH keys provide password-less, encrypted authentication to servers.
Advantages:
- 🔒 More secure than passwords
- ⚡ Faster login
- 🤖 Enables automation (no interactive password)
- 🛡️ Resistant to brute-force attacks
- 💪 Support for strong algorithms (Ed25519)
Disadvantages of passwords:
- Weak passwords can be guessed
- Traffic can be sniffed
- Reuse across systems increases risk
- Takes time to type
SSH uses public/private key pairs:
-
Private Key (kept secret, on your machine)
- Never share this
- Guards like a password
- Stored in
~/.ssh/id_ed25519(orid_rsa)
-
Public Key (shared freely, on servers)
- Added to server's
~/.ssh/authorized_keys - Proves you own the private key
- Cannot be reverse-engineered
- Added to server's
Authentication Flow:
Your Machine Server
┌──────────────┐ ┌──────────────┐
│ Private Key │ │ Public Key │
│ (id_ed25519) │ │ (authorized_ │
│ │ ──encodes──> │ keys) │
│ │ │ │
│ │ <──verifies─ │ │
└──────────────┘ └──────────────┘
✅ Access Granted
Pros:
- ✅ Shorter keys (256-bit)
- ✅ Faster signing
- ✅ Modern, resistant to attacks
- ✅ Better security margins
Cons:
- ❌ Older systems may not support (unlikely in 2024+)
Generate:
ssh-keygen -t ed25519 -C "user@domain.com"Pros:
- ✅ Widely supported
- ✅ Compatible with old systems
- ✅ Standard for years
Cons:
- ❌ Requires longer keys (4096-bit minimum)
- ❌ Slower signing
- ❌ Small risk of future weakness
Generate:
ssh-keygen -t rsa -b 4096 -C "user@domain.com"Recommendation: Use Ed25519 for all new keys.
Open the SSH KEYS panel in the sidebar:
SSH KEYS
├── web-key (Ed25519)
│ Fingerprint: SHA256:abc123...
│ ✓ Added on Mar 01, 2024
│
├── backup-key (RSA)
│ Fingerprint: SHA256:def456...
│ ✓ Added on Feb 15, 2024
│
└── my-macbook (Ed25519)
Fingerprint: SHA256:ghi789...
✓ Added on Jan 10, 2024
Each Key Shows:
- 🔑 Key name
- 📊 Key type (Ed25519 or RSA)
- 🔗 Fingerprint (short identifier)
- 📅 Date added
- Generate a key locally (see Generating Keys below)
- In extension's SSH KEYS panel, click +
- A file picker opens to
~/.ssh/ - Select your
.pubfile (public key) - Key uploaded to Hetzner Cloud
- Appears in SSH KEYS panel within seconds
Important: Upload the .pub file, NOT the private key!
- Right-click key in SSH KEYS panel
- Choose Delete SSH Key
- Confirm the action
- Key removed from Hetzner Cloud
After deletion:
- Existing servers keep access (key already authorized)
- New servers cannot use this key
- Existing servers cannot add this key back (must supply new key)
-
In the SETUP panel, click Generate SSH Key
-
SSH Key Generation Guide opens with tabs for your OS:
- 🪟 Windows
- 🍎 macOS
- 🐧 Linux
-
Follow step-by-step instructions
-
At the end, add the public key to Hetzner
# Open PowerShell as Administrator
# Generate Ed25519 key
ssh-keygen -t ed25519 -C "you@example.com"
# When prompted, press Enter for default location (~/.ssh/id_ed25519)
# Enter a strong passphrase (or leave empty for no passphrase)Result:
-
~/.ssh/id_ed25519(private key) -
~/.ssh/id_ed25519.pub(public key)
- Download & install PuTTY
- Open PuTTYgen (comes with PuTTY)
- Select Ed25519 under Key Type
- Click Generate and move mouse for entropy
- Enter a passphrase (recommended)
- Click Save Private Key → save as
.ppk - Copy Public Key text (top box)
- Paste into Hetzner Cloud → save file as
id_ed25519.pub
# Install WSL2 with Ubuntu
# Generate key
ssh-keygen -t ed25519 -C "you@example.com"
# Key stored in /home/<username>/.ssh/id_ed25519# Open Terminal
# Generate Ed25519 key
ssh-keygen -t ed25519 -C "you@example.com"
# When prompted:
# Location: Press Enter (uses ~/.ssh/id_ed25519)
# Passphrase: Enter a strong passphrase
# Verify key creation
cat ~/.ssh/id_ed25519.pub
# (Optional) Add key to macOS Keychain
ssh-add --apple-use-keychain ~/.ssh/id_ed25519# Open Terminal
# Generate Ed25519 key
ssh-keygen -t ed25519 -C "you@example.com"
# When prompted:
# Location: Press Enter (uses ~/.ssh/id_ed25519)
# Passphrase: Enter a strong passphrase
# Verify permissions
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519
chmod 644 ~/.ssh/id_ed25519.pub
# Verify key
ssh-keygen -l -f ~/.ssh/id_ed25519.pubOnce a server is created with your SSH key:
# Default: SSH as root
ssh root@<server-public-ip>
# Example
ssh root@192.0.2.123
# If you set a non-standard port
ssh -p 2222 root@192.0.2.123If SSH is configured on your machine:
- In SERVERS panel, right-click server
- Choose Open SSH Terminal (if available)
- Terminal opens with active SSH connection
- You're logged in as root
Create ~/.ssh/config for easier connections:
Host hcloud-web-01
HostName 192.0.2.123
User root
IdentityFile ~/.ssh/id_ed25519
AddKeysToAgent yes
IdentitiesOnly yes
Host hcloud-*
StrictHostKeyChecking accept-new
UserKnownHostsFile ~/.ssh/known_hosts
Then connect simply:
ssh hcloud-web-01✅ Good: MyDog#Likes9BlueBerries!
❌ Bad: password, 123456, qwerty
A passphrase protects your private key if someone steals the file.
- Keep private keys on your machine only
- Don't email or Slack private keys
- Don't commit to GitHub
- Don't put in config files
Store passphrase temporarily so you don't type it repeatedly:
# Start SSH agent (usually automatic on macOS/Linux)
eval "$(ssh-agent -s)"
# Add key with passphrase
ssh-add ~/.ssh/id_ed25519
# (Enter passphrase once)
# Now SSH works without typing passphrase
ssh root@server.com- Delete old keys from Hetzner after replacing them
- Keep private keys for 1-3 years max
- After leaving a company, revoke all keys
✅ Good: laptop-ed25519, desktop-ed25519, ci-server-ed25519
❌ Bad: Single key on all machines
If one key is compromised, revoke only that key.
After adding SSH keys, disable password authentication:
# SSH to server
ssh root@server.com
# Edit SSH config
sudo nano /etc/ssh/sshd_config
# Find and change these lines:
# PasswordAuthentication no
# PubkeyAuthentication yes
# PermitRootLogin prohibit-password
# Restart SSH daemon
sudo systemctl restart sshCause: Public key not in authorized_keys on server
Solution:
- Use root password (if created without SSH key) to login:
ssh root@server.com # (Enter password from server detail panel) - Manually add your key:
cat >> ~/.ssh/authorized_keys << EOF ssh-ed25519 AAAA... you@example.com EOF
- Verify permissions:
chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys
Cause: SSH agent not running
Solution:
# Start SSH agent
eval "$(ssh-agent -s)"
# Add your key
ssh-add ~/.ssh/id_ed25519Cause: Server not in known_hosts
Solution:
# Accept the key
ssh-keyscan -t ed25519 <server-ip> >> ~/.ssh/known_hosts
# Or accept interactively
ssh root@server.com
# (Type "yes" when prompted)Cause: Different key being used or key compromised
Solution:
- Verify fingerprint from Hetzner Cloud console
- Ensure correct key in
~/.ssh/ - Check
ssh -vfor debugging:ssh -vvv root@server.com
Allow scripts to run commands with sudo without password:
# SSH to server
ssh root@server.com
# Edit sudoers (safely)
sudo visudo
# Add this line:
# app ALL=(ALL) NOPASSWD: /usr/bin/systemctl
# Now run without password
/usr/bin/systemctl restart nginx# Copy file to server
scp /local/file root@server.com:/remote/path/
# Copy from server
scp root@server.com:/remote/file /local/path/
# Recursive copy
scp -r /local/dir root@server.com:/remote/#!/bin/bash
# Deploy script
SERVER="web-01.example.com"
# Copy app
scp -r ./app root@$SERVER:/opt/
# Run commands
ssh root@$SERVER << 'EOF'
cd /opt/app
npm install
npm run build
systemctl restart app
EOF
echo "Deployment complete"Next: Explore the Features Guide 👉