SSH key forwarding is dangerous and a large attack vector.
Here’s what man ssh_config(5) has to say about ForwardAgent:
Agent forwarding should be enabled with caution. Users with the ability to bypass file permissions on the remote host can access the local agent through the forwarded connection.
An attacker cannot obtain key material from the agent, however they can perform operations on the keys that enable them to authenticate using the identities loaded into the agent.
The solution is to confirm by hand each time the key is used. For this we use a simple Allow/Deny dialog which can be confirmed with the return key. So no big loss of comfort.
- With this setup
ssh-agent
will ask for confirmation every time an ssh key is used - This solution refers to macOS, since macOS does not include
ssh_askpasss
by default - For this to work SSH keys must be loaded with
ssh-add -c
- Download the script and make it executable
- Set
SSH_ASKPASS
to the path of the script - Load the SSH key with
ssh-add -c /path/to/key
$ cat .zshrc | grep askpass -A8
# askpass
export DISPLAY=":0"
export SSH_ASKPASS="$HOME/bin/ssh-askpass"
export SSH_AUTH_SOCK="$HOME/.ssh/ssh-agent.sock"
if ! ssh-add -l 2>/dev/null >/dev/null; then
killall ssh-agent
rm $SSH_AUTH_SOCK
ssh-agent -a "$SSH_AUTH_SOCK" >/dev/null
fi