Skip to content

SSH Key Forwarding

Wyatt Barnes edited this page Dec 4, 2018 · 2 revisions

Create a config file in your .ssh directory, and edit the file like so:

DANGER

The following code snippet will store your private SSH key in the memory of an machine you connect to over Port 22. This means there's potential that someone could copy your private key from memory and store it elsewhere for later use!

This generally won't be a problem if you only SSH into machines you own/trust.

Host *
  UseKeychain yes
  AddKeysToAgent yes
  IdentityFile ~/.ssh/id_rsa
  ForwardAgent yes
  Port 22

The above will forward the ~/.ssh/id_rsa private key to any machine you connect to using Port 22 (a.k.a. any machine you SSH into), and store your private key in that machine's memory.

Why Would I Use This?

  • SSHing into a cloud instance (e.g. AWS EC2 instance) and cloning down a private Github repository
    • Without key forwarding, you'd typically have to choose to clone over HTTPS and enter your login credentials each time you need to pull or push or the repository

Clone this wiki locally