happy-git-with-r icon indicating copy to clipboard operation
happy-git-with-r copied to clipboard

More about ssh keys

Open jennybc opened this issue 5 years ago • 7 comments

Building up to better coverage of ssh keys in general and, specifically, getting git2r to work well. These notes are likely macOS specific.

What keys are currently registered with the ssh agent?

ssh-add -l
ssh-add -L

See the RSA key fingerprint for a local key in order to, say, match it up against a key on GitHub.

ssh-keygen -E md5 -lf /path/to/key

https://stackoverflow.com/questions/9607295/how-do-i-find-my-rsa-key-fingerprint

Probably important, in terms of understanding behaviour I see on my Mac:

OS X users take note that magic passwordless SSH via Keychain is not the same as using ssh-agent.

jennybc avatar Oct 14 '18 20:10 jennybc

http://blog.joncairns.com/2013/12/understanding-ssh-agent-and-ssh-add/

https://github.com/wwalker/ssh-find-agent

jennybc avatar Oct 14 '18 20:10 jennybc

This allowed me to verify that yes it's the macOS keychain that is managing my ssh key passphrase right now (macOS Mojave 10.14).

Launch Applications > Utilities > Keychain Access. Now search for "ssh" or "id_rsa", etc. The relevant entry for me shows up as an application password for SSH and I can, indeed, verify it's managing the passphrase for the key I use on GitHub.

https://apple.stackexchange.com/questions/265131/recover-ssh-private-key-passphrase-from-keychain

jennybc avatar Oct 14 '18 20:10 jennybc

Good way to test the ssh connection and get a passphrase prompt:

https://help.github.com/articles/testing-your-ssh-connection/

ssh -T [email protected]

jennybc avatar Oct 26 '18 18:10 jennybc

https://superuser.com/questions/1330469/macos-keychain-access-holds-on-to-ssh-passphrase-indefinitely

jennybc avatar Nov 08 '18 20:11 jennybc

https://superuser.com/questions/88470/how-to-use-mac-os-x-keychain-with-ssh-keys

jennybc avatar Nov 08 '18 20:11 jennybc

I think on macOS, especially if you want git2r to work, you really do need to use ssh-agent. My experiment with not running it is resulting in lots of friction.

https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/

Key commands for quick access:

Start the ssh-agent in the background:

eval "$(ssh-agent -s)"

Check if you can access github.com via ssh (can trigger a challenge for ssh passphrase):

ssh -T [email protected]

jennybc avatar Jan 10 '19 20:01 jennybc

Finally got my usethis::git_sitrep() to return git2r supports SSH: TRUE and wanted to capture it, since it was a weird combination of steps...

Had/have SSH setup with GitHub from terminal (per Happy Git w/ R and GH docs), specified usethis protocol as SSH, working GitHub PAT, ssh-agent enabled etc.

Basically the entire git_sitrep() below, but with git2r supports SSH: FALSE

usethis::git_sitrep()
#> Git user
#> * Name: 'Mara Averick'
#> * Email: 'my email address'
#> * Vaccinated: TRUE
#> usethis + git2r
#> * Default usethis protocol: 'ssh'
#> * git2r supports SSH: TRUE
#> * Credentials: '<usethis + git2r default behaviour>'
#> GitHub
#> * Personal access token: '<found in env var>'
#> * User: 'batpigandme'
#> * Name: 'Mara Averick'

I ultimately found the solution in the git2r release notes here re. no longer supporting SSH transport by default (breaking change for git2r 0.23.0). To enable, you need to install from source.

Though I'd been using the GitHub version, and already libgit2 on my machine (installed using homebrew), this somehow wasn't linking up until I used the suggested:

install.packages('git2r', type='source', configure.vars='autobrew=yes')

This didn't actually reinstall libgit2 from homebrew, though it would have been allowed, if it hadn't been on my computer.

System info:

R version 3.5.3 (2019-03-11)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.6
git2r_0.26.1 

@jennybc — just let me know if this is the wrong place, or useless or whatever!

batpigandme avatar Jul 24 '19 14:07 batpigandme