Skip to content

Dear Internet Explorer user: Your browser is no longer supported

Please switch to a modern browser such as Microsoft Edge, Mozilla Firefox or Google Chrome to view this website's content.

Using 1Password SSH Keys with Git in RStudio on Windows

Getting RStudio to authenticate Git operations via 1Password-managed SSH keys on Windows requires three small but non-obvious fixes: pointing Git at the Windows OpenSSH client, correcting RStudio’s HOME directory, and explicitly configuring SSH-based commit signing.

It is really easy to set-up Git in RStudio on Windows; I published a methodology back in 2022. But that relied on password authentication via HTTPS. What happens if you are using SSH keys instead?

If you are happy to use locally-stored SSH keys, then implementing SSH key authentication in RStudio is easy. But I like to use 1Password to securely store and manage my SSH keys, and getting that to work in RStudio isn’t quite straightforward. There are two problems:

Here’s how this can be fixed:

Prerequisites:

Step 1: Tell Git to use Windows OpenSSH

Run the following command in PowerShell:

git config --global core.sshCommand "C:/Windows/System32/OpenSSH/ssh.exe"

This forces Git to use the Windows OpenSSH client that 1Password integrates with, rather than Git’s bundled SSH client.

Step 2: Fix RStudio’s HOME directory

R on Windows often sets HOME to the Documents folder rather than your actual user profile, meaning Git can’t find your .gitconfig. Fix this by adding one line to your .Rprofile.

In R, type the following commands

install.packages("usethis")
usethis::edit_r_profile()

Then add the following line to .Rprofile:

Sys.setenv(HOME = Sys.getenv("USERPROFILE"))

Save and restart RStudio fully.

Step 3: Configure SSH commit signing

Retrieve your public key from 1Password via the CLI:

op item get "Name of SSH Key in 1Password" --fields "public key"

In my case, I named the SSH key “GitHub (Adam Dimech)” in 1Password, so my command would be:

op item get "GitHub (Adam Dimech)" --fields "public key"

Next, set up commit signing globally, using the public key returned above:

git config --global gpg.format ssh
git config --global user.signingkey "ssh-ed25519 AAAA...your-public-key-here"
git config --global gpg.ssh.program "C:/Windows/System32/OpenSSH/ssh-keygen.exe"
git config --global commit.gpgsign true

How it works:

Step 4: Verify everything is working

In R:

system("git config --global --list")  # should show all four settings
system('git ls-remote "git@github.com:your-username/your-repo.git"')  # should succeed

Then try a commit through the RStudio Git pane; 1Password will prompt for approval and the commit should succeed.

   

Comments

No comments have yet been submitted. Be the first!

Have Your Say

The following HTML is permitted:
<a href="" title=""> <b> <blockquote cite=""> <code> <em> <i> <q cite=""> <strike> <strong>

Comments will be published subject to the Editorial Policy.