Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

up vote 14 down vote accepted

Yes.

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!

share|improve this answer
    
I added some more detail on configuring SSH as a second answer. –  penguin359 Apr 28 '11 at 10:54
add comment

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.

share|improve this answer
add comment

You could also do it differently though by using port forwards.

hostA> ssh hostB -L 8022:hostC:22
hostA> ssh localhost -p 8022
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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