How to SSH on Ubuntu – A Simple Guide 01/19/12

Lots has been written about SSH on Linux machines, but all too often it is written in technical jargon that confuses what is actually a very simple and infinitely useful technology. Here is a idiots guide to getting started with SSH in 2 minutes.

What is SSH and why should I know about it?

SSH stands for Secure SHell and gives a robust and secure way to control another computer (including servers) remotely.

You know how you can control your Linux box through the terminal command line? Well, if you have SSH set up, you can also control a remote computer over the network. This is really useful for taking control of things like webservers. If you use a host like Bluehost (Please note this is an affiliate link, but it is the hosting company I use and I recommend them totally) you can get a fixed IP address and SSH access which allows you to take control of the server using the command line.

To successfully have a SSH connection, you need an SSH Client and a SSH Server that speak to each other.

The SSH Client

The SSH Client is the piece of software that you have on the computer you are sitting in front of and typing on. It sends messages to the SSH server which is on the remote computer (such as the webserver). We’ll assume that there is already a valid SSH server up and running that you are trying to connect to.

In Ubuntu, there is a SSH client installed as standard and it is called Open SSH.

To use it, you simply open a terminal and proceed any command with “ssh”.

For example, if you would like to log in to your remote server, just use the command…

ssh username@mysite.myserver.org

However, as this is a blog that likes to keep things simple (and annoy a lot of the die-hard Linux geeks), I’m going to suggest a different tool… PuTTY.

PuTTY is a client program for SSH (among other things) and gives a neat little interface for making SSH connections. It is also in my opinion one of the best pieces of software ever written. It has been around for ever and can also be used on Windows without installation (just runs as a .exe). Learn this little guy and you will never look for another SSH client.

Install PuTTY by typing the following into a terminal…

sudo apt-get install putty

You will then find the PuTTY program among your other internet applications.

(When you start it up, you will be able to enter the ip address or name of the remote computer you wish to contact and click connect. You will then be asked for password etc. If you are going to be using SSH regular, you can save that connection as a profile which makes things easier).

 

The SSH Server

We’ve assumed up to now that you already have a SSH server to connect to. If this is not the case, then we need to install a SSH server on what will be the remote computer. (If you are using Bluehost, just speak to their support guys and they will do this for you).

If you have access to the computer that will be the remote computer, just open up a terminal and type…

sudo apt-get install openssh-server

That wasn’t too difficult now was it?

 

A couple of tests and a Security improvement

Let’s test that everything is up and running.

On the remote computer, start up PuTTY as mentioned above. Put int he local IP address of your machine (nearly allways 127.0.0.1 as shown below and click “Open”.

You will get a warning box talking about Keys and Certiicates, but just be like an iPad user and click accept to everything that pop-s up ;)

You now need to log in using your username and then your password for the remote machine.

That should be you logged in over SSH!!!

(You can now go off and see if you can use a different computer to log in to this system , remember that you will then need to use the external IP address of the remote computer when logging in via PuTTY).

 

A good way to test using your SSH connection is to make a little security update. The default port for SSH is 22 and some bad boys out there try and force their way in via this port. Let’s open the SSH config file and change that port to something else.

Via your PuTTY session, type in…

sudo vi /etc/ssh/sshd_config

This lets you edit the config file directly through the terminal. Use the arrow keys to find the line that shows the “Port 22″, press Shift+i on the keyboard and this lets you edit the file. change the port to whatever port you want, for example 3901. Press Ctrl+x and then :x to save the file and exit.

You then need to restart the SSH server to change the port. Again in PuTTY type…

sudo /etc/init.d/ssh restart

Next time you log into the SSH, via PuTTY you will need to change the SSH Port to the new one you set (i.e 3901).

 

There are lots of other security improvements you can make in this config file. If you know one, why not put it in the comments box below? (If you don’t know one, why not Like this article on Facebook and maybe your friends will know one ;) )

 

Care to Share?


You can leave a response, or trackback from your own site.

9 Responses to this article

 
Anonymous Bloke January 29, 2012 Reply

Hey dude, thx for posting this. As I suspected, the ssh part isn’t too bad. The problem must in the networks. I imagine that between 2 pcs on the same lan, all is good. Between 2 differents lans, you need to setup some port forwarding or something of the like. Between my PC at home and the server I set up inside my uni’s network…

Anyway, here’s a question. Can you start graphical applications? Can you even go crazy and run ‘startx’?

 
PuTTY Potty March 16, 2012 Reply

Hmm… Why would I install PuTTY, to show me the same thing that’s displayed in a terminal? PuTTY is so… “Windows”.

That’s like someone talking to me, but instead having another person relay to me, everything the other person says. Why? Just talk to the person direct. – Don’t need a middle-man.

Especially when the app your suggesting is buggy (like many other apps are): http://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/#pending

The post was great until it suggested using PuTTY. :/

 
Jason September 18, 2012 Reply

Putty is good to store all the different SSH servers you might connect to, so you don’t have to remember all the IP/hostnames and ports to connect to…

 
Marek November 19, 2012 Reply

Thanks a lot. I found this post while writing quick instruction explaining ssh config file in bit more details.

 
Felipe Sardi December 5, 2012 Reply

Help. Quick and simple. I’ll be changing all my ssh ports from now on I continuously get annoying attacks on my servers.

 
PPN January 4, 2013 Reply

All you have to do in ubuntu is to press CTRL + T or open the terminal (already installed), you won’t need any other software.
type in: ssh username@ip

That’s all, simple and done!

 
Rama October 11, 2012 Reply

You don’t need”PuTTY potty” on Ubuntu, just open a terminal and use the SSH command – VERY simple to do. :/

So to SSH into ubuntulinuxhelp.com, the command would be something like:

ssh your-username@ubuntulinuxhelp.com

 
peter December 19, 2012 Reply

What a dush….

 
stasta March 25, 2013 Reply

You can run graphical applications, if you pass the -X option to ssh.
ssh -X user@host
And graphical results of the programs you run remotelly will be dispayed on your pc.
note:
1) for some servers this -X may be -Y
2) the server may simply refuse this
3) this option will not transfer sound
4) your pc must have the X Window System. i.e. running linux (for mac you should manually install it)
5) it may be a litle slow

Leave a Reply

close comment popup

Leave A Reply