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:
- Git ships with its own bundled SSH client which bypasses the 1Password SSH agent
- RStudio sets
HOMEto the Windows Documents folder (which may be OneDrive-redirected), so Git can’t find the.gitconfigfile.
Here’s how this can be fixed:
Prerequisites:
- 1Password desktop app installed with SSH agent enabled (more info)
- 1Password CLI installed (more info)
- Git for Windows installed
- RStudio installed, with R
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:
- The public key in
.gitconfigis not sensitive — it just tells Git which key to request - When Git authenticates or signs a commit, it calls Windows OpenSSH, which asks the 1Password SSH agent to perform the operation
- The private key never leaves 1Password — the agent signs on its behalf each time, prompting for your Windows Hello/PIN or 1Password approval
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!