ssh connection refused on Raspberry Pi [closed]
Asked Answered
A

2

112

I realize this question has already been asked in some different ways, however it doesn't seem like any of the ways I've come across have worked to fix this problem, so here it goes:

I'm trying to connect to my raspberry pi 3 raspbian setup via ssh on my laptop, but although I have the correct ip address, I keep getting the error:

ssh: connect to host xxx.xxx.xx.x port 22: connection refused.

This is unusual because when I try to ping that address, it works fine. Is there anything I can try to figure out what's wrong?

Also keep in mind I am relatively inexperienced with bash in linux, so inclusion of any specific commands with a description of what they do would be greatly appreciated.

Athene answered 25/12, 2016 at 4:5 Comment(3)
Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See What topics can I ask about here in the Help Center. Perhaps Super User or Unix & Linux Stack Exchange would be a better place to ask. Also see Where do I post questions about Dev Ops?Cornstarch
There is also a Raspberry Pi Stack Exchange.Dam
Since it's a bit buried lower down, but important for most people "For headless setup, SSH can be enabled by placing a file named ssh, without any extension, onto the boot partition of the SD card from another computer."Atelier
D
258

Apparently, the SSH server on Raspbian is now disabled by default. If there is no server listening for connections, it will not accept them. You can manually enable the SSH server according to this raspberrypi.org tutorial :

As of the November 2016 release, Raspbian has the SSH server disabled by default.

There are now multiple ways to enable it. Choose one:

From the desktop

  1. Launch Raspberry Pi Configuration from the Preferences menu
  2. Navigate to the Interfaces tab
  3. Select Enabled next to SSH
  4. Click OK

From the terminal with raspi-config

  1. Enter sudo raspi-config in a terminal window
  2. Select Interfacing Options
  3. Navigate to and select SSH
  4. Choose Yes
  5. Select Ok
  6. Choose Finish

Start the SSH service with systemctl

sudo systemctl enable ssh
sudo systemctl start ssh

On a headless Raspberry Pi

For headless setup, SSH can be enabled by placing a file named ssh, without any extension, onto the boot partition of the SD card. When the Pi boots, it looks for the ssh file. If it is found, SSH is enabled, and the file is deleted. The content of the file does not matter: it could contain text, or nothing at all.

Dam answered 25/12, 2016 at 4:11 Comment(13)
Thank you, this worked perfectly! That is a rather strange decision to disable ssh by default considering that's one of the main ways to interface the device...Athene
This "disabled by default" is likely for security. You don't want to leave a method of access lying around unless you know that you need it. If it's connected to a network, it would be accessible from the network. I do think they still have a serial (UART) login connection enabled by default. I guess the difference there is that you would need physical access to the board to use it.Dam
Any way to do this in a headless config? The tutorial says to place a file named "ssh" in the boot directory, but this does not work.Calcicole
@Calcicole I suggest looking (or asking) on the Raspberry Pi Stack Exchange. This question has been voted off-topic for StackOverflow (which is for programming questions).Dam
For others that may find this, the issue is that if the RPi is not restarted properly before the first successful SSH connection, the SD card will have to be re-imaged. Once I did this and added the empty "ssh" file, it worked.Calcicole
To enable ssh on raspberry pi : raspberrypi.org/documentation/remote-access/ssh/README.mdCammiecammy
If you're going headless, enable SSH by placing a file called ssh, (empty, without extension), in the root folder of the SD card. When the unit boots, ssh will be enabled, and the file is deleted.Indoor
Wow, this is a dumb move on the RPi community's part. So now even if I download the desktop-less version, I still need to setup a desktop just to enable SSH? What a pain.Jasisa
It would have made more sense if the ssh file contained a user name and password to enableLipson
@Athene Jeff & Cerin: The default user (pi) and password (raspberry) are widely known. If one would connect his raspberry for the first time, until he changes the password he will be vulnerable to attacks. That's why ssh is initially disabled and you get a change to set the password first before you enable it. On a headless pi you can generate your own new password and write it to the /etc/shadow passwords file.Kiernan
What if I typed the wrong password and got blocked? How can I erase the "blocked" list?Bradberry
🤷🏻‍♂️ ssh is opened, but still can not connect, what's wrong with that?Suburbanize
In April 2022 the procedure has changed as announced in the a blog post on raspberrypi.com: "To set up a user on first boot and bypass the wizard completely, create a file called userconf or userconf.txt in the boot partition of the SD card; [...] This file should contain a single line of text, consisting of username:encrypted- password – so your desired username, followed immediately by a colon, followed immediately by an encrypted representation of the password you want to use." (raspberrypi.com/news/raspberry-pi-bullseye-update-april-2022)Cystocarp
U
-9

I think pi has ssh server enabled by default. Mine have always worked out of the box. Depends which operating system version maybe.

Most of the time when it fails for me it is because the ip address has been changed. Perhaps you are pinging something else now? Also sometimes they just refuse to connect and need a restart.

Urfa answered 25/12, 2016 at 4:12 Comment(1)
Appears to be disable by default out of the box now. The error here is "connection refused" not a delay followed by a "operation timed out" - which would occur if the ip changed on you. Granted another device could have taken the ip and be refusing the connection.Homestead

© 2022 - 2024 — McMap. All rights reserved.