SSH is a good way to remote control a Linux machine. This beginners guide is meant to give you a quick start with it, so I will try to keep it as simple as possible.
If you don’t know what I’m talking about: just imagine you can send command line commands from your machine to another Linux machine, so that it feels like you are on the machine itself. That is, very simplified, what SSH is. A very good replacement for things like TeamViewer, with the tiny little downside, that you can only do command line things and nothing with a GUI. The big upside: it is very simple, uses almost no bandwidth and you can also control headless machines without a GPU.
First, you need to install openssh-server on the machine you want to remote control, so it can be reached via SSH. If you use for example Ubuntu Server, openssh-server should already be installed. If you use a Linux desktop version (like Ubuntu or Mint), you need to install it first with:
sudo apt install openssh-server
now your machine should be reachable by SSH!
Opening an SSH connection
First, we will open an SSH connection from inside your local network. Of cource, doing it from outside your LAN is even more useful. The additional steps required for that will be described later.
If you want to initiate an SSH session from a Linux machine, you use openssh-client. This should already be installed on any Linux. Find out the local IP adress of the machine you want to remote control with the command ifconfig. At the top you find your IP adress starting with 192.168.x.y. Then initiate an SSH connection from a different machine this way:
Replace “user” with the username you want to log in into the other machine, or remove “user@” if the user us the same on both machines. Replace x and y to match your IP. Confirm with “yes” when asked if you want to continue. You have now initiated a connection and can execute commands on the other machine. Close the connection with the “exit” command.
In Windows a SSH client is not already built in. One good option therefore is, to search for “Ubuntu” in the Microsoft store and install the Ubuntu app. This way you can run a (command line only) Linux inside Windows and simply proceed with the instructions above.
Another option is, to install a SSH client in Windows. Certainly the most used is PuTTY. Install it and open a SSH connection with it. Usage should be very intuitive…
Of course, using SSH from your mobile device is also possible. On my Android phone I use JuiceSSH. As I’m not familiar with iOS I have no specific advice for you, but there are more than enough apps available that you can use.
Port forwarding: opening an SSH connection from outside your LAN
The above solution works fine, if you have access to your local network. If not, you might still want to connect to your machines via SSH. The problem is, that a computer typically has no IP through which it can directly be reached from outside. Only your router has one.
So you have to tell your router, that every connection through port 22 (the standard port used for SSH) should be forwarded to a specific IP adress in your LAN (192.168.x.y).
This is a bit different for every router model. Access the configuration interface of your router and search for “port forwarding” or something similar. Then you forward port 22 to port 22 of the device or local ip adress you like. Every incoming SSH connection through port 22 will now be forwarded to the machine you specified.
Now you only need to find out the external IP adress of your router (e.g. by looking it up on whatismyip.com) and establish a SSH connection to this adress (use the ipv4 adress). Note that this will not work from inside your local network! You can for example use the mobile connection of your phone (disconnect from wifi) to test it.
Multiple machines in your LAN
Now what if you have more than one machine in your LAN, that you want to reach from outside? As you only have one public IP adress, you can forward port 22 only to one of your machines. The solution is, to simply use another port and use a different port for every of your machines. For example you can specify the following port forwardings in your router:
port 55221 -> machine1 port 22
port 55222 -> machine2 port 22
port 55223 -> machine3 port 22
port 55224 -> machine4 port 22
You are free in the port numbers you use. Just make sure you use a port number above 1023 (below that are the well-known ports that are often used) – ideally a port number above 49151. The highest port number that can be used is 65535.
Now you can connect to machine3 with the following command:
ssh <global ip> -p 55223
Or you use PuTTY and enter the specified port before establishing the connection.
Dynamic DNS: dealing with a changing IP
Now the problem is, that you probably have a dynamic IP adress, which changes from time to time (if you have a static ip adress you probably know). And while you can find out your dynamic IP adress fairly easy if you have access to the machine, the point is that you specifically need it, if you do not have access to your machine!
The solution to that problem is a Dynamic DNS provider. This way, you get a fixed domain, that always points to your current IP adress.
I use No-IP, which is free, with the only catch that you have to verify a free account every 30 days (you get an email notification). There are many other alternatives, just search for “ddns provider” on Google.
After registering you can register a domain (at No-IP for example in the form of yourname.hopto.org), which you can always point to the IP adress you have.
How do you tell your Dynamic DNS provider, which is your current IP? Your router can do this for you. Go to the configuration interface of your router, like in the part about port forwarding. Then search for “Dynamic DNS” or something similar. There you enter the data of your Dynamic DNS provider and your router will regularly send them your current IP.
Now you can open a SSH connection for example like this:
ssh yourname.hopto.org -p 55223
Now you should be able to control your crunchers with tools like Boinctui from whereever you like.
If you have any questions or problems setting this up, just write a comment – I will try to help!