Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm trying to use git from the terminal in my Ubuntu 12.04 desktop. My repository is hosted in Github, and I have the a key for my desktop. Whenever I do either "git pull" or "git push," a dialog box will pop up asking for my passphrase. This works fine if I type the passphrase correctly. However, if I'm connected to my desktop through ssh and do a git pull or push, the command does not prompt the passphrase and it outputs the following error:

Permission denied (publickey).
fatal: The remote end hung up unexpectedly

This error makes sense because I'm not inputting my passphrase. So the question is, how can I get the passphrase prompted in the terminal?

Thanks!

share|improve this question
add comment

2 Answers 2

I think I figured it out. After running ssh -vT git@github.com, I noticed how my key was not being included in the list of keys that were being tried for authentication:

debug1: Trying private key: /home/***/.ssh/id_rsa
debug1: Trying private key: /home/***/.ssh/id_dsa
debug1: Trying private key: /home/***/.ssh/id_ecdsa
debug1: No more authentication methods to try.

I figured that somehow I needed to tell ssh to use my specific key when connecting to github.com. I added a github entry in my ~/.ssh/config file

Host github.com
    IdentityFile ~/.ssh/id_github.pub

After doing that, the ssh command and the git push/pull commands ask for my passphrase in the terminal and connect successfully. I still don't know why when the command is run from the desktop, the dialog box for the correct key comes up. Does anybody know why this works?

Thanks!

share|improve this answer
add comment

If you want to push/pull to git on a machine that you're connected to via ssh, using the ssh version of the git protocol, you can do it one of two ways:

1) Do not forward the agent (ssh -A) when connecting to the machine, and ensure the key you want to use is on the host you're connecting to, and ssh is looking for it. You can do this with the IdentifyFile option for a Host in the ssh config file. Note you should point at the private key file, and not the public key file.

2) Forward the agent with ssh -A when connecting to the host you wish to use git on, and ensure the private key is available on the client machine you're connecting from, and that ssh can find it.

For slightly more security, you can use a different key from each machine, and add the public keys for the keys you're using for github, for each machine, to your github account. This way, if one key is compromised, you only need to replace it in one place, rather than trying to make sure you have the same keys everywhere.

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.