Skip to content

Instantly share code, notes, and snippets.

@coltonbh
Last active May 16, 2023 05:09
Show Gist options
  • Save coltonbh/d3fd5bd95a2dcaaf405d21e79756dd22 to your computer and use it in GitHub Desktop.
Save coltonbh/d3fd5bd95a2dcaaf405d21e79756dd22 to your computer and use it in GitHub Desktop.
Two Hop SSH Login
  1. Create new ssh key

Change to ssh directory

cd ~/.ssh/

Create a new key. Give it a useful name (you are prompted for a name after you hit enter; leave passphrase blank)

ssh-keygen -t ed25519 -C "your_email@example.com"

or if no Ed25519 algo:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  1. Copy key to server
ssh-copy-id -i ~/.ssh/my_key.pub username@ip_address_of_server
  1. Update ~/.ssh/config file
Host first-hop
  HostName login-node-dns-or-ip
  User username
  IdentityFile ~/.ssh/my_key
  IdentitiesOnly yes
  ForwardAgent yes

Host second-hop
  HostName second-hostname-or-ip
  User username
  IdentityFile ~/.ssh/my_key
  ProxyCommand ssh first-hop -W %h:%p
  1. If needed chomd the newly created key to 600
chmod 600 my_key_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment