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 YES/NO 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 requested. - 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
.
$ 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
$ cat $HOME/bin/ssh-askpass
#! /bin/sh
# An SSH_ASKPASS command for MacOS X
# Based on script by Joseph Mocker, Sun Microsystems
TITLE=${MACOS_ASKPASS_TITLE:-"SSH Agent"}
DIALOG="display dialog \"$@\" buttons {\"Deny\", \"Allow\"} default button 2"
DIALOG="$DIALOG with title \"$TITLE\" with icon caution"
result=`osascript -e 'tell application "Terminal"' -e "$DIALOG" -e 'end tell'`
if [ "$result" = "button returned:Allow" ]; then
exit 0
else
exit 1
fi
source: https://serverfault.com/a/238500