29 August, 2009
How to setup and use SSH to access your computer from anywhere - Ubuntu 9.04
One of the most powerful pieces of software available is SSH, SSH allows you to remotely control your linux box at the command line level from just about anywhere in the world with an Internet connection. Here I am going to briefly explain how to install SSH on your Ubuntu box, set it up and then connect to it.
Firstly we need to install ssh, to do that run the following command:
sudo apt-get install openssh-server openssh-client
OK, SSH is now installed, to check that it has installed correctly you are going to connect using SSH to your own computer, this is a simple test but shows that it is working, to do this type the command:
ssh -l YOURUSERNAME localhost
This should ask you to enter your password, when you have entered your password you will be returned to the command prompt, you have now connected via SSH to your own computer. You can now type the word "exit" and you will be returned to the command line where you started.
This means that SSH is working, now to make use of SSH you obviously need to be able to connect the the computer from other computers not just your own, to do this you use a slightly different command line where instead of localhost you use the IP address of the computer on the local network, so for example if the IP address of the computer you want to connect to is 192.168.1.10 the you would use the following command:
ssh -l YOURUSERNAME 192.168.1.10
If you have access to another linux box you may want to give this a try. Note that you will need to install the openssh-client package using the following command:
sudo apt-get install openssh-client
It is also possible to connect to your linux box from a windows machine using an application called putty, if you want to have a go at this then have a look on google for putty and some instructions how to use it.
Now you are at a stage where you can connect to your own computer on your local network, this can be very useful however what would be more useful is being able to connect to your computer over the Internet. Well you can, in order to do this you need to do a couple of things, firstly you need to set up your router to allows connections on port 22 to be routed to the IP address of the computer that you have set the SSH server to be on. If you are unsure how to do this then you will have to have a look on google to see how it is done with your specific router.
Once you have set up the routing of port 22 then you are ready to connect to the computer from over the Internet, however at the moment you will need to know the IP address given to you by your broadband provider and use that instead of the local IP address. This isn't really a problem if you have a static IP address however if like me you are on a dynamic IP address then it is a big problem. The solution to this problem is to use a service such as DYNDNS(www.dyndns.com) that allows you have a domain or sub domain pointing at your computer even if it has a dynamic IP.
This is accomplished in one of two ways, the first and easier way depends on what router you have, a large number of router come with DYNDNS support built in, all you have to do is enter the details of your DYNDNS account into the router. If your router supports this then go register at DYNDNS and setup an account(FREE). Fill in the details on the router and you are ready to rumble.
If your router doesn't support DYNDNS then you will have to use software to keep DYNDNS working, if you look on the DYNDNS website there is a list of software that will do this for you, choose whichever piece of software suits your circumstances and set it up following there instructions.
Well that is SSH setup and a brief description of how to connect to it, there is one other thing that can be very useful when setting up SSH, this is allowing port 443 to be used to connect to the SSH server. Port 443 is usually used for HTTPS communications, so if you are running HTTPS services you can't do this. If however you arn't using port 443 there are a number of reasons to setup SSH to use that port, the primary reason is that this allows you to access your SSH in buildings(University,College,Work,Internet Cafes,etc...) where they are blocking ports as none of these places will be blocking HTTPS ports.
In order to have you SSH server recognise port 443 you have to change the config files, to do this enter the following command:
sudo gedit /etc/ssh/sshd_config
In the file you will find a line that reads:
Port 22
now you can either change the 22 to 443 and only user port 443 or copy the line and paste another copy just below if with the number changed to 443, like so:
Port 22
Port 443
Save the file. Now that you have done that we need to restart the SSH server, to do that type the following command:
sudo /etc/init.d/ssh restart
That is it your SSH server will register port 443, you can test that out by using the following command:
ssh -l YOURUSERNAME -p 443 localhost
The -p specifies the port and so is needed whenever you are connecting on a non standard port.
OK, there is one more thing that you need to do, this is make your router forward port 443 to the computer like you did for port 22.
Well that is a basic run down of SSH, there are a lot of other things that can be done with SSH most notably SSH tunneling which I will do a tutorial on soon.
Oh and yes I did just tell you partly how to get around your works security :-)
------------------------------------------
NOTE: These articles are tutorials/general ramblings. I do not except responsibility for anything that goes wrong, be it a broken HDD, an entire computer or if you chop off your arms, follow anything I say on this site at your own risk.
------------------------------------------
Comments
Leave a comment