ssh: connect to host raspberrypi port 22: Connection refused Error Fixed

I was setting up a new install of Raspbian Pixel and found I couldn’t login to the Raspberry Pi. It was giving me an error:

chewett@bunker-master:~$ ssh pi@raspberrypi
ssh: connect to host raspberrypi port 22: Connection refused

It turns out that recently the Raspberry Pi Foundation have changed the default setting for SSH and disabled it by default. Below are two ways to enable this useful feature.

Please remember that if you are enabling SSH you should also change the default password of the Raspberry Pi from raspberry. This can be done by running passwd as the pi user.

How to enable SSH for Raspberry Pi

There are two ways to enable SSH. If you are able to  connect your Raspberry Pi to a monitor and attach a keyboard and mouse you should follow the first steps. If you are unable to do this easily then I suggest using the second step.

Enabling SSH via the GUI

To enable SSH via the GUI you will need to attach your Raspberry Pi to a monitor, keyboard and mouse. Once this has been done you should open a console and run

sudo raspi-config

Once in the config editing screen you can use your keyboard to enter interfacing options then SSH. Here you are now able to enable SSH.

Once this has been done SSH will be accessible on your Raspberry Pi and you should not get the above error.

Enabling SSH by adding a file to the memory Card

If you are unable to connect your Pi to a monitor you can enable it using a file. To do this put your Raspberry Pi memory card in your computer and open its first partition. You should put a file called ssh in the boot partitionof the memory card. When the Raspberry Pi turns on it will enable SSH if this file exists, then delete the file. This will then let you SSH into your Raspberry Pi.

Why was SSH disabled?

There has been recent concern that Internet of Things devices are being used to create large botnet. This is partially down to the fact many use default passwords and some of these cannot be changed. Therefore the Raspberry Pi Foundation changed their default setting to disable SSH by default.

Hopefully this will help other users trying to access their Raspberry Pi by SSH.

Full details are written in a blogpost written by the Raspberry Pi Foundation.

 

One Comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.