Enabling remote SSH on Raspbian (Raspberry Pi)

I’m off to visit some family this weekend and I’d like to be able to use my Raspberry Pi while I’m away, so this will involve setting up SSH and making it visible remotely (outside my home network). I’d like to access it from my Android phone.

Enable SSH on Raspbian

Firstly install the SSH service by running this command:

sudo apt-get install ssh

Then start the service:

sudo /etc/init.d/ssh start

And now we want to make it start every time the Pi boots:

sudo update-rc.d ssh defaults

Next up, try a reboot and confirm everything works. Reboot by running sudo reboot.

Connecting to the Pi over SSH

To connect, you’ll need to know the IP address of your Pi. You can get that by typing sudo ifconfig. There will be a line starting “inet addr: …”, and the IP address is next to that.

I have connected to the Pi from my windows machine using PuTTY. Download here. Once you’ve got PuTTY installed, put it in a sensible location on your hard drive and open it. Fill in your Pi’s IP address, and in the Saved Sessions section, type “Raspberry Pi”. Click Save.

 You should be able to click Open and log in.

For convenience, I created a shortcut on my desktop that would open the session directly. Right click your desktop, and click Create Shortcut. Browse to putty.exe and create it. Then right click on the shortcut and go to Properties. Change the Target to this:

"C:\path\to\putty.exe" -load "Raspberry Pi"

 SSH from your Android phone

I installed a great app called ConnectBot. I tried a couple and this was the best. It’s open source and doesn’t have any ads. When you open it, just type in the address in the format “pi@:“. It’ll prompt you for your password.

Allow access from the internet

OK, I don’t recommend this. Everything up to now is in your own home network and is pretty much a walled garden, safe from bad people. Once you allow access from the internet, you’re potentially opening yourself up to hackers and I don’t have the knowledge to give proper security advice.

That said, I do know the first step is to change your password. Use the command passwd.

Next you need to open port 22 on your router, and set it to forward to your Raspberry Pi. This means that requests from the internet on that port will automatically go to the right place. On my Sky router the set up looks like this:

Next you will want to set the IP address of your Pi to be static, so that it doesn’t change when you reboot. In your router interface, check the list of attached devices and note your Pi’s MAC address:

Then add an entry to the list of reserved IP addresses:

Now you should be able to SSH into your Pi from your laptop (using PuTTY) or phone (using ConnectBot) and instead of entering the 192.168.0.x address, you can use your public broadband IP address.

Finally, if you don’t have a public static IP address (in other words, your ISP keeps changing your IP address) then how do you know what it is? You need to set up a DNS service on your Pi that will regularly check what the network public IP address is, and keep a domain name up to date. Then you can connect using a domain name instead of an IP and it’ll automatically resolve to the correct IP. There are lots of ways to do this – click here for some ideas.

3 thoughts on “Enabling remote SSH on Raspbian (Raspberry Pi)

  1. Pingback: Samba olé – Clickomania

  2. I needed to ‘touch ssh’ in the /boot folder before these instructions started the ssh server on boot. I’m on Raspbian 10.

Leave a Reply to suba suba Cancel reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>