Mosh doesn't provide proper support for agent forwarding, generating error messages like this one:
Permission denied (publickey)
in response to a git clone.
For adressing the issue, follow bellow steps:
- Open an separate SSH session with agent forwarding enabled in another terminal:
ssh -A user@server - In your mosh session execute the given command for setting SSH_AUTH_SOCK to the last created ssh-agent socket:
export SSH_AUTH_SOCK=$( \
find /tmp -path '*/ssh-*' -name 'agent*' -uid $(id -u) -printf "%T+\t%p\n" 2>/dev/null \
| sort \
| tail -n1 \
| awk -F'\t' '{print $2 }' \
)- Run
git clone ...or whatever you wanted. - When you are done, disconnect the SSH session