jayt80
Posts: 22
Joined: Tue Nov 08, 2016 11:53 pm

SSH Connection refused

Thu Dec 01, 2016 2:16 am

Hi there,

I've got a pi3 with raspbian installed working great. I have set the internal IP address as static.

I took out the SD card from the pi3 and put another SD card in with a clean install of raspbian.

I want to set this up different to the existing one for other purposes and use it on a pizero. Now I boot the pi3 up with the new clean install and I cannot SSH into it. It says connection refused (still using the same ip address)

How can I resolve this?

I'm using a mac and terminal to SSH into the pi.

Also if I put the original SD card back in, it works fine and I can SSH into.

jayt80
Posts: 22
Joined: Tue Nov 08, 2016 11:53 pm

Re: SSH Connection refused

Thu Dec 01, 2016 2:30 am

I've tried running this command:

Code: Select all

ssh-keygen -R nnn.nnn.nnn.nnn
Where nnn.nnn.nnn.nnn is the IP address of my pi

Then this : But it didn't work. Still says connection refused on port 22.

Tzarls
Authorised Reseller
Authorised Reseller
Posts: 246
Joined: Tue Feb 26, 2013 6:59 am

Re: SSH Connection refused

Thu Dec 01, 2016 4:04 am

I guess you´ve used the latest image of Raspbian for your fresh install? If you check the lastest blog entry then you´ll find the answer. SSH has been disabled by default for security reasons. There are 2 ways to re-enable it:

1. If your Pi has a display and keyboard you can run:

Code: Select all

sudo raspi-config
And use the Advanced options to enable SSH server.

2. If you are runnig your RPi headless just take your SD to the computer you used to flash it and in the /boot partition create a file called ssh. An empty file will do. Next time you RPi boots off that card it will find that file and "understand" that you want to enable the SSH server.

jayt80
Posts: 22
Joined: Tue Nov 08, 2016 11:53 pm

Re: SSH Connection refused

Thu Dec 01, 2016 4:42 am

Thanks! I totally forgot about enabling SSH.

Do I create a .txt file?
Tzarls wrote:I guess you´ve used the latest image of Raspbian for your fresh install? If you check the lastest blog entry then you´ll find the answer. SSH has been disabled by default for security reasons. There are 2 ways to re-enable it:

1. If your Pi has a display and keyboard you can run:

Code: Select all

sudo raspi-config
And use the Advanced options to enable SSH server.

2. If you are runnig your RPi headless just take your SD to the computer you used to flash it and in the /boot partition create a file called ssh. An empty file will do. Next time you RPi boots off that card it will find that file and "understand" that you want to enable the SSH server.

Tzarls
Authorised Reseller
Authorised Reseller
Posts: 246
Joined: Tue Feb 26, 2013 6:59 am

Re: SSH Connection refused

Thu Dec 01, 2016 4:43 am

AFAIK it´s just a file with the name ssh - no extensions.

jayt80
Posts: 22
Joined: Tue Nov 08, 2016 11:53 pm

Re: SSH Connection refused

Thu Dec 01, 2016 5:06 am

Tzarls wrote:AFAIK it´s just a file with the name ssh - no extensions.
Tried all of the above and still no luck???

This is getting annoying.

Tzarls
Authorised Reseller
Authorised Reseller
Posts: 246
Joined: Tue Feb 26, 2013 6:59 am

Re: SSH Connection refused

Thu Dec 01, 2016 5:12 am

Are you sure the Pi is using the same IP? Usually it´s that way, but better be sure.

jayt80
Posts: 22
Joined: Tue Nov 08, 2016 11:53 pm

Re: SSH Connection refused

Thu Dec 01, 2016 5:16 am

Tzarls wrote:Are you sure the Pi is using the same IP? Usually it´s that way, but better be sure.
Yip. What I ended up doing was plugging a usb keyboard into the pi. Don't have a mouse so used these commands to access terminal.

Alt + F2 to get the run dialog up
Run "lxterminal" to get the terminal window open.

Then from there sorted it.

Thanks for your help all the same. I got there in the end!

The file I created was a plain text .txt file ssh.txt. Not sure why it didn't work. Maybe I should of tried created a folder instead?

Tzarls
Authorised Reseller
Authorised Reseller
Posts: 246
Joined: Tue Feb 26, 2013 6:59 am

Re: SSH Connection refused

Thu Dec 01, 2016 5:19 am

No, no. Like I told you, it should be a file named just ssh, with no extension - meaning ssh without the ".txt" part!

Anyway, glad you have it sorted out.

jayt80
Posts: 22
Joined: Tue Nov 08, 2016 11:53 pm

Re: SSH Connection refused

Thu Dec 01, 2016 5:54 am

Tzarls wrote:No, no. Like I told you, it should be a file named just ssh, with no extension - meaning ssh without the ".txt" part!

Anyway, glad you have it sorted out.
Forgive my noobness but how does one create a file with no ext on a mac??

Tzarls
Authorised Reseller
Authorised Reseller
Posts: 246
Joined: Tue Feb 26, 2013 6:59 am

Re: SSH Connection refused

Thu Dec 01, 2016 6:05 am

Oh, you´re on a Mac - forgot that part. I guess you can try to edit the filename and erase the extension after creating the file. As far as I remember you´ll have to right click the file, then get information, and then you should be able to edit the filename. Don´t know if it´ll work - I haven´t touched my Mac boot partition for a couple of months now.

As a workaround you can use your original pi, create a file using it, then copy the file to the Mac, then copy it to the new Card. Or insert the new card (using an USB adapter) to the Pi running the old card and use the Pi to create the file directly into the /boot partition of the new card. I hope this makes sense!

User avatar
rpdom
Posts: 16719
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: SSH Connection refused

Thu Dec 01, 2016 6:07 am

jayt80 wrote:Forgive my noobness but how does one create a file with no ext on a mac??
Presumably you're running macos or OS-X, so you can do it the same was as you would in unix/linux.

Code: Select all

touch ssh
That will create a file of zero length, called "ssh". That is all that is needed.

Tzarls
Authorised Reseller
Authorised Reseller
Posts: 246
Joined: Tue Feb 26, 2013 6:59 am

Re: SSH Connection refused

Thu Dec 01, 2016 6:10 am

In case you don´t know what is rpdom talkign about, he means using the terminal to issue that command. You can find the terminal using spotlight (upper right corner).

jayt80
Posts: 22
Joined: Tue Nov 08, 2016 11:53 pm

Re: SSH Connection refused

Thu Dec 01, 2016 6:15 am

Thanks all. FYI doing that above command to create a non ext file on a mac creates it to your home directory incase there is some other noob like me wondering where the file gets created to!

Learning lots! Thanks again!

User avatar
rpdom
Posts: 16719
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: SSH Connection refused

Thu Dec 01, 2016 6:24 am

jayt80 wrote:Thanks all. FYI doing that above command to create a non ext file on a mac creates it to your home directory incase there is some other noob like me wondering where the file gets created to!
It will create the file in your current directory. I assumed you would cd to the boot partition of the SD card before running it, or you could give the full path to the file name.

Return to “Beginners”