I want to ssh from A to B, using a particular private key that I have in A. Then I want to ssh from B to C using the same credentials that I used to ssh into B.

Is it possible to "pass" the credentials from a ssh session to another ssh session started inside the first session?



What you are looking for is known as ssh-agent forwarding. Once you learn to use ssh-agent to load up your unlocked keys and make them available to the ssh-client, it is possible for the clients to pass this data down the chain of connections so that future ssh clients can talk to the original agent.

Among other things, you will need to setup ForwardAgent yes in your ssh configs for the various machines that should be allowed these privaleges. You should be aware that this introduces several new layers of security issues. You are playing with fire. Don't say we didn't warn you!

  • I added some more detail on configuring SSH as a second answer. – penguin359 Apr 28 '11 at 10:54

This answer is in addition to what Caleb wrote. You should be careful enabling SSH Agent forwarding to untrusted hosts. What I do is list specific hosts in my ~/.ssh/config file as such:

ForwardX11 yes

Host trusted-server
    ForwardAgent yes
    Compression yes

Host trusted-desktop
    ForwardAgent yes
    ForwardX11Trusted yes

This enables X11 forwarding for everyone, but OpenSSH filters out SECURITY commands. Compression is enabled to the server, Trusted X11 (without filtering) is enabled to the desktop and SSH Agent is enabled when connecting to either.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.