You want to access a remote computer from a local computer. The remote computer does not have a public IP, is on its own local network and can access internet.
Solution: To access the remote computer, you need a middleman (proxy server) which is accessible by both, the remote and the local computer. You open an ssh tunnel from remote to middleman. Use that ssh tunnel on local to access the remote computer.
- Create VM on a cloud service (like https://www.digitalocean.com/products/droplets/). Get its public IP and password.
- As a test, access the VM from local computer:
ssh [email protected]
. If successful, proceed. If not, inspect.
- On remote computer:
-
Get username of remote computer (use this in Step 3.):
whoami
-
Install autossh:
sudo apt install autossh
-
Copy remote computer's ssh keys to proxy server:
ssh-copy-id ~/.ssh/id_rsa.pub VM_USER_NAME@VM_PUBLIC_IP
-
Open ssh tunnel:
autossh -R VM_PUBLIC_IP:AUTOSSHPORT:localhost:22 'VM_USER_NAME@VM_PUBLIC_IP'
Example:
autossh -R 203.162.43.12:5090:localhost:22 '[email protected]'
- On local computer:
- Get remote computer's username.
- Access remote computer via the ssh tunnel:
ssh -p AUTOSSHPORT REMOTEUSERNAME@VM_PUBLIC_IP
. Example:ssh -p 5090 [email protected]
- Enter remote computer's password and it should work.
If Step 3 says "Connection refused", ssh into proxy server first and ssh REMOTEUSERNAME@localhost -p 5090