brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: IdentityAgent tells ssh which key agent to use for each host

Network and access
~/tips/tip-ssh-identityagent

Host github.com

Point ssh at a different agent socket per host, or switch the agent off entirely.

Password managers and tools like Secretive run their own SSH agent with a socket somewhere in your home folder. Instead of changing SSH_AUTH_SOCK for your whole session, you can choose the agent per host.

Host github.com
    IdentityAgent ~/.1password/agent.sock

Host *.example.com
    IdentityAgent SSH_AUTH_SOCK

The first block uses the password manager’s agent for GitHub. The second explicitly uses whatever SSH_AUTH_SOCK points to, which is the normal system agent. The man page says the option overrides the environment variable, and a value starting with $ is read from an environment variable of that name.

Use none to keep a host away from any agent:

Host untrusted.example.com
    IdentityAgent none

That is useful when you connect to a box you do not fully trust and also use agent forwarding elsewhere.

To check what ssh will pick, ssh -G github.com | grep -i identityagent shows the result.

If keys from the agent seem to be ignored, look at IdentitiesOnly too. With it on, ssh only offers keys that match your IdentityFile lines, even when the agent holds more. For agents that keep the private key to themselves, I’d point IdentityFile at the public key file, which is enough for ssh to know which agent key to use.

Further reading: ssh_config man page

More Network and access tips scp -3 alice@server-a:/var/backups/db.sql.gz bob@server-b:/srv/restore/ tailscale exit-node suggest tailscale lock sign nodekey:1abddef1 tlpub:abcdef12 wg genpsk > peer1.psk Table = off All Network and access tips (163) All topics

Link