Free tech learning for everyone, from basics to pro

Network FundamentalsNetworking SecurityIntermediate

SSH keys explained: generating keys, authorized_keys, agents and key-based login for network devices

In short: SSH keys replace passwords with a key pair. The public key is placed on servers and devices, and the private key stays on your computer, protected by a passphrase. Logging in proves you hold the private key without sending any secret. Keys are stronger than passwords, easy to automate, and can be revoked per person when managed properly.

Why keys instead of passwords

Passwords can be guessed, reused, phished or captured. With public key authentication, you create a pair of keys. The public key can be shared freely and is copied to every server you want to log in to. The private key never leaves your computer. When you connect, the server sends a challenge that only the holder of the private key can sign. Nothing secret crosses the network, and there is nothing for an attacker to guess.

Logging in with an SSH keyGenerate keypairssh-keygenCopy publickeytoauthorized_keysConnectserver sends achallengeSign withprivate keynever leavesyour PCAccessgrantedno passwordsent
Figure 1. The server only stores the public key. Proving you hold the private key is enough to log in.

Creating a key

ssh-keygen -t ed25519 -C "mohamed@laptop"
# saves ~/.ssh/id_ed25519 (private) and ~/.ssh/id_ed25519.pub (public)

Ed25519 is the modern default: short, fast and secure. Use RSA (3072 or 4096 bits) only for old systems that do not support it. Always set a passphrase when asked; it encrypts the private key file so a stolen laptop does not mean stolen access. Windows 10 and 11 include OpenSSH, so the same commands work in PowerShell.

Copying the public key to a Linux server

ssh-copy-id [email protected]
# or manually: append the .pub line to ~/.ssh/authorized_keys on the server
# permissions matter: ~/.ssh 700, authorized_keys 600

Once key login works, disable password logins on the server (PasswordAuthentication no in /etc/ssh/sshd_config) to stop password-guessing attacks entirely.

Keys on Cisco IOS devices

ip ssh pubkey-chain
 username admin
  key-string
   AAAAC3NzaC1lZDI1NTE5AAAAI...rest-of-key...
  exit

Supported key types depend on the IOS XE release (RSA is supported everywhere; newer releases add others). For teams, central authentication with TACACS+ is often easier to manage than keys on every device, and keys are typically used for automation accounts.

The SSH agent and config file

  • ssh-agent holds your unlocked key in memory, so you type the passphrase once per session: ssh-add ~/.ssh/id_ed25519.
  • The config file (~/.ssh/config) saves typing and handles jump hosts:
Host bastion
  HostName 203.0.113.30
  User mohamed
Host core1
  HostName 10.10.99.11
  User admin
  ProxyJump bastion

Now ssh core1 connects through the bastion automatically.

Managing keys in a team

  • One key per person (and per device), never shared keys.
  • Keep a record of which public keys are installed where, and remove them when people leave.
  • Larger environments use SSH certificates (signed by an internal CA with an expiry date) or a privileged access tool, so access expires automatically.
  • Never email or paste a private key; only the .pub file is shared.

Real-world example: thousands of failed logins a day

A company's internet-facing Linux server logged thousands of failed SSH password attempts every day from bots. The admins switched to Ed25519 keys with passphrases, disabled password login, and moved SSH behind the VPN. The failed attempts dropped to zero, and the risk of a weak password being guessed disappeared.

Practice

Which part of an SSH key pair is copied to servers?
The public key (the .pub file).
Why should you set a passphrase on a private key?
It encrypts the key file, so someone who steals it cannot use it without the passphrase.
Which SSH config option connects through a jump host automatically?
ProxyJump.

Key takeaways

  • SSH keys prove identity without sending a password.
  • Create Ed25519 keys with ssh-keygen and protect them with a passphrase.
  • Copy the public key to authorized_keys, then disable password login.
  • Use the agent and config file, one key per person, and remove keys for leavers.
Tracks your learning on this device only. See your progress on the learning paths.
Verified author✓ Valid
Issued to
Mohamed Fayas
Role
Founder of FM TecHub
Credentials
CCNABTEC HND Network EngineeringBEng (Hons) Computer Networking & Cloud Security
Issuer
FM TecHub · fmtechub.com

He writes practical, plain-English guides on networking, security and cloud.

More about the author →

Original content written by Mohamed Fayas for FM TecHub. © 2026 FM TecHub. You're welcome to share a link to this page; please don't copy the text elsewhere without permission.

Email updates: coming soon

New notes, tools and security news from FM TecHub by email, explained simply. Free. We're not collecting email addresses yet; see our privacy policy.

PortServiceStatus
SMTP/25Email updatesopening soon

Meanwhile, stay connected: