rstudio / rstudio

RStudio is an integrated development environment (IDE) for R
https://posit.co/products/open-source/rstudio/
Other
4.69k stars 1.1k forks source link

2022.12 might have broken the git ssh directory location (publickey permission denied issues) #12458

Closed hdrab127 closed 1 year ago

hdrab127 commented 1 year ago

System details

RStudio Edition : Desktop
RStudio Version : 2022.12.0 Build 353
OS Version      :  Windows 10 Home 21H2 (19044.2364)
R Version       : 4.2.2 Patched (2022-12-14 r83470 ucrt)
Git Version     : 2.39.0.windows.1

Steps to reproduce the problem

This might be hard to reproduce sorry. After updating to 2022.12, I started getting git permission denied (publickey) errors. So I checked ssh and it looks like the new RStudio version might have altered the default ssh key directory to '/c/Program Files/RStudio/resources/app/resources/terminal/bash/.ssh'?

I definitely don't know my way around git or windows though, so I'm really sorry if this is a me issue rather something in RStudio.

hdrab@DESKTOP MINGW64 /c/Users/hdrab/some-project (main)
$ ssh -Tvvv git@gitlab.com
OpenSSH_9.1p1, OpenSSL 1.1.1s  1 Nov 2022
debug1: Reading configuration data /etc/ssh/ssh_config
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/c/Program Files/RStudio/resources/app/resources/terminal/bash/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/c/Program Files/RStudio/resources/app/resources/terminal/bash/.ssh/known_hosts2'
debug2: resolving "gitlab.com" port 22
debug3: resolve_host: lookup gitlab.com:22
debug3: ssh_connect_direct: entering
debug1: Connecting to gitlab.com [172.65.251.78] port 22.
debug3: set_sock_tos: set socket 4 IP_TOS 0x48
debug1: Connection established.
...
debug1: Trying private key: /c/Program Files/RStudio/resources/app/resources/terminal/bash/.ssh/id_rsa
debug3: no such identity: /c/Program Files/RStudio/resources/app/resources/terminal/bash/.ssh/id_rsa: No such file or directory
debug1: Trying private key: /c/Program Files/RStudio/resources/app/resources/terminal/bash/.ssh/id_ecdsa
debug3: no such identity: /c/Program Files/RStudio/resources/app/resources/terminal/bash/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /c/Program Files/RStudio/resources/app/resources/terminal/bash/.ssh/id_ecdsa_sk
debug3: no such identity: /c/Program Files/RStudio/resources/app/resources/terminal/bash/.ssh/id_ecdsa_sk: No such file or directory
debug1: Trying private key: /c/Program Files/RStudio/resources/app/resources/terminal/bash/.ssh/id_ed25519
debug3: no such identity: /c/Program Files/RStudio/resources/app/resources/terminal/bash/.ssh/id_ed25519: No such file or directory
debug1: Trying private key: /c/Program Files/RStudio/resources/app/resources/terminal/bash/.ssh/id_ed25519_sk
debug3: no such identity: /c/Program Files/RStudio/resources/app/resources/terminal/bash/.ssh/id_ed25519_sk: No such file or directory
debug1: Trying private key: /c/Program Files/RStudio/resources/app/resources/terminal/bash/.ssh/id_xmss
debug3: no such identity: /c/Program Files/RStudio/resources/app/resources/terminal/bash/.ssh/id_xmss: No such file or directory
debug1: Trying private key: /c/Program Files/RStudio/resources/app/resources/terminal/bash/.ssh/id_dsa
debug3: no such identity: /c/Program Files/RStudio/resources/app/resources/terminal/bash/.ssh/id_dsa: No such file or directory
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
git@gitlab.com: Permission denied (publickey).

This same behaviour occured after adding a new ssh key from the Create SSH Key button in RStudio "Tools/Global Options/Git-SVN/SSH key:".

Also, it doesn't matter if using git bash by itself, or the intergrated terminal in RStudio with git bash.

Describe the problem in detail

A quick fix (https://stackoverflow.com/questions/71563841/how-to-fix-ssh-git-connections-after-windows-update-broke-them-issue-seems-to) was to add my previous ssh key manually and everything worked again:

hdrab@DESKTOP MINGW64 /c/Users/hdrab/some-project (main)
$ eval $(ssh-agent -s) && ssh-add C:/Users/hdrab/.ssh/id_ed25519
Agent pid 1076
Identity added: C:/Users/hdrab/.ssh/id_ed25519 (hdrab@DESKTOP)

hdrab@DESKTOP MINGW64 /c/Users/hdrab/some-project (main)
$ ssh git@gitlab.com
...
debug1: Will attempt key: hdrab@DESKTOP ED25519 SHA256:... agent
...
Welcome to GitLab, @hrabel!
Connection to gitlab.com closed.

But this needs to be run for each new terminal session. I copied my .ssh folder to /c/Program Files/RStudio/resources/app/resources/terminal/bash/ and gave that folder write access, which seemed to fix the ssh call but not git pull or push permission oddly.

I also tried re-installing RStudio 2022.12 into my home directory (instead of program files) to avoid write issues but this only allowed the creation of the /c/Users/hdrab/RStudio/resources/app/resources/terminal/bash/.ssh/known_hosts file. It didn't fix the git ssh connection.

Finally, I reverted to RStudio 2022.07.2-576 and could not reproduce the issue there. Git and ssh worked as expected again. I then updated back to 2022.12 and received the same issues as above. So I guess some internal configuration is changed when installing 2022.12?

Describe the behavior you expected

Git & ssh to continue working as it did before updating RStudio. Or the Create SSH Key UI in RStudio to create the new key in the RStudio terminal/bash/ directory maybe.

Apologies again if this is something to do with my system setup!

hdrab127 commented 1 year ago

If it helps, I also have my .ssh/config file set up with

Host gitlab.com
    HostName gitlab.com
    IdentityFile C:/Users/hdrab/.ssh/id_ed25519

But maybe that's getting ignored or overruled somewhere. Adding this to C:/Program Files/Git/etc/ssh/ssh_config appears to have fixed the issue above permanently

kevinushey commented 1 year ago

This is probably a consequence of the RStudio shell hooks, which we use to try and ensure that an appropriate version of Python is placed on the PATH. It can be disabled here (Tools -> Global Options... -> Terminal -> General):

Screenshot 2022-12-20 at 11 09 41 PM
hdrab127 commented 1 year ago

Thanks! That fixes it without the ssh_config settings