0Pricing
Linux Server Deployment & SSH Mastery · Lesson

SSH Agent and Multi-hop

Utilize the SSH agent for seamless key management and configure multi-hop SSH connections to access deeply nested networks.

SSH Agent and Multi-hop is a free Linux Server Deployment & SSH Mastery lesson on CoddyKit — lesson 3 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 Linux Server Deployment & SSH Mastery learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

SSH Agent: Key to Convenience

Tired of typing your SSH key passphrase every time you connect to a server? The SSH agent is here to help!

  • It's a background program that securely stores your private keys.
  • You unlock your keys with their passphrase just once per session.
  • This means you can connect to multiple servers without re-entering your passphrase, boosting both convenience and security.

Starting Your SSH Agent

Before adding keys, you need to start the SSH agent. It usually runs as a background process.

You can start it and set up your shell to use it with this command:

eval "$(ssh-agent -s)"

Adding Keys to the Agent

Once the agent is running, you can add your private keys to it. The ssh-add command does this:

  • It will prompt you for your key's passphrase.
  • Your key will remain loaded until the agent stops or you explicitly remove it.

To see which keys are loaded, use ssh-add -l.

ssh-add ~/.ssh/id_rsa
ssh-add -l

Agent Forwarding: The Concept

Sometimes, you need to connect from one server (Server A) to another server (Server B) using your local SSH key, without storing the key on Server A.

Agent forwarding allows your local SSH agent to handle authentication for connections originating from a remote server. It's like temporarily extending your local agent to the remote host.

Using Agent Forwarding

To enable agent forwarding, simply add the -A flag when connecting to your first server (the jump host).

Then, from the jump host, you can connect to another server using your local keys, without ever storing them on the jump host. This is a powerful security feature!

ssh -A user@jump_host
# Now, from jump_host, connect to target_server
ssh user@target_server

Multi-hop SSH: Accessing Deep Networks

What if your target server isn't directly accessible from your local machine, but only through an intermediary server (a 'jump host')?

Multi-hop SSH, also known as SSH chaining, allows you to establish a connection through one or more intermediate servers to reach your final destination.

Multi-hop with ProxyJump

The easiest and most recommended way to set up multi-hop SSH is using the ProxyJump directive in your ~/.ssh/config file.

This tells your SSH client to first connect to the JumpHost, and then from there, establish a connection to the TargetServer.

Host TargetServer
  HostName 192.168.1.100
  User myuser
  ProxyJump jump_host_user@jump.example.com

Multi-hop with ProxyCommand

For older SSH clients or more complex scenarios, ProxyCommand offers greater flexibility. It executes a command to establish a connection to the target server.

The ssh -W %h:%p part tells SSH to forward standard input/output to the target host and port.

Host TargetServer
  HostName 192.168.1.100
  User myuser
  ProxyCommand ssh jump_host_user@jump.example.com -W %h:%p

Combining Agent Forwarding and Multi-hop

You can combine these powerful features! Use agent forwarding with your multi-hop setup to avoid re-entering passphrases.

Simply add ForwardAgent yes to your jump host configuration in ~/.ssh/config, or use ssh -A to the jump host. This allows your local agent to authenticate you on the final target server too.

Host JumpHost
  HostName jump.example.com
  User jump_user
  ForwardAgent yes

Host TargetServer
  HostName 192.168.1.100
  User target_user
  ProxyJump JumpHost

Quick Check: SSH Features

Consider the following statements about SSH Agent and Multi-hop SSH. Which ones are TRUE?

Recap: Seamless & Secure Access

In this lesson, you mastered two advanced SSH techniques:

  • SSH Agent: Stores your unlocked keys, eliminating repeated passphrase entries for convenience and security.
  • Agent Forwarding: Securely extends your local agent's power to remote servers, allowing you to authenticate from a jump host using your local keys.
  • Multi-hop SSH: Enables access to deeply nested networks via intermediate jump hosts, configured easily with ProxyJump or ProxyCommand.

These tools are essential for managing complex server infrastructures efficiently and securely.

Frequently asked questions

Is the “SSH Agent and Multi-hop” lesson free?

Yes — the full text of “SSH Agent and Multi-hop” is free to read here on the web, and the Linux Server Deployment & SSH Mastery 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 Linux Server Deployment & SSH Mastery course, upgrade to CoddyKit PRO.

What will I learn in “SSH Agent and Multi-hop”?

Utilize the SSH agent for seamless key management and configure multi-hop SSH connections to access deeply nested networks. You practise Linux Server Deployment & SSH Mastery 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 Linux Server Deployment & SSH Mastery?

No prior experience is required. Linux Server Deployment & SSH Mastery on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “SSH Agent and Multi-hop” 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 Linux Server Deployment & SSH Mastery lesson?

Yes. Every Linux Server Deployment & SSH Mastery 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 Port Forwarding (Local/Remote)
  2. SSH Tunnels and SOCKS Proxy
  3. SSH Agent and Multi-hop
  4. Secure File Transfer with SCP, SFTP, and rsync
← Back to Linux Server Deployment & SSH Mastery