I've set up ssh authentication with an instance of ssh-agent being run from ~/.bashrc on each reboot.
Pushing to github from RStudio I get the following error:
ssh_askpass: exec(/usr/lib/ssh/ssh-askpass): No such file or directory git@github.com: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
Pushing from the shell works perfectly fine.
Also running ssh -T git@github.com I get "you've successfully authenticated..."`
I also tried creating a new repository and cloning it using Rstudio (new project/version control) and again got the same error as quoted above. Doing it manually from the terminal works fine.
Yes Kevin, sorry, I should have been clearer: this is me trying to press the Push button in the Git pane. (Same thing when I am trying to clone a new repo from github I mean going through the menu: New Project/Version Control). In both cases I get the error I reported.
Taking a hint from https://stackoverflow.com/questions/51866922/ssh-keygen-does-not-find-ssh-askpass (which relates to Git for Windows, but seems to have a similar description), does it make a difference if you unset the DISPLAY environment variable? Alternatively, can you reproduce this issue if DISPLAY is set within one of your terminals?
My DISPLAY value is ":0-0"
So if I set "DISPLAY=" in .bashrc, and source it, it doesn't change anything i.e. I still get the same error pushing from RStudio.
I'm not sure what you mean by setting DISPLAY in one of my terminals. I mean I can set it to empty, but I already have no problems running git push from any terminal. So I cannot reproduce this in my terminal anyway, since ssh-agent seems to work fine there.
Also I am not sure what to do with x11-ssh-askpass, since I don't want a graphical dialog (sorry if I am misunderstanding). What I am trying to do (or rahter what I think I am doing):
In my bashrc I have the following code: if [ ! -S ~/.ssh/ssh_auth_sock ]; then eval ssh-agent`` ln -sf "$SSH_AUTH_SOCK" ~/.ssh/ssh_auth_sock fi export SSH_AUTH_SOCK=~/.ssh/ssh_auth_sock ssh-add -l > /dev/null || ssh-add
So upon reboot after i first open a terminal I get asked my passphrase. from then on ssh-agent is running in the background and my key is decrypted.
so anytime I run e.g. git push or whatever, the ssh key has already been authorised, and it works automatically.
i would expect this to work also by using the buttons in RStudio to push. But it does not, hence my question.
before trying to perform a Git push? My hypothesis is that, when Git is invoked by RStudio, something is causing it to try to invoke /usr/lib/ssh/ssh-askpass, which shouldn't be needed or required. Note that RStudio runs git as a child process, and so would inherit any environment variables set in the R session.
It may also be worth saying that these environment variables may not necessarily match what you've set in your terminal through your startup profiles.
You could also try unsetting the GIT_ASKPASS and SSH_ASKPASS environment variables; e.g.
I wonder then, if since ssh-agent is only activated for interactive shell sessions (through ~/.bashrc), then perhaps it's not being run when RStudio just tries to execute git from the command line.
I'm not sure what the right solution to that is, but I guess the approach you're looking for would involve making sure ssh-agent is active when git is launched by RStudio. Does that sound correct?
Alternatively, you could set SSH_ASKPASS or GIT_ASKPASS (through Sys.setenv()) to a command line application that knows how to supply the necessary credentials.
Hey Kevin,
Yes, that makes sense, it seems ssh-agent is not being run when git is launched from RStudio and that is what I would ideally like to achieve.
As to your alternative suggestion, I'm not really sure how to approach it, since I'm not completely confident I understand how the env vars fit together in this whole thing . Would you mind being more concrete about this solution? Cheers
Sorry, I don't have a great answer here. I would recommend checking out whether the git credential helper can be configured to help in this particular scenario.
Alternatively, you could fall back to using an https:// remote URL, and avoid SSH-based authentication.
hey Kevin, thanks for helping! i was hoping to be able to use git directly from rstudio on this machine, but tbh, this has finally gotten me to use git from the terminal, which is probably a good thing so i guess i'll just stick to that.
maybe this is helpful for someone else and i'd still be interested in knowing how to get it to work, but i'm happy to close this thread, cheers!