Skip to content

Guide

How to sync your SSH config between computers

Last updated

To sync your SSH config between computers, keep ~/.ssh/config in one shared place (a git repo, a Syncthing folder or a connection manager) and leave your private keys out of it. This guide shows four ways to do it, with the commands, and when each one fits.

What to sync, and what not to

  • Sync: ~/.ssh/config (your hosts, users, ports and jump hosts), and optionally known_hosts, so a new machine doesn't ask you to confirm every server's key again.
  • Don't sync: private keys (id_ed25519, id_rsa and the like). Make a key on each computer with ssh-keygen -t ed25519 and add its public key to your servers. Then a lost laptop means removing one key, not replacing the key on every server.
  • Keep local: anything specific to one machine, such as a ControlPath socket folder, an IdentityAgent path, or a macOS UseKeychain line that other systems don't understand.
Your config has no secrets in it, but it is a map of your infrastructure: hostnames, users and jump hosts. Keep it somewhere private.

First: split shared and local

OpenSSH 7.3 and later can Include other files. Keep the hosts you share in their own file, and the machine-specific bits in the main config:

# ~/.ssh/config, on each computer
# Include must come before any Host block, or it only applies inside that block.
Include config.d/*

Host *
    ServerAliveInterval 30
    # machine-specific settings go here

Relative paths in Include are read from ~/.ssh, so config.d/* means ~/.ssh/config.d/. Put your shared hosts in a file there, say config.d/hosts, and sync only that folder. Each option below works with either the whole config or just config.d.

Option 1: a dotfiles repo

The classic answer: keep the file in a private git repo and link it into place. You get history and can see exactly what changed.

mkdir -p ~/dotfiles/ssh
mv ~/.ssh/config.d ~/dotfiles/ssh/config.d
ln -s ~/dotfiles/ssh/config.d ~/.ssh/config.d
cd ~/dotfiles
git init
git add ssh/config.d
git commit -m "SSH hosts"

Push it to a private repository, then on each other computer clone it and make the same link. After that, git pull brings in new hosts.

Guard against committing a key by accident with a .gitignore in the repo:

id_*
!*.pub
*.pem
  • Good: history, review, works everywhere git does.
  • Catch: it's manual. You have to commit and pull, and you'll forget on the machine you need. On Windows, symbolic links need Developer Mode or an admin prompt; copying the file is the simple fallback.

Option 2: Syncthing

Syncthing keeps a folder the same on all your computers, peer to peer, with no account. Share ~/.ssh/config.d as a Syncthing folder on each machine, and changes show up everywhere within seconds while both are online.

Share the config.d folder, not all of ~/.ssh. If you do share more, add a .stignore file so keys stay put. Syncthing uses the first pattern that matches, so the exception comes first:

!*.pub
id_*
*.pem
  • Good: automatic, no server, no account, works across Windows, macOS and Linux.
  • Catch: edit the same file on two machines before they sync and you get a .sync-conflict copy to merge by hand. It's another background program on every computer, and there's no official iPhone app.

Option 3: rsync or scp

For two computers that can already reach each other over SSH, copy the file across when it changes:

rsync -av ~/.ssh/config.d/ laptop:.ssh/config.d/

Here laptop is a host in your config. Without rsync (it isn't on Windows by default), scp does the same:

scp -r ~/.ssh/config.d laptop:.ssh/
  • Good: nothing to install or set up.
  • Catch: one way and manual. Whichever copy you edit last wins, and with three machines it gets hard to know which one is current.

Option 4: a connection manager that syncs

If you'd rather not keep a text file in step at all, an SSH connection manager can hold your hosts and sync them for you. Most do it through the vendor's cloud and an account, as Termius does. Some sync without any server.

TerminalLynx, which we make, works the second way. It imports your ~/.ssh/config (hosts, users, ports, keys, jump hosts and forwards), and your computers then sync it directly with each other, end to end encrypted, over your LAN or a VPN such as Tailscale. There's no account, and the Free plan covers 25 connections on 3 devices. Keys can go into its encrypted vault and sync too, or stay in ~/.ssh on each machine, used where they are.

  • Good: automatic, no file to merge, and it syncs to an Android phone as well. Teams can share a set of hosts with roles.
  • Catch: your hosts live in the app, so plain ssh in a terminal doesn't see new ones until you export them back to an ssh config file. Two computers only sync when they can reach each other, directly or through a relay.

The steps are in Pair a device and sync. To compare other managers, see the best Termius alternatives.

Which one to pick

Ways to sync an SSH config between computers
MethodAutomaticNeedsBest for
Dotfiles repoNo: commit and pullgit and a private repoPeople who already keep dotfiles and want history
SyncthingYes, while both are onlineSyncthing on every computerA few personal machines, no account
rsync or scpNo: copy when it changesNothing extraTwo computers, rare changes
Connection managerYesThe app on every computerMany hosts, a phone, or a team

Whichever you pick, the rule is the same: sync the config, make a key per computer, and keep the file private.