
Table of Contents
By Khimananda Oli | Last reviewed: August 2026
Password-based remote access is the single most common entry point for server compromises in 2026. A proper SSH Key Only Auth Setup eliminates brute-force risk entirely by replacing guessable secrets with cryptographic proof of identity. This guide walks you through generating modern Ed25519 keys, configuring sshd_config safely, and validating that password login is permanently disabled before you lock yourself out.
How do you generate secure SSH keys for SSH Key Only Auth Setup?
The foundation of any reliable Ubuntu security hardening strategy is strong cryptography at the transport layer. In 2026, Ed25519 is the default recommendation for new deployments. It offers fixed-size 256-bit keys, constant-time signing to prevent timing attacks, and broad compatibility across OpenSSH 6.5+, AWS EC2, Azure VMs, and GCP Compute Engine. RSA-4096 remains acceptable for legacy systems that lack Ed25519 support, but avoid DSA (deprecated) and ECDSA (implementation-dependent curve risks).
Generate an Ed25519 key pair with a strong passphrase
ssh-keygen -t ed25519 -C "khimananda@prod-bastion-2026" -f ~/.ssh/id_ed25519_prod - -t ed25519: Selects the Edwards-curve algorithm. Keys are always 256 bits regardless of output encoding.
- -C: Adds a comment embedded in the public key. Use a descriptive label including hostname, purpose, and year so you can identify keys during audits or rotation.
- -f: Specifies a non-default filename. Never reuse the same private key across environments. Separate keys per environment (dev, staging, prod) limits blast radius if one is compromised.
When prompted for a passphrase, use a minimum of 20 characters or a six-word diceware phrase. The passphrase encrypts the private key at rest using AES-256-CTR. If your laptop is stolen or your home directory is backed up insecurely, the passphrase is your last line of defense. Store passphrases in a dedicated secrets manager like Bitwarden or 1Password — never in plaintext files, shell history, or sticky notes.
Verify key fingerprint before distribution
ssh-keygen -lf ~/.ssh/id_ed25519_prod.pub
# Output example: 256 SHA256:AbCdEf...GhIjKl khimananda@prod-bastion-2026 (ED25519) Record this fingerprint in your team’s access registry or infrastructure documentation. When onboarding new engineers or rotating keys, compare fingerprints to confirm the correct public key was deployed. This prevents man-in-the-middle substitution attacks where an attacker swaps their own key during transfer.
How do you configure sshd_config for SSH Key Only Auth Setup?
The server-side configuration is where most failures occur. A single typo in /etc/ssh/sshd_config can lock you out permanently or leave password auth silently enabled. Always edit this file with a backup session open, or use a console/IMPI/IPMI fallback if working on bare metal.
Essential directives for key-only enforcement
# /etc/ssh/sshd_config — Production hardened for 2026
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM yes
PermitRootLogin prohibit-password
MaxAuthTries 3
ClientAliveInterval 300
ClientAliveCountMax 2
AllowUsers deployer admin sre-team
LogLevel VERBOSE Each directive serves a specific security function:
- PubkeyAuthentication yes: Explicitly enables public key verification. While often the default, declaring it prevents accidental override by included config fragments.
- PasswordAuthentication no: Disables interactive password prompts. This is the core of SSH Key Only Auth Setup. Without this line, attackers can still attempt brute force even when keys are configured.
- ChallengeResponseAuthentication no: Prevents keyboard-interactive methods that may fall back to PAM password modules. Some distributions enable this by default for 2FA; disable it unless you have a verified TOTP/PAM setup.
- PermitRootLogin prohibit-password: Allows root key login only when absolutely necessary (e.g., emergency recovery). Prefer disabling root entirely and using sudo via named accounts. Never set this to
yes. - AllowUsers: Whitelists permitted usernames. Rejects connections before authentication begins. Update this list whenever personnel change. For larger teams, use
AllowGroups ssh-usersinstead. - LogLevel VERBOSE: Logs key fingerprints on successful auth. Critical for forensic analysis and compliance audits (SOC 2, ISO 27001). Avoid DEBUG levels in production as they expose sensitive metadata.
Validate configuration syntax before restart
sudo sshd -t -f /etc/ssh/sshd_config
# Returns nothing on success; prints error location on failure Never skip this step. A missing newline, incorrect indentation in a Match block, or unsupported option will cause sshd to fail on restart. The -t flag performs a full parse without starting the daemon. Fix all errors before proceeding.
How do you safely deploy public keys without locking yourself out?
The transition period between enabling keys and disabling passwords is the highest-risk moment. Follow this exact sequence to maintain access throughout.
- Open two separate terminal sessions to the target server. Keep Session A active and untouched. Use Session B for all configuration changes. If something breaks, Session A remains authenticated under the old rules.
- Deploy the public key while password auth is still enabled. Use
ssh-copy-id -i ~/.ssh/id_ed25519_prod.pub user@serveror manually append to~/.ssh/authorized_keys. Verify permissions:chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys. Incorrect permissions cause silent key rejection. - Test key authentication in a third session. Run
ssh -i ~/.ssh/id_ed25519_prod -o BatchMode=yes user@server 'echo KEY_AUTH_OK'. TheBatchMode=yesflag ensures the command fails immediately if key auth doesn’t work, rather than prompting for a password. Confirm output shows KEY_AUTH_OK. - Apply sshd_config changes and validate syntax as shown above. Only proceed if
sshd -treturns clean. - Restart sshd and test again. Run
sudo systemctl restart sshd, then immediately test key auth in a new session. Do not close Session A until this succeeds. - Disable password auth only after confirmed key access. Edit
sshd_configto setPasswordAuthentication no, validate, restart, and test once more. Now attempt a password login from a different machine — it must be rejected instantly.
This disciplined approach mirrors the change management practices required for Ubuntu server security best practices and aligns with SOC 2 CC6.1 controls for logical access provisioning. Skipping the parallel-session safeguard is the #1 cause of self-inflicted outages during SSH hardening.
How does SSH Key Only Auth Setup compare to password and certificate auth?
Understanding the trade-offs helps you justify this control to stakeholders and choose the right model for your scale.
| Criteria | Password Auth | SSH Key Only Auth Setup | SSH Certificates (CA-signed) |
|---|---|---|---|
| Brute-force resistance | Vulnerable (rate-limited only) | Immune (no secret to guess) | Immune + short-lived credentials |
| Key rotation effort | N/A (password reset) | Manual per-host authorized_keys update | Centralized CA re-signing; auto-expiry |
| Audit trail granularity | Username only | Key fingerprint per login | Fingerprint + principal + validity window |
| Scalability (100+ hosts) | Poor (shared secrets leak) | Moderate (Ansible/Terraform managed) | Excellent (single trust anchor) |
| Setup complexity | Trivial | Low (this guide) | High (requires CA infrastructure) |
| Compliance acceptance | Fails PCI-DSS, SOC 2, ISO 27001 | Meets baseline requirements | Exceeds requirements; preferred for high-assurance |
For most teams managing fewer than 50 servers, SSH Key Only Auth Setup delivers the optimal balance of security and operational simplicity. Certificate-based auth becomes worthwhile when you manage hundreds of ephemeral instances or require automatic credential expiration. Password authentication should never appear in production environments after 2024.
What ongoing maintenance does SSH Key Only Auth Setup require?
Deploying keys is not a set-and-forget task. Sustainable security requires operational discipline around rotation, revocation, and monitoring.
Key rotation and revocation procedures
Rotate individual keys annually or immediately upon personnel departure. Remove departed users’ keys from every host within 24 hours. Automate this with Ansible, Terraform, or a GitOps tool like ArgoCD. For guidance on integrating this into broader infrastructure automation, see automating server setup with Ansible playbooks. Maintain a centralized inventory mapping keys to owners and purposes — this is mandatory evidence for ISO 27001 A.9.2.6 reviews.
Monitoring and alerting on authentication events
Configure log aggregation to capture sshd events at VERBOSE level. Alert on:
- Failed key authentications exceeding 5 attempts per minute (indicates misconfiguration or probing)
- Successful logins from unexpected key fingerprints (potential key compromise)
- Any password authentication attempt after disablement (config drift or rollback)
Integrate these signals into your existing observability stack. If you’re building out monitoring, the Prometheus and Grafana full monitoring stack provides native node_exporter metrics for SSH session counts and auth failure rates.
Defense in depth beyond sshd_config
SSH Key Only Auth Setup is necessary but insufficient alone. Layer additional controls:
- Fail2Ban or CrowdSec: Block IPs after repeated failed key attempts. Even though keys can’t be brute-forced, excessive failures indicate reconnaissance or misconfigured clients.
- Network segmentation: Restrict SSH port 22 to bastion hosts or VPN CIDRs via firewall rules. Never expose SSH directly to 0.0.0.0/0 on public clouds.
- SSH agent forwarding caution: Disable
ForwardAgent yesunless connecting through a trusted bastion. Agent forwarding exposes your private key to compromised intermediate hosts. - Regular config audits: Schedule quarterly reviews of
sshd_configagainst CIS Benchmarks. Drift happens during incident response or hurried deployments.
Implement SSH Key Only Auth Setup Today
Every day password authentication remains enabled is another day your servers are exposed to automated credential stuffing and targeted brute-force campaigns. The steps outlined here take under 30 minutes per host and deliver immediate, measurable security improvement. Start with your most critical production systems, validate thoroughly using the parallel-session method, and expand outward. If your team needs hands-on assistance implementing this across a multi-cloud fleet or preparing for a compliance audit, reach out to discuss your infrastructure security posture.