Step by step: keep your SSH keys in 1Password and have Terminal's ssh use them, with a Touch ID check, one server at a time. Background on keys and the config file is on the SSH sheet.
READ-ONLY only looks; safeCHANGES THINGS be carefulON YOUR MAC in Terminal or the 1Password app$ = you type this
Set up once
#1How it works
Your private keys live inside 1Password, not as files on your Mac. When you log in to a server, ssh asks 1Password for the right key, and 1Password checks with you first.
The pieces you'll set up
1Password's SSH agent
A setting in 1Password that lets ssh ask it for keys. Turned on once (step 3).
SSH Key items
Each private key, stored in 1Password (step 4).
.pub files
The public half of each key, saved in ~/.ssh. Safe to keep on your Mac; it tells ssh which key to ask for (step 5).
One config entry per server
In ~/.ssh/config, pointing that server at 1Password and at its key (step 6).
WHY THIS WAYEach server says exactly which key it uses, so the right key is always offered, and servers you haven't switched over keep working exactly as before. You can move one server at a time.
The 1Password app for Mac (version 8), installed, signed in, and unlocked.
Your existing key files (for example AWS .pem files), and a server you can currently log in to, to test with.
Make sure the ~/.ssh folder and config file exist
mkdir -p ~/.ssh && chmod 700 ~/.ssh
touch ~/.ssh/config && chmod 600 ~/.ssh/config
Safe to run even if they already exist: mkdir -p and touch don't change existing ones; chmod sets "only you" permissions, which ssh requires. No output = done.
Back up your config file
cp ~/.ssh/config ~/.ssh/config.backup
Your safety net. To undo every change later: cp ~/.ssh/config.backup ~/.ssh/config.
From the menu bar: 1Password › Settings (or press Cmd+,).
Click Developer.
Turn on Use the SSH Agent.
If offered, also turn on Display key names when authorizing connections. The approval prompt then names the key, so you can see the right one is being used.
Check the agent is running (read-only)
ls -l ~/Library/Group\ Containers/2BUA8C4S2C.com.1password/t/agent.sock
A line starting with srw = the agent is on. (s means it's a "socket," a connection point programs talk through.)
No such file or directory = the setting isn't on yet, or 1Password isn't running.
THE AGENT'S ADDRESSThat long path is where ssh finds 1Password. You'll paste it into each config entry in step 6. It's the same on every Mac.
⚠ PUT IT IN THE RIGHT VAULTBy default, the SSH agent only uses keys in your Personal vault (called Private on some accounts). A key saved in any other vault is ignored, and the error you get doesn't say so (see step 9).
Choose a name
Name each key for what it's for, so it's easy to identify: a client, a group of servers, or a purpose. Use the same name for the 1Password item and, in step 5, the .pub file. On this sheet the name is shown as key-name.
Option A: import a key you already have (like an AWS .pem)
Make sure the Personal/Private vault is selected in the sidebar.
Click + New Item and choose SSH Key.
Click Add Private Key › Import a Key File, and pick the key file (for example key-name.pem).
If the key file has its own passphrase, 1Password asks for it once.
Set the item's title to key-name and click Save.
Option B: create a new key in 1Password
In the Personal/Private vault, click + New Item and choose SSH Key.
Click Add Private Key › Generate a New Key, choose Ed25519, and click Generate.
Set the title to key-name and click Save.
The private key never leaves 1Password. You'll still need to put its public half on each server (SSH sheet, section 5).
What you'll see in the item
private key
Hidden. Never needs copying out.
public key
One long line starting with ssh-rsa or ssh-ed25519. You'll use it in step 5.
fingerprint
A short ID starting with SHA256:. Used to check that files and items match.
key type
Ed25519, or RSA for most AWS .pem files. Both work.
Each config entry points at a .pub file, so ssh knows which key to ask 1Password for. A .pub file is only the lock, not the key, so it's safe to keep on your Mac.
Check first: does it already exist? (read-only)
ls ~/.ssh/*.pub
If key-name.pub is already listed, skip to the fingerprint check below.
Way 1: copy it from 1Password (works for any key)
Open the SSH Key item in 1Password and copy the public key field (hover over it and click Copy).
In Terminal, save the clipboard as the file:
pbpaste > ~/.ssh/key-name.pub
pbpaste prints what's on your clipboard; > saves it into a new file. Use your key's name. No output = done.
Way 2: make it from the private key file (if you still have the file)
Compare the part after SHA256: with the fingerprint in the 1Password item. The first 6 to 8 characters matching is enough. No match = different key: don't use that file.
⚠ CAREFULPaste only the public key into the .pub file. And with >, if that file name already exists, it's replaced, which is why the check above comes first.
Each server gets its own entry, and each entry points at 1Password itself. There's no catch-all Host * line, so servers you haven't switched yet are left exactly as they are.
Open the config file
nano ~/.ssh/config
An existing server: before and after
Before (key file on disk)
Host ubuntu1 HostName 203.0.113.10 User ubuntu IdentityFile ~/keys/key-name.pem
Paste it at the end of the file, then replace NICKNAME, ADDRESS, and key-name. User is ubuntu on Ubuntu, ec2-user on Amazon Linux. Leave a blank line between entries.
Save and exit
Save: Ctrl+O, then Enter. Exit: Ctrl+X.
ONE KEY, MANY SERVERSSeveral entries can point at the same .pub file. Only the Host and HostName lines differ.
One line per key 1Password will hand out, with its fingerprint and name. Your key should be listed.
The agent has no identities = the agent is on, but sees no keys. Check the vault (step 4).
3. Log in
ssh ubuntu1
A 1Password window asks to allow Terminal to use the key, naming it. Approve with Touch ID or your 1Password password.
Then you're logged in as usual. Type exit to log out.
1Password remembers your approval for a while, so you won't be asked on every login.
⚠ NEW KEY? PUT IT ON THE SERVER FIRSTA key imported from an existing .pem already works on that server. A key you just created doesn't yet: add its public half to the server's authorized_keys first (SSH sheet, section 5), and keep your old login open while you test.
Is its key in 1Password, in the Personal/Private vault? If not: step 4.
Is its .pub file in ~/.ssh, with a matching fingerprint? If not: step 5.
Change its config entry: step 6.
Test it: step 7.
One server at a time. The config backup from step 2 only needs making once.
When every server works through 1Password
The old private key files (like .pem files) aren't needed anymore, since 1Password holds the keys. Don't delete them right away:
Confirm each key is in 1Password (step 7, check 2 lists them).
Move the old key files into one folder, for example ~/old-keys, so nothing uses them.
Use your servers normally for a couple of weeks.
If nothing needed them, delete that folder.
⚠ KEYS ON THE DESKTOP OR IN DOCUMENTSIf iCloud's "Desktop & Documents" syncing is on, private key files there are being copied to iCloud too. Once they're safely in 1Password, move them out of those folders.
Optional: use a vault other than Personal/Private
To keep server keys in their own vault, 1Password needs a small settings file listing the vaults the agent may use. Create it:
mkdir -p ~/.config/1Password/ssh
nano ~/.config/1Password/ssh/agent.toml
⚠ Example only: use your own vault names, spelled exactly as in 1Password
Each [[ssh-keys]] block allows one vault. Once this file exists, only the vaults listed are used, so keep your Personal/Private vault in the list if it still holds keys.
WARNING: UNPROTECTED PRIVATE KEY FILE! naming a .pub file, then Permission denied
Misleading. 1Password didn't hand over the key, so ssh tried the .pub as a private key. Almost always the key is in the wrong vault (step 4). Also check the agent is on (step 3) and the IdentityAgent line (step 6). Don't change the file's permissions.
Permission denied (publickey) with no warning
1Password offered the key, but the server doesn't accept it. Check the User line (ubuntu vs ec2-user), the fingerprint (step 5), and that the key is on the server (step 7's red box).
No 1Password window appears
It may be behind other windows; check the Dock. Or 1Password is locked or not running. Unlock it and try again.
Too many authentication failures
The entry is missing IdentitiesOnly yes (step 6).
The agent has no identities
Agent on, but no keys visible: wrong vault, or a vault left out of agent.toml (step 8).
Could not open a connection to your authentication agent / No such file
The agent isn't on. Turn on Use the SSH Agent (step 3) and make sure 1Password is running.
Bad configuration option / line 12: …
A typo in ~/.ssh/config at that line number. Open it with nano and compare with step 6.
Look for Offering public key:, which names the key it's trying, and Authenticated to for success. Ctrl+C stops it.
UNDO EVERYTHINGPut the config back the way it was: cp ~/.ssh/config.backup ~/.ssh/config. Your original key files still work as before, as long as you haven't deleted them (step 8).