Bits and bytes of code
Bytes is my collection of short-form posts, tips, and things I learn as I build software.
Bytes is my collection of short-form posts, tips, and things I learn as I build software.
At work, engineers are strongly encouraged to use an additional factor of authentication for SSH keys, rather than the traditional passwordless approach. While Yubikeys work well for this type of thing, I found that 1Password’s SSH support is actually much more ergonomic.
The way that 1Password’s SSH integration works is that you specify an
IdentityAgent in your SSH config which is what tells Git and other tools
how to access your SSH keys stored in 1Password. When you create an SSH key
in 1Password, the file it creates on disk is simply a reference to the item
in 1Password, so your private key is never stored on disk and can only be
accessed through 1Password.
To use 1Password for SSH, we first need to configure the identity agent. The agent will run in the background and trigger you to authenticate when pushing to GitHub.
With the identity agent configured, we need to create a new SSH key in 1Password.
Unlike traditional SSH key generation, 1Password will fully own the private key, so when we save the key to our ~/.ssh directory, we will be using the public key that 1Password uses to identify the private key.
In 1Password, click on the public key to copy it and run the following command:
pbpaste > ~/.ssh/id_ed25519.pubNext, we need to update our SSH config to use the 1Password identity agent. This is what allows 1Password to use the public key to identify the private key and then authenticate with the server.
Host *
IdentityAgent "~/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock"
Host github.com
User git
IdentityFile ~/.ssh/id_ed25519.pub
IdentitiesOnly yesNote: If you are using SSO authentication for GitHub, you will also need to authorize the key for your organization:
If you need to use multiple SSH keys for different repositories, such as personal and work repositories, you can create separate SSH keys and then configure multiple SSH hosts so you can switch between them easily.
Host *
IdentityAgent "~/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock"
Host home
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_home.pub
IdentitiesOnly yes
Host work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work.pub
IdentitiesOnly yesThen, when cloning a repository, change git@github.com: to home: or work: depending on which host you want to use. For example:
git clone home:mskelton/bytes.git
git clone work:org/repo.git