February 12, 2015 by Daniel P. Clark

Setting up Remote SSH Access to your Ubuntu Box

I’ll keep this as short and simple as I may.  In my use case I have a Netbook that doesn’t build or run Rails very well, but I love editing with it.  My main computer runs Ubuntu 14.04 and is a great development environment handling server features like a champ.  For your PC that you want to access remotely you will need to install two things.

Secondly you will need to extract the ngrok package from https://ngrok.com/download.  Place the executable in your system path /usr/bin, or your home ~/bin directory if you have that as an executable path.

Third you need to have your SSH keys generated on both of your computer systems if you don’t have them already.  Follow the guide: Generating RSA Keys

After you’ve successfully generated your keys you need to add the public key from the remote computer (e.g. my netbook), to the one you will be accessing (the host) in the file ~/.ssh/authorized_keys .  Assuming that file does not exist yet on your main system you can copy your file directly over your local network with scp.  First you need to know what the IP address of your desktop computer is.  Open up a shell and run ifconfig.  You will need the IP address from either eth0 or wlan0 (these are the most common network interfaces).  Get the number at inet addr:192.168.*.*** and use that number on your client machine for the transfer.

Agree with the prompts and your file will be transferred.  This should be the minimal amount of setup to access your system remotely.  Just run ngrok in a terminal with.

You will see a ngrok url like tcp://ngrok.com:12345 . You will need to take those numbers as a port number parameter for your client connection.  Now you can login to your desktop PC from anywhere with.

You will then be asked for your SSH pass-phrase; which is what you created when you generated your RSA key originally on the client; enter it and you’re logged in!  Now you can use your favorite command line editor (pico, nano, joe, vim, emacs, etc).

Additional Notes

You can add which user account on the server has permission for SSH sessions by adding it to the /etc/ssh/sshd_config file then restart the server.

You can setup an ngrok configuration file to open multiple ports.  Good for viewing your Rails project on one port while ssh’d into another.  See the ngrok docs: https://ngrok.com/docs

When running ngrok on your server computer I prefer doing it from a separate login session (not just in a regular terminal window).  You can use the CTRL-ALT F1 through F6 keys for alternate command prompts (shells).  You can have ngrok running here without interfering with your desktop.  To get back to your desktop enter CTRL-ALT-F7.

There are many howtos on this subject online. I personally feel most give too much detail.  Feel free to look them up.  You have one for most any kind of situation.

Summary

A lot of the defaults work right out of the door so there isn’t too much configuration involved.  Besides, if you’re like me, you have your SSH keys ready beforehand.  For the longest time I’ve always wanted remote access to my home computers.  I had often failed in setting it up.  I have found that it is the simple things we overlook and miss that are the reason for this.  For example I tried ssh’ing in with ssh ngrok.com:12345 but could never connect.  That’s because the port needs to be defined earlier: ssh -p 12345 ngrok.com (-p is for port).  If I hadn’t of stumbled across that written online I may have never of had success.  So keep an eye out for the right pieces of information relative to your problems.  It’s easy once you figure them out.

I hope this was both enjoyable and insightful for you.  Have fun coding!  Please feel free to comment, share, subscribe to my RSS Feed, and follow me on twitter @6ftdan!

God Bless!
-Daniel P. Clark

Image by Brett Davies via the Creative Commons Attribution-NonCommercial-ShareAlike 2.0 Generic License.

#access#cli#ngrok#remote#secure#session#shell#ssh#ubuntu