I will be travelling shortly, and I have a machine that run runs a bunch of cron jobs etc. I need to log in remotely to check the results of the jobs run and to do some work on the machine.

Here are the salient facts:

  1. The machine to be connected (mothership) is running Ubuntu 14.0.4 LTS
  2. The mothership is connected to the internet via a LAN at home, so has a public facing IP address.
  3. The IP address is dynamically assigned.
  4. I will be connecting to the mothership using a Laptop running Ubuntu 15.10

I prefer to use ssh rather than VNC, because of bandwidth problems - plus, all I need is the command line anyway.

What is the best way to securely connect remotely to my machine?

  • SSH is secure. What is your problem with it? Mar 20 '16 at 13:08
  • VNC is graphical remote control. Do you mean VPN? Mar 20 '16 at 13:13
  • @techraf ah, I get it. I sent an approval vote Mar 20 '16 at 13:15
  • Just read a good guide, there's a bettercrypto section dedicated to ssh out there. And disable password log in!
    – Braiam
    Mar 20 '16 at 18:21
  • From the chat, I see you thought of authentication with passphrases instead of passwords. What you might look into is to allow private/public-key authentication only. Mar 20 '16 at 22:27

Your best bet is probably to run an SSH server on a non-default port, such as 2020. This prevents most attempts at brute force attacks from the web, as these bots tend to only look on default ports.

You are also going to need to assign the server a static IP address on the LAN, as it needs to be accessible at all times. You can set this in System Settings --> Network. To prevent IP address conflicts, it's also advisable that you tell your DHCP server (the router in most cases) that this IP address is taken. The method varies by model, but there should be an area somewhere in the router configuration that lets you reserve IP addresses.

The reason for the static IP is that you need to set up port forwarding in your router setup. This allows connections from port to you external IP to be routed to that port on your server.

If your public IP address is dynamic, which it probably is, you're going to want to set up some sort of dynamic DNS service. My recommendation for this service is No-IP. It gives you a free sub-domain that always points to your public IP. This setup does require the installation of a program on an always-on machine on your LAN (called the DUC, provided by No-IP).

Once you have the SSH server set up how you want, SSH to it by entering

ssh user@remotehostip -p XXX

or by using whatever SSH/SFTP client you prefer.

If any of these sections need more detailed instructions, comment and I'll add them in.

If anyone else has trouble following, here is a chat room that has further/more detailed steps: http://chat.stackexchange.com/rooms/37251/discussion-between-homunculus-reticulli-and-zacharee1

  • +1 Thanks @Zacharee1 for the prompt response. I have registered a domain for my purpose, using no-ip. I have followed all the steps. The last step is where I'm at a loss: setting up router for port forwarding. I could do with some help in this area if possible. Thanks Mar 20 '16 at 13:29
  • @HomunculusReticulli What's your router model? Mar 20 '16 at 13:30
  • Also, I can't see where/how to assign the static IP address. I am using Ubuntu Trusty Tahir Mar 20 '16 at 13:31
  • 1
    No-IP is there because you have a dynamic external address Mar 20 '16 at 13:35
  • 1
    @BharadwajRaju that isn't something I can explain in a comment. Look up how to set an Ubuntu computer up as a router, and you will find something Mar 23 '16 at 16:58

In addition to Zacharee1's answer, you should install either Fail2ban or DenyHosts (get the .deb from the Precise repos). You should not authenticate with keys if you are travelling. Use a "secure" password as well. Maybe set up a dedicated user account with reduced access for the times you don't need to be admin.

I would not touch the network settings on the Server, the static IP can be assigned from the router. The router ip address should be the "gateway" address assigned in DHCP. In the cases where it is not (!) the default address should be written underneath it somewhere. If you have changed this, you should have left the last value alone. So if you have a class C home network the address will be a.b.c.x where a.b.c matches all your other ip addresses and x is the trailing value from your router sticker. The ISP should have help pages for that in any case.

When you use a non standard port, avoid '22' as the final digits (8122, say). It leaves clues.

NB. you can access X based applications over SSH without VNC, another topic entirely.

  • could you please explain your comment: "You should not authenticate with keys if you are travelling. ", this goes against everything I have read so far. What is the reason behind you saying that? Mar 21 '16 at 9:18
  • Why should one not authenticate with keys when travelling? Authentication does not care if you are travelling or not.
    – user423626
    Mar 23 '16 at 2:00
  • You have not crossed a border lately ? Nor ever lost a phone ? Your keys will be shared. The same applies to certificates. Install one on an internet cafe machine at your risk. Keys provide instant access without a password, the client should be secured, not in your back pocket.
    – mckenzm
    Mar 24 '16 at 0:32

Instead of NoIP, I may suggest to write a script and run it repeatedly to save your IP in your cloud of choice (DropBox, MEGA, etc.). Something like:

wget  http://wtfismyip.com/text -O ~/Dropbox/myip6.txt 
wget  https://ipv4.wtfismyip.com/text -O ~/Dropbox/myip4.txt

And then run it with watch -n 1800 sh get_ip.sh which runs the script for you every half an hour.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.