Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have my github.com private ssh key in an ssh-agent on a key server. From my home computer behind NAT I want to run git pull and use my github ssh key.

The only way I know of doing this is to ssh into the key server and forward port 22, then ssh back into my home computer while forwarding the agent, then run git pull in that new shell like so:

home$ ssh keyserver -R10022:localhost:22
keyserver$ ssh -A localhost -p10022
home$ git pull

Is there a simpler way to use the remote ssh key?

share|improve this question
add comment

1 Answer

I have used two different approaches in scenarios similar to yours.

  1. Start an agent locally
  2. Forward it to the server
  3. Use ssh-add to add the key from the server to your local agent (optinally with a limited lifetime)
  4. Log out from the server
  5. Use the key from the local agent as many times as you wish

Or

  1. Start an agent locally
  2. ssh server cat keyfile | ssh-add /dev/stdin

If the server is configured in a way that will not let your key get off the server ever, neither of the above approaches will work. In that case there isn't any solution, which is simpler than your own approach. But there are alternatives, which may provide better user-experience and/or security.

This command would open the same pair of ssh connections you used in your own example. But then return to the initiating shell where you can make use of the forwarded agent.

export $(grep -m1 ^SSH_AUTH_SOCK= <(
ssh -n -R10022:localhost:22 keyserver ssh -A localhost -p10022 "'env ; sleep 99999'"))
share|improve this answer
    
I really like both of your approaches. Too bad ssh -A keyserver ssh-add shows my key's password in plain text. I was hoping your first approach could be simplified. –  Collin Anderson Mar 30 at 3:27
1  
To get the password not to display on the screen, you need to add the -t flag to that command like ssh -At keyserver ssh-add –  kasperd Mar 30 at 6:07
    
awesome. thanks so much. i'll leave the answer unaccepted a little bit longer to see if there are any more ideas out there. –  Collin Anderson Mar 31 at 0:41
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.