How to SSH to device which is connected via VPN to server?
15,843
Since the PC has a dynamic address, it must be assigned a hostname.
- If the dynamic IP is internal to your network and you control the DHCP/DNS server such as Dnsmasq, you can make it assign a hostname.
- If the dynamic IP is ISP-assigned, use a DDNS service such as DynDNS to assign your PC a hostname.
Once your PC has a proper hostname, you can setup your server as the SSH jumphost:
- Install your laptop's public SSH key in the server and the PC.
In your laptop's
~/.ssh/config
, add the followingHost <PC_hostname> ProxyJump <server_hostname>
There are 2 alternatives that don't use DDNS.
Make the PC dump its IP in the server:
- PC dumps its IP in
user@server:~/pc-ip-addr.txt
at 1-minute intervals. - In the laptop, read the file and SSH to the PC's IP.
Make PC maintain a permanent SSH connection to server:
- In the PC,
ssh user@server -R 2222:localhost:2222
- In the laptop,
ssh user@server "ssh user@localhost -p2222"
Related videos on Youtube
![Артур Мурадянц](https://lh3.googleusercontent.com/-RT8b1nIWAyo/AAAAAAAAAAI/AAAAAAAAACs/9kF6OWKAxUw/photo.jpg?sz=256)
Author by
Артур Мурадянц
Updated on September 18, 2022Comments
-
Артур Мурадянц almost 2 years
I have a laptop, a server (static IP) and a PC (dynamic IP).
The PC is connected to the server via OpenVPN service. I want to use this to SSH from my laptop to this PC via server. I assume this is the easiest way to SSH to this computer given it uses a dynamic IP address.
Is it possible? If yes, how can it be done?
-
Артур Мурадянц almost 7 yearsI heard that connecting via VPN is similar to connecting device to your local network. So I thought I can use VPN connection instead of dynamic dns. Is it possible? Is it possible to do with out services like dynnds?
-
Eugene Chow almost 7 yearsIt's true that a VPN connection makes your device "local". Since your IP is dynamic, your your laptop needs a way to identify the PC. I've edited the answer above to include 2 DDNS-free methods. Tell me which you prefer and I'll provide more details.