All of this is done from the local machine – the one you want to connect from.
- Generate an SSH key to use with this specific host. (This makes it safer than using a single key for everything, in case someone ever gets that one private key.)
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa-HOSTNAME
- Add the key to your remote HOST
ssh-copy-id -i ~/.ssh/id_rsa-HOSTNAME.pub USERNAME@HOSTNAME
- Test your connection by SSHing with this key:
ssh -i ~/.ssh/id_rsa-HOSTNAME.pub USERNAME@HOSTNAME
- In VS Code, use the command palette (Ctrl+Shift+P) to run Remote-SSH: Open Configuration File… and pick
~/.ssh/config. Add or modipy the contents to be something like this (but matching your stuff, of course):
Host tupuxuara User jtebert HostName 10.243.52.252 IdentityFile ~/.ssh/id_rsa-HOSTNAME
Hostis just something human-friendly. The
HostNameis the IP address or name that actually gets your machine.
- Test your SSH Config by using it to log in:
You shouldn’t need to enter a password or anything. Magic.
- Test in VS Code. From the command palette run Remote-SSH: Connect to Host… and select your hostname. It should take a moment to set itself up the first time, but if the previous step worked, this should work.
- Within VS Code, you can now also do super useful things like port forwarding (in case your remote code runs a server, for example.)
- You may need a VPN to connect this way, if you otherwise need a VPN to connect (duh). (Looking at you, Harvard SEAS.)