I’ve got a computer in my cellar. It’s where media lives, and a bunch of little web apps that I’ve written to do stuff that I care about. It’d be handy to be able to get at those little web apps from my phone, wheresoever my phone is. However, I don’t want to just expose the server to the vagaries of the web. So, a few steps.
Make sure the server can be connected to by SSH
SSH, as I imagine most readers know, is the secure shell; a way to connect to a computer’s command line as if you were sitting at it. (For Ubuntu computers, anyway. I think Macs have ssh too; Windows computers generally don’t.) I’m fairly sure that ssh comes out of the box on Ubuntu, but if not there’s a page in the help guide about setting it up.
Make sure that I can connect to that server over SSH from outside
Like most people, I’ve got a router which connects to my ISP and provides wired network and wifi to the house, and the server computer in the cellar is connected to it. However, you can’t connect to computers inside my house from outside the house: your connection gets as far as my router and then stops. The way to change this is port forwarding; when you try and connect to my router on a particular port, it actually sends that connection through the router and into a particular computer in the house. SSH runs on port 22, so set up the router so that it forwards port 22 on itself to port 22 on the server computer. (How to do this is very router-specific. RTFM.)
Give your house a name on the internet
Normally, while the house — while the router, I should say — is connected to the internet, it can be connected to with its IP address; a string of digits like a telephone number. Of course, these are hard to remember, which is why everyone uses domain names: ubuntu.com rather than 18.104.22.168. The IP address for your router will occasionally change (most ISPs charge you extra for a “static IP” which does not change), so you want something which will give your router a domain name, an easy-to-remember alias for the IP address, and keep it up to date when the IP address changes. For this I use DynDNS.org who I’ve had an account with for years. Sign up for an account and you get a name, like whatever.dyndns.org, which you can point at your IP address.
Keep the domain name up to date when your IP changes
To keep the name up to date, I installed ddclient on the server computer, and taught it about my DynDNS account. Now, when my IP address changes, ddclient will update dyndns.org so that my chosen domain name correctly points at the new IP address.
Connect from your phone
I installed vSSH Lite from the iPhone app store. I can now connect from my phone to mychosenname.dyndns.org and log in with my username and password, and I’ve got the command line on my server!
More port forwarding, to connect to the web server
But I don’t really want the command line: what I want is to connect to the web apps on the server. For this, use SSH’s port forwarding feature. This is a bit different from the port forwarding above; instead of the router passing connections through itself, what this does is make a local port on your phone connect to a remote port on the server. So, I connect to my server with SSH, and port forward local port 8080 to remote port 80. Then, I can open up iPhone Safari and browse to http://localhost:8080/ and I’m actually connecting to the web server on my computer in the cellar. Which was the goal.
Techie people will already know this stuff, of course. But it’s quite cool to be able to glue together all these little parts.