48

I don't have a screen for my Raspberry Pi. I want to SSH into it, but I get Connection Refused, so I presume SSH is not enabled.

As advised in other questions I have looked at enabling the boot_enable_ssh.rc script on the sd card. However I don't have a boot directory in my OS (or it is not visible via the card reader in my iMac) - 2012-12-16-wheezy-raspbian.img.

I have also tried issuing the following commands via a usb keyboard:

pi [enter]
raspberry [enter]
sudo /etc/init.d/ssh start [enter]
raspberry [enter]

But this hasn't worked. Now in some docs I see that raspi-config is the first thing to come on a newly booted RPi. Could someone tell me the keystrokes to enable SSH via raspi-config please? Or if I am on the wrong track, please advise. Thanks.

EDIT: In trying to follow this advice https://raspberrypi.stackexchange.com/a/1706/4373 I am not seeing an etc directory when mounting the SD card on my iMac. If I run ls from the terminal I only get the following:

bootcode.bin            fixup.dat               kernel.img            start.elf
cmdline.txt             fixup_cd.dat            kernel_cutdown.img      start_cd.elf
config.txt              issue.txt               kernel_emergency.img

Have I screwed up the imaging of the SD card?

  • Is plugging in a screen temporarily not an option? – Adam Houldsworth Jan 11 '13 at 11:25
  • Hi Adam, I don't have a cable for that. – Lemmy Jan 11 '13 at 11:30
  • I don't have my RPi at my current location, but as I recall, first time you boot Raspian Wheezy it shows a setup dialog (sudo raspi-config) where you can enable SSH. To see that, maybe you could follow the steps shown in this video: youtube.com/watch?v=nXvODj6YpAE ? I know it is a bit primitive approach, but I thought I would mention it :) – Lasse Christiansen Jan 11 '13 at 11:52

10 Answers 10

21

ssh is installed but not started by default on runlevel 2, the default for raspbian.
Rename /etc/rc2.d/ssh/K??ssh to /etc/rc2.d/ssh/S02ssh

EDIT
The sd card comes with 2 partitions. The 1st is vfat; the 2nd is ext3. You need some utility to access it from macosx.

1st google result for ext2 macosx:
http://blog.applegrew.com/2011/12/access-ext3ext2-file-system-on-mac-osx-lion-10-7/

Also check /var/log/auth.log

UPDATE 2016
The default raspberry distribution is now raspbian jessie, and uses systemd instead of sysvinit. The command line is now systemctl enable ssh.socket (although ssh should be enabled by default).

Note: I still have /etc/rc2.d/ssh/S02ssh and /var/log/auth.log after upgrading from wheezy to jessie; it may or may not be the case with a fresh jessie install.

  • Thanks, with the help of that link I can now see the partition. I don't have an ssh folder in rc2.d though. I have an S02ssh file (looks like a link) in the root of rc2.d. – Lemmy Jan 11 '13 at 13:17
  • OK, the S02ssh file is a link to init.d/ssh, so I presume SSH is already enabled? – Lemmy Jan 11 '13 at 13:20
  • K means kill; S means start. the init.d files are sourced with "stop" or "start" as argument depending on the name of the file.On my image from december 16 IIRC it was K. – M Noit Jan 11 '13 at 13:46
  • 1
    OK, I'm in now - I was trying to connect to the wrong ip address. The RPi wasn't showing up from the Mac terminal but I could see it from my router config. page. So I will mark this answer as correct as it helped point me to the solution and will be useful to other mac users looking at their SD cards. As a side issue it would seem that the current distribution has SSH enabled by default. – Lemmy Jan 11 '13 at 14:39
  • 1
    @Frankenstein : updated my answer, thanks for reprting. – M Noit Jun 2 '16 at 9:32
107

All you need is to place an empty file named 'ssh' onto the boot (FAT) partition of your SD card (no need to mount ext3). Tested with 2016-11-25-raspbian-jessie-lite.img.

Source: https://www.raspberrypi.org/documentation/remote-access/ssh/

More info about Nov '16 security update: https://www.raspberrypi.org/blog/a-security-update-for-raspbian-pixel/

  • 13
    This should be the accepted answer as of Dec '16. But please replace the link (which does not explain headless setup anyway) by the respective blog entry raspberrypi.org/blog/a-security-update-for-raspbian-pixel – flaschbier Dec 26 '16 at 15:31
  • 4
    The boot partition is the one with a start.elf file. The linked blog post confused me by calling it the /boot/ directory – raphael Feb 3 '17 at 3:40
  • I agree that this should now be the accepted answer. – Tyler C Apr 24 '17 at 16:20
  • this works , tested with - 2017-04-10-raspbian-jessie – Divyanshu Jimmy May 3 '17 at 6:06
  • Can confirm this works with 2019-04-08-raspbian-stretch – Oenotria 2 days ago
14

I had the same issues using the wheezy image.

The goal is to have the Pi boot up so you can ssh into it from another system, without having to ever connect a monitor and keyboard.

The problem is that while the SSH service is enabled, as noted above, it hasn't been configured yet, so you can't connect even if networking is running. Here are the tasks to get this working:

  1. Put the image on the SD card. (Covered elsewhere.)

  2. Ensure that you can determine the TCP/IP address once your Pi boots.

    hint: Look at your router to see what addresses have been assigned.

  3. Ensure that ssh will run and allow connections. Here's how I did it:

    a. Mount the second SD Card partition, the big one with the etc directory.

    b. Create a file etc/SSHFLAG

    c. Insert the following code into etc/rc.local just above the exit 0 line.

    if [ -e /etc/SSHFLAG ]; then
      /usr/sbin/update-rc.d -f ssh defaults
      /bin/rm /etc/SSHFLAG
      /sbin/shutdown -r now
    fi
    

    The idea is that when your Pi boots, the SSHFLAG file triggers it to reconfigure ssh (regenerating the keys and starting the service), remove the flag file so it only happens once, and reboot your system. Worked for me, YMMV

  • Nice solution to the problem. – 0xC0000022L Nov 15 '13 at 0:18
  • After that, I had to add /etc/init.d/ssh start into /etc/rc.local file, so the SSH service starts. – Iván Pérez Dec 3 '16 at 15:57
  • Iván: Not sure why my solution failed for you. Most likely explanations are a) typo, or b) changes to the rpi ssh package. Probably not worth debugging. Your solution might not work if the ssh service hasn't been configured yet (i.e., if the keys haven't been generated). – nortally Dec 19 '16 at 23:34
  • I had exactly the same experience as Ivan. ssh start worked. – Robert3452 Dec 25 '16 at 21:36
5

For headless setup, SSH can be enabled by placing a file named 'ssh', without any extension, onto the boot partition of the SD card.

  • 1
    Not "can be", but must be and since November 2016. The question is from January 2013. – techraf Jan 31 '17 at 6:35
2

From my yesterday experience: 2012-12-16-wheezy-raspbian.img (suggested as "official distribution") has SSH enabled by default. Get it from http://www.raspberrypi.org/downloads

You don't have to edit anything on card or start raspi-config in "blind mode".

Just make sure you use a correct IP address. Use your router DHCP web-interface to get IP from the table; use cable, not WiFi; make sure that SD card is OK (you may try another SD-card); make sure that SD card filesystem is OK (try to write image again and don't forget to "eject" card properly).

  • While the gist is true, the details aren't. ssh isn't enabled by default. Instead regenerate_ssh_host_keys is enabled, which will then enable ssh after generating the host keys and disable itself. Of course the net effect is the same. – 0xC0000022L Nov 15 '13 at 0:22
1

Got to this page via google after not using pi for a couple of months. After the recent update, ssh is disabled by default.

For the benefit of anyone doing a headless clean install of Jessie:

pi

raspberry

sudo nano /boot/ssh

test [or any other text]

[press ctrl-x]

y

sudo shutdown -r now

Done! All the best.

Remember to change your password and disable user 'pi' via ssh.

  • 1
    Why would anyone do this when /boot/ssh can be created using the same computer you have used to flash the SD card? Also, if you disable the default user, how do you login? – Dmitry Grigoryev Jan 31 '17 at 8:28
0

You have multiple partition on your SD card, and the files you are seeing from your Mac are those from the partition which is mounted as /boot/ on the Raspberry.

You should have another partition on the SD card that would store the root (aka /) partition, with all /etc/... stuff in it. Be sure to enable EXT3 filesystem support on your Mac to get this one available on Mac OS X.

0

Else I've just put this file on my boot partition and SSH started automatically. Link to boot_enable_ssh.rc

In fact, I've just found a Debian modification for the RPi on the net that had SSH enabled by default. I checked the boot partition and found this file!

  • 1
    tib20 has the answer for enabling SSH if you've lost it. Simply drop the file he linked straight into the boot partition and it works beautifully! Thank you for that. I had lost my SSH after changing the hostname on the pi. – user10440 Nov 6 '13 at 15:36
0

I hear a lot of "couldn't find it on the network" issues. I'm going to suggest running this to find all the machines with the ssh port open.

nmap 192.168.0.1/24 -p 22
# change the 192.168.0.1 part to match the first 3 octets of your ip address
# as seen via: ifconfig

This was very important to me as I do not have the admin password for the router I connect to. Now, I will say that even once I identified the ip address of my raspberry pi, I still couldn't connect even though nmap says the port was open. I immediately get a message of...

Connection closed by 192.168.0.116

I still haven't figured that one out.

0

Just to update, there is a much simpler method for doing this.

As of the November 2016 release, Raspbian has the SSH server disabled by default. >You will have to enable it manually. This is done using raspi-config:

Enter sudo raspi-config in the terminal, first select Interfacing options, then >navigate to ssh, press Enter and select Enable or disable ssh server.

For headless setup, SSH can be enabled by placing a file named 'ssh', without any >extension, onto the boot partition of the SD card.

Source

protected by Ghanima Apr 26 '17 at 5:58

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.