Skip to content

Instantly share code, notes, and snippets.

@ictus4u
Last active July 18, 2021 23:58
Show Gist options
  • Save ictus4u/81f8761ec4dafa7b73441b9757558601 to your computer and use it in GitHub Desktop.
Save ictus4u/81f8761ec4dafa7b73441b9757558601 to your computer and use it in GitHub Desktop.
Fix agent forwarding inside a mosh session

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:

  1. Open an separate SSH session with agent forwarding enabled in another terminal: ssh -A user@server
  2. 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 }' \
)
  1. Run git clone ... or whatever you wanted.
  2. When you are done, disconnect the SSH session
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment