0Pricing
Cryptology Academy · Lesson

Public Key Authentication and Agent Forwarding

Understand authorized_keys, Ed25519 vs RSA keys, and the security implications of SSH agent forwarding.

Public Key Authentication and Agent Forwarding is a free Cryptology Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cryptology Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

authorized_keys File Format

SSH public key authentication relies on the authorized_keys file, typically located at ~/.ssh/authorized_keys on the server. Each line contains a public key in the format: algorithm base64-key comment. The server checks whether the client can prove possession of the matching private key by signing a challenge.

Generating SSH Keys with ssh-keygen

The ssh-keygen command creates key pairs for authentication. Running ssh-keygen -t ed25519 generates a modern Ed25519 key pair. You can specify a comment with -C for identification, such as your email. The tool saves the private key (id_ed25519) and public key (id_ed25519.pub) in ~/.ssh by default.

Comparing Key Types: RSA, ECDSA, Ed25519

RSA 4096-bit keys are highly compatible with legacy systems but slower to sign. ECDSA on NIST P-256 is faster and produces smaller signatures, but some cryptographers question NIST curve parameter selection. Ed25519 based on Curve25519 is the current best practice: fast, small keys and signatures, no known weaknesses, and available in all modern SSH implementations.

Passphrase-Protected Private Keys

The private key file should be protected with a passphrase. ssh-keygen encrypts the private key using a passphrase-derived key (bcrypt for modern keys), so an attacker who steals the file cannot use it without the passphrase. Without a passphrase, anyone with access to the file can authenticate as you to any server holding the matching public key.

ssh-agent for Key Management

The ssh-agent daemon holds decrypted private keys in memory during a login session. You load a key with ssh-add ~/.ssh/id_ed25519, which prompts for the passphrase once. Subsequent SSH connections ask the agent to sign challenges without re-entering the passphrase, combining security with convenience.

How ssh-agent Signs Challenges

When an SSH server sends an authentication challenge, the SSH client delegates signing to ssh-agent via a Unix socket. The agent performs the cryptographic signing using the private key stored in memory and returns only the signature. The private key bytes never leave the agent process, not even to the SSH client itself.

Agent Forwarding: Capability and Risk

Agent forwarding (ForwardAgent yes or ssh -A) allows a remote SSH session to use your local agent for onward authentication. This is useful for hopping through bastion hosts without copying private keys to the bastion. However, if the bastion is compromised, a root user there can access your agent socket and authenticate as you to any server.

ProxyJump vs ForwardAgent for Bastions

ProxyJump (ssh -J bastion target) is the safer alternative to ForwardAgent for bastion host access. It creates a TCP tunnel through the bastion without exposing your agent socket there. The target server receives a direct connection from your local client, and the bastion only forwards encrypted TCP bytes without any ability to use your credentials.

SSH Certificate Authentication

SSH supports certificate-based authentication where a Certificate Authority (CA) signs host and user public keys. Instead of distributing individual public keys to every server, you configure servers to trust your CA. A signed user certificate grants access to all servers trusting that CA, with optional expiry and principal restrictions embedded in the certificate.

ssh-keyscan for Bulk Key Collection

The ssh-keyscan tool connects to one or more hosts and retrieves their public host keys without authentication. This is useful for automating the population of known_hosts files in deployment scripts. Output can be piped directly into a known_hosts file: ssh-keyscan -H example.com >> ~/.ssh/known_hosts.

Key Authentication Flow Summary

Public key authentication: client sends public key, server checks authorized_keys, server sends a challenge signed with the session ID, client (via agent) signs it with the private key, server verifies the signature using the stored public key. If valid, authentication succeeds without transmitting any secret credential.

SSH Key Type Selection

Which SSH key type is the current best practice for new deployments due to its speed, small key size, and strong security properties?

Public Key Auth Recap

Key takeaways: store public keys in authorized_keys, protect private keys with passphrases, use ssh-agent to hold decrypted keys in memory, prefer Ed25519 key type, use ProxyJump instead of ForwardAgent for bastion access to avoid exposing the agent socket, and consider SSH certificates for scalable access management.

Frequently asked questions

Is the “Public Key Authentication and Agent Forwarding” lesson free?

Yes — the full text of “Public Key Authentication and Agent Forwarding” is free to read here on the web, and the Cryptology Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cryptology Academy course, upgrade to CoddyKit PRO.

What will I learn in “Public Key Authentication and Agent Forwarding”?

Understand authorized_keys, Ed25519 vs RSA keys, and the security implications of SSH agent forwarding. You practise Cryptology Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Cryptology Academy?

No prior experience is required. Cryptology Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Public Key Authentication and Agent Forwarding” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Cryptology Academy lesson?

Yes. Every Cryptology Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. SSH Handshake and Host Key Authentication
  2. Public Key Authentication and Agent Forwarding
  3. SSH Tunneling and Port Forwarding Techniques
  4. SSH Hardening and Audit Best Practices
← Back to Cryptology Academy