Skip to content

Instantly share code, notes, and snippets.

@jezeniel
Last active November 27, 2023 17:32
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jezeniel/031a93a7fa73c77fb4a2 to your computer and use it in GitHub Desktop.
Save jezeniel/031a93a7fa73c77fb4a2 to your computer and use it in GitHub Desktop.
SSH Agent Forwarding cheatsheet

Using the ssh agent

The following would show a similar output if a key is already added to your agent, and you are good to go.

$ ssh-add -l
2048 d7:8e:3d:03:9c:4f:f8:9d:04:0f:11:c5:24:e1:2f:3a rsa w/o comment (RSA)

The following will show if no agent is running.

$ ssh-add -l
Could not open a connection to your authentication agent.

If no agent is running execute the following.

$ eval `ssh-agent`

If the agent is running but no identities.

$ ssh-add -l
The agent has no identities.

Adding identities to the ssh agent

If an agent is running run the following.

$ ssh-add

The above example assumes that you already generated your ssh-key.

Connecting to a server with ssh forwarding

$ ssh -A -i <your_pemfile> user@<remote_addr>

The -A flag enables forwarding of the authentication agent.

Testing ssh agent forwarding (remote server)

Once you logged inside your remote server just run the following to check if ssh forwarding agent is enabled:

$ echo "$SSH_AUTH_SOCK"
/tmp/ssh-DCIux21917/agent.21917

If the variable is not set then the forwarding agent is not working.

TODO

  • Handling ssh-agent across multiple terminal sessions locally

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment