ccontavalli / ssh-ident

Different agents and different keys for different projects, with ssh.
Other
963 stars 71 forks source link

git doesn't seem to work without ssh first #29

Closed dracos closed 7 years ago

dracos commented 8 years ago

If in a new session I try and git pull, then I am not asked for my passphrase, the key isn't loaded and I can't log in. If I SSH first and then use git pull, it is fine, see transcript below. I have ssh-ident as a symlink from ssh in my bin directory, which the readme says: "This works for rsync and git". This is on a Mac 10.10.5, with git 2.8 from MacPorts. Let me know if you need any more information.

$ git pull
Loading keys:
    /Users/matthew/.ssh/identities/work/id_rsa
ssh_askpass: exec(/usr/libexec/ssh-askpass): No such file or directory
Password: [Ctrl-C]
$ ssh work.machine
Loading keys:
    /Users/matthew/.ssh/identities/work/id_rsa
Enter passphrase for /Users/matthew/.ssh/identities/work/id_rsa: 
Identity added: /Users/matthew/.ssh/identities/work/id_rsa (/Users/matthew/.ssh/identities/work/id_rsa)
[ Successfully logged in to work.machine ]
work.machine:~$ logout
Connection to work.machine closed.
$ git pull
All keys already loaded
Already up-to-date.
$ 
ccontavalli commented 8 years ago

This is weird, could you check where ssh-askpass is installed on your system? Is it possible that you have two ssh versions installed? or that git or your .bashrc set environment variables to change the behavior of ssh? or that different configs are used for the ssh command vs git?

So, ... ssh-ident calls ssh-add to load keys. In turn, ssh-add invokes ssh-askpass to ask you for a passphrase. It does the same thing whatever ssh-ident is invoked from shell directly, or via git.

From the error message above, it seems like that when git invokes ssh-ident, it looks for ssh-askpass in /usr/libexec/ssh-askpass, which cannot be run. While when you run ssh from your console, well, it decides that ssh-askpass is not necessary?? so prompts you directly on the console.

Could you post the following?

By googling randomly about git and ssh-askpass, it seems like git has a default parameter to use ssh-askpass, which is probably not the case when run from console directly.

1) did you try running git without ssh-ident at all, no agent, no keys loaded? maybe the problem is in general that git sets the environment variables to require ssh-askpass, but it is not installed.

Seems like the parameter can be overridden with:

git config --global core.askpass ''

2) if you run ssh-askpass manually from your console, does it work?

Thank you, Carlo

dracos commented 8 years ago

Is it possible that you have two ssh versions installed?

I don't believe so.

or that git or your .bashrc set environment variables to change the behavior of ssh?

I don't believe I have any special config; it all works fine without ssh-ident being present.

which ssh is /Users/matthew/bin/ssh (it's a symlink to ssh-ident; without that it is /usr/bin/ssh). which ssh-askpass is empty. env | grep -i ssh is SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.1W3vbATfMx/Listeners

1) did you try running git without ssh-ident at all, no agent, no keys loaded?

Yes, git is fine without ssh-ident, working as you would expect, asking for my passphrase on my SSH key.

git config --global core.askpass ''

If I set that, there's no change, it still has the exec(/usr/libexec/ssh-askpass).

2) if you run ssh-askpass manually from your console, does it work?

No, I don't appear to have any such program.

Hope that's of some help.

s1kx commented 8 years ago

Can you try setting VERBOSITY = LOG_DEBUG in your .ssh-ident configuration and paste the output when you try to use git again?

In the meantime, you could try using either a ssh-askpass script (as OS X doesn't seem to provide a system binary), or if your git installation provides git-gui--askpass (e.g. try finding the location with locate git-gui--askpass or look in the folder that git is stored in, which you can find with which git).

This will probably only start working with #31 merged due to SSH_ASKPASS currently not working correctly in master.

dracos commented 8 years ago
$ git pull
Will run '/usr/bin/ssh' as ssh binary - deteced from argv[0] and $PATH
Agent in /Users/matthew/.ssh/agents/agent-work-Aura.local not running
Preparing new agent for identity work
Loading keys:
    /Users/matthew/.ssh/identities/work/id_rsa
ssh_askpass: exec(/usr/libexec/ssh-askpass): No such file or directory
+ . /Users/matthew/.ssh/agents/agent-work-Aura.local
+ exec /usr/bin/ssh -oUseRoaming=no git.work.example.org 'git-upload-pack '\''/data/git/public/repo.git'\'''
Verification code: 
$ ssh git.work.example.org
Will run '/usr/bin/ssh' as ssh binary - deteced from argv[0] and $PATH
Agent in /Users/matthew/.ssh/agents/agent-work-Aura.local not running
Preparing new agent for identity work
Loading keys:
    /Users/matthew/.ssh/identities/work/id_rsa
Enter passphrase for /Users/matthew/.ssh/identities/work/id_rsa: 
Identity added: /Users/matthew/.ssh/identities/work/id_rsa (/Users/matthew/.ssh/identities/work/id_rsa)
+ . /Users/matthew/.ssh/agents/agent-work-Aura.local
+ exec /usr/bin/ssh -oUseRoaming=no git.work.example.org

I'm guessing (looking at ssh-add source code), the only difference is ssh-add when called via ssh/ssh-ident via git is getting a false for isatty/or being able to open /dev/tty, whereas when called via ssh/ssh-ident directly it's okay. I don't know why this is okay when ssh-ident isn't in the loop.

ccontavalli commented 7 years ago

Sorry for latency, finally got enough time to investigate the issue, and reproduce the error:

Should have a fix very soon.

$ git pull
Loading keys:
    /home/ccontavalli/.ssh/identities/ccontavalli/ssh2-private
    /home/ccontavalli/.ssh/identities/ccontavalli/ssh2-4096-private
ssh_askpass: exec(/usr/bin/ssh-askpass): No such file or directory
ssh_askpass: exec(/usr/bin/ssh-askpass): No such file or directory
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.