Page 1 of 1

SSH connection refused

Posted: Sun Apr 17, 2016 12:19 pm
by Azrae^^l
Hi all,

I bought a raspberry pi 3 and I've installed Raspbian and Openelec with Noobs. Everything works fine with Openelec, but ssh in Raspbian.

It is supossed to be enabled by default in the latest version of Raspbian, right? In fact, when I go to Rapberry Configuration menu ssh appears as enabled. Unfortunately I don't have a keyboard so I can assure it with some terminal command, I only have a screen (tv) and a mouse. That is why I want to connect via ssh with my linux laptop.

When I try to ssh -vvv a get this:

Code: Select all

ssh -vvv pi@192.168.1.134
OpenSSH_7.2p2, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: resolving "192.168.1.134" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to 192.168.1.134 [192.168.1.134] port 22.
debug1: connect to address 192.168.1.134 port 22: Connection refused
ssh: connect to host 192.168.1.134 port 22: Connection refused
Is there any configuration that I can write plugin in the sd card in my laptop? I've been reading a lot, but I can't found a solution. I've looked at runlevel 2, and /etc/rc2.d/ssh/S02ssh is alredy named that way.

Any advice or help??

Thank you in advance!

Re: SSH connection refused

Posted: Sun Apr 17, 2016 2:00 pm
by B.Goode
Azrae^^l wrote: Any advice or help??
I, and probably thousands of other people, have found that ssh does indeed work 'out of the box' with Raspbian. No reconfiguration of fiddling with runlevels is needed.

Are you sure that you have correctly identified the IP address for your RPi?

Re: SSH connection refused

Posted: Sun Apr 17, 2016 2:13 pm
by klricks
Check the firewall on your laptop. Most Linux distros have SSH disabled by default.

Re: SSH connection refused

Posted: Sun Apr 17, 2016 2:35 pm
by stderr
Azrae^^l wrote:Hi all,

I bought a raspberry pi 3 and I've installed Raspbian and Openelec with Noobs. Everything works fine with Openelec, but ssh in Raspbian.

It is supossed to be enabled by default in the latest version of Raspbian, right? In fact, when I go to Rapberry Configuration menu ssh appears as enabled. Unfortunately I don't have a keyboard so I can assure it with some terminal command, I only have a screen (tv) and a mouse. That is why I want to connect via ssh with my linux laptop.

When I try to ssh -vvv a get this:

Code: Select all

ssh -vvv pi@192.168.1.134
OpenSSH_7.2p2, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: resolving "192.168.1.134" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to 192.168.1.134 [192.168.1.134] port 22.
debug1: connect to address 192.168.1.134 port 22: Connection refused
ssh: connect to host 192.168.1.134 port 22: Connection refused
This message is the same as you'd get if you were going to the wrong ip that exists but just isn't running ssh. This might be an older router or a windows box or some phone or any number of other ip devices.

Can you ssh back to the machine you are on? Is it set up to receive incoming ssh? Do you have an android phone you could load in sftp or sshd so you could test with that? If you google rule of three, there are a lot of hits. In this case, if you have three devices (or more), you can quickly figure out which ones are working and maybe which one isn't. With just two, is the problem your laptop or the pi? You could waste a lot of time wondering if the problem was the pi and find out it was the laptop or the other way round.

Re: SSH connection refused

Posted: Sun Apr 17, 2016 4:49 pm
by DougieLawson
Connection refused means you've reached a perfectly valid IP address (on your LAN segment), but port 22 isn't open.

Three reasons that could happen
1. wrong IP address
2. sshd not running on the right IP address
3. iptables blocking your source address or your target port

More likely reason is #1.

Re: SSH connection refused

Posted: Mon Aug 15, 2016 7:33 am
by IgorGanapolsky
What if I registered a subdomain with Google Domains. Shouldn't I be able to ssh into port 22 after that? I mean, I already configured my ddns daemon...

Re: SSH connection refused

Posted: Tue Jan 03, 2017 12:45 am
by kanekin
Although this question was posted earlier than the change, it still pops up as one of the top hits on google search.
There was an important change in November 2016
As of the November 2016 release, Raspbian has the SSH server disabled by default. You will have to enable it manually.
For anyone who is facing "SSH connection refused" using Raspbian released after November 2016, you need an additional step to enable ssh.
For headless setup, SSH can be enabled by placing a file named 'ssh', without any extension, onto the boot partition of the SD card.
You could do this by:

Code: Select all

cd /Volumes/disk<disk# from diskutil>
touch ssh
Here is the reference: https://www.raspberrypi.org/documentati ... ccess/ssh/.
I hope this helps anyone who is struggling with this issue after November 2016.

Re: SSH connection refused

Posted: Mon Feb 06, 2017 10:31 am
by KjeldFlarup
Thanks kanekin

Now I miss the +1 button on this Forum.

Re: SSH connection refused

Posted: Sun Feb 12, 2017 10:27 am
by Gerrelt
+2

Thanks kanekin!

For the people using Jessie Lite and Windows for creating the SD card: You can just add a (empty text) file name "ssh" onto the root of the SD card. Then SSH will be enabled on boot.

Re: SSH connection refused

Posted: Mon Feb 13, 2017 7:58 pm
by saper_2
Hi,

I just grabbed latest raspbian (2017-01-11)... And I had to use google, 4th link, I'm here.
This is just bad joke to disable ssh by default, there was always ssh on pi, it was just done to mess up with users (or just me? anyway you managed to make me angry). So if you disabled then UNINSTALL SSH demon - why to keep it now? (this is rhetorical)


OK, now I'm calm, so I had to go to my dad computer and steal his keyboard, so I just could enable back this stupid "idea"...

The 3rd option to enable SSH:
Faster than playing with raspi-config is just enable service and start if from console so make this quick:
1. I hit CTRL+ALT+F1 to switch to console (tty1)
2. Enable SSH deamon:

Code: Select all

sudo systemctl enable ssh.service
3. Start sshd deamon:

Code: Select all

sudo systemctl start ssh.service
4. I'm done, and I can return keyboard to my dad computer. Now I can log-in from my laptop.
enable_ssh.jpg
photo of tty1
enable_ssh.jpg (36.17 KiB) Viewed 185946 times
-------------

I get the point of securing RPi from bots but, this is not your problem RPF, it is the user problem. If he/she don't have a slightest idea about security on public network (internet), then, uh, well..... :roll:
Everybody is responsible of his/her own actions (and the results of them).

I just wanted to express my opinion, I don't want, nor I'm interested in any discussion about this matter. And yes, I am a self centered [xxxxxxxxxx]. :twisted:

Re: SSH connection refused

Posted: Tue Feb 14, 2017 12:03 pm
by Cancelor
SECURITY!

If I can get access to your RPi, using public password and name then I can get access to your home network.

When I have access to your home network then I can get access to your PC and other devices.

Then I can empty your bank account and tell when you are not at home and empty that as well.

Then you blame the raspberry pi foundation, and they get a bad name.

What would you do if you wanted to be a responsible supplier?

Re: SSH connection refused

Posted: Tue Feb 14, 2017 12:05 pm
by Martin Frezman
heh heh.

As flawed as all that logic is, it probably is what drove the decision.

So, yes, you are correct in your explanation.

Re: SSH connection refused

Posted: Thu Jun 29, 2017 9:57 pm
by poxley
I've been working on this for quite awhile, and I was finally able to get things working. I hope my solution may be helpful to someone else.

I was following the instructions at https://learn.adafruit.com/turning-your ... net-gadget but was unable to complete a connection. Both devices reported the USB-as-Ethernet, but I was getting connection refused messages. The instructions imply that a static IP is optional, but they provide instructions on setting a static IP if you want. I was trying to use the dynamic IP and getting nowhere, but as soon as I set a static IP (and rebooted the Pi), the Ethernet over USB worked. I can now SSH and VNC over the USB connection and <hostname>.local is working as well.

(static on Raspberry Pi side: https://learn.adafruit.com/turning-your ... g-fixed-ip)
(static on PC side: https://learn.adafruit.com/turning-your ... st-machine)

I hope this solves the problem for some others as well!

Re: SSH connection refused

Posted: Wed May 01, 2019 9:13 pm
by scostesu
If you are booted into raspbian, then you can put the empty file "ssh" in the boot directory like this:

Code: Select all

sudo touch /boot/ssh
TL;DR
  • sudo because you have to elevate to root
  • touch will create a file if it doesn't exist (and just update the access time if it does)
  • /boot/ is the boot directory on the root of the OS
  • ssh is the name of the file to "touch"