Unix & Linux
ssh openssh remote-management remote-control
Updated Sun, 17 Jul 2022 11:26:25 GMT

SSH PC at office in local network from home


My office has one default gateway and behind that is a local network with locally assigned IP addresses to all computers including mine.

I hold admin in my Ubuntu installed office PC and is it essential that I access the computer during weekends through SSH.

At office, I do not have a public IP but I always get the same local IP from the DHCP. I'm free to set up any software I like in my pc although I cannot set up port forwarding in the main firewall.

I get a public IP to my home computer which also runs Linux. please note I cannot install Team Viewer-like software.

How can I solve my problem?




Solution

It's easy:

  1. [execute from office machine] Setup connection Office -> Home (as Home has public IP). This will setup reverse tunnel from your office machine to home.

    ssh -CNR 19999:localhost:22 homeuser@home

  2. [execute from home machine] Connect to your office from home. This will use tunnel from the step 1.

    ssh -p 19999 officeuser@home

Please ensure, that ssh tunneling is not against your company policies, cause sometimes you can get fired for such connection schema (e.g. my employer will fire me for that).

ps. In the first step you may want to use autossh or something like that, so your tunnel connection will be automatically restored in case of unstable network.





Comments (5)

  • +1 – +1 I think the part about company policy should be in bold. Oh but if they allow outgoing encrypted communications, then probably he does nothing wrong :) — Nov 16, 2014 at 14:32  
  • +0 – this is under their request, so I think i'm safe. And SSH is such a sophisticated software. I didn't know it could do this. many thanks for the answers and your concerns. Im going to try this and I will comment the results here. — Nov 16, 2014 at 16:33  
  • +0 – I ran the command: ssh -CNR 19999:localhost:22 -i privateKey.pem homeuser@homeIP while i was at office. Its seems the whole terminal is stuck. What could be the possible problem? — Nov 18, 2014 at 15:17  
  • +0-N option tells ssh do not perform actual login and it will just open tunnel and hand till disconnected with ^c or network issue — Nov 18, 2014 at 15:26  
  • +0 – In the same way. autossh is wrapper for ssh which is able automatically restore connection in case of connectivity lost. — Nov 18, 2014 at 16:19