12

I tried to use SSH to reach my Pi 3

ssh [email protected] 

but I get this message ssh: connect to host 192.168.100.3 port 22: Connection refused I install and install SSH but nothing has worked I tried to run

sudo ufw status verbose

but the output was :

Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip

To                         Action      From
--                         ------      ----
22                         ALLOW IN    Anywhere                  
22 (v6)                    ALLOW IN    Anywhere (v6)     

EDITED :

I tested the SSH status and it was active

sudo service ssh status

the output :

ssh.service - OpenBSD Secure Shell server
   Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enab
   Active: active (running) since Wed 2016-09-07 05:01:47 AST; 7h ago
  Process: 16337 ExecReload=/bin/kill -HUP $MAINPID (code=exited, status=0/SUCCE
 Main PID: 15478 (sshd)
   CGroup: /system.slice/ssh.service
           └─15478 /usr/sbin/sshd -D

Plz help

** I am using Ubuntu 16.04

10
  • You say "I am using Ubuntu" - I assume you mean MATE (you really should be more specific in aassking questions). Did you create a user pi?
    – Milliways
    Commented Sep 7, 2016 at 3:08
  • Try "sudo netstat -lpn" and see if anything is listening on port 22. You may also need to bounce the service (easier to reboot the pi; the process for restarting the service varies depending on version and distro).
    – BJ Black
    Commented Sep 7, 2016 at 4:49
  • @Milliways no I am not using MATE but Ubuntu 16.04 LTS. and I did not create a user pi
    – test me
    Commented Sep 7, 2016 at 9:16
  • @BJBlack the port is listening, can please explain what do you mean by 'bounce the service' ?
    – test me
    Commented Sep 7, 2016 at 9:23
  • OK, so if something is listening on tcp/22, there's no need to restart the service. I did just note that you mention two different IPs--192.168.0.3 and 192.168.100.3. Was one of those a typo?
    – BJ Black
    Commented Sep 7, 2016 at 9:26

5 Answers 5

1

There can be couple of simple reasons why you are not able to connect. But before all these steps make sure you are able to ping the machine without fallback / packet loss.

  1. check if ps -ef|grep "ssh"|grep -v grep . This should yield you the sshd daemon if its up. You can also check the status using systemctl/services sudo service ssh status

  2. Clear your keys from /home//.ssh/authorized_keys. Clear the entry which pertains to the previous raspberry connect. Sometimes its likely that the fingerprint (you would have seen [yes/No] option when you connect first time to a server or a linux pc over ssh) might be corrupted which is not allowing you to connect.

  3. You can look at other possibilities like firewall once you confirm the above steps.

25
  • Thank you, I tried to ping the machine and it is able to ping it without packet loss. 1- SSH server is active (running) . 2- I don't have authorized_keys file. 3- the port 22 is listening.
    – test me
    Commented Sep 7, 2016 at 9:46
  • @testme what's the user you have used to login to Ubuntu Mate 16.04
    – Varad A G
    Commented Sep 7, 2016 at 10:13
  • Sir I do not use Ubuntu Mate 16.04 but Ubuntu 16.04 LTS, and I only have one user
    – test me
    Commented Sep 7, 2016 at 10:23
  • @testme can you add the output of 'id' command from your Ubuntu 16.04 LTS.
    – Varad A G
    Commented Sep 7, 2016 at 10:33
  • sure uid=1000(jojo) gid=1000(jojo) groups=1000(jojo),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),113(lpadmin),128(sambashare)
    – test me
    Commented Sep 7, 2016 at 10:36
20

Make sure you have enabled SSH on your Raspberry Pi:

pi@raspberrypi$ sudo raspi-config 
>> Interface Settings 
>> SSH 
>> ENABLE

I think that will solve your problem.

3
  • 2
    thank you. Your solution was the only thing which worked for me
    – John D
    Commented Jan 19, 2018 at 5:01
  • Have to be logged in to do that, so good luck if you can't ssh for the first time on a headless config.
    – clearlight
    Commented Dec 21, 2018 at 8:48
  • Also, make sure you are using the US keyboard layout and your SSH your keys have permissions. Commented Apr 4, 2021 at 19:00
7

I have headless raspberry pi. This is what I did to enable SSH.

Remove the memory and put it to reader. On your boot drive (raspberry memory card) make a file named "ssh" without file extension name.

Alternative way on macos is to cd to the raspberry pi boot volume. Then type touch ssh

then put the memory card back to raspberry pi. connect the r-pi to network.

ssh on terminal using ssh [email protected]

1
  • 1
    Flashing raspbian onto the sd card created 2 partitions for me - one small 256mb and the rest of the card was taken by the big partition. I needed to touch ssh on the SMALL partition Commented Nov 9, 2021 at 19:55
2

I had a similar issue and I found an easy solution.

You may need to check your /etc/ssh/sshd_config file in order to allow connection. Check the PasswordAuthentication then type sudo service ssh restart in a terminal. You should be able to connect through ssh now.

1

Ubuntu or Ubuntu Mate does not come with a SSH server installed by default. Do you have installed it?

Try apt-get install openssh-server.

In other case, I would recommend to do a local connection to the raspberry. From a console inside your raspberry execute:

ssh localhost

You will skip on this way any firewall issue.

5
  • If local connection is not working but it is installed, check if the server is running with ps -e | grep ssh.
    – King Midas
    Commented Sep 7, 2016 at 5:33
  • Thank you, it is already installed. And actually I am trying to setup my Pi without a monitor (I want to use my laptop screen instead).
    – test me
    Commented Sep 7, 2016 at 9:26
  • I am not sure how you want to test the raspberry without a monitor. I would recommend to attach it to any screen/TV, login with your user, do a ssh localhost from inside the raspberry, and when everything works, unplug the monitor and use it as a sever.
    – King Midas
    Commented Sep 7, 2016 at 14:15
  • Also, if you have not any monitor, how are you able to finish the ubuntu installation? Are your sure it is installed? Are your sure that the openssh-server is installed in the raspberry?
    – King Midas
    Commented Sep 7, 2016 at 14:17
  • I have my PC (Ubuntu) and for the Pi I had the monitor only(TV), so I knew that I have installed the OS correctly onto my SD card. But finally I have the keyboard and the mouse, so I can setup the Pi. I did not success because I think there was not SSH in my Pi. And thank YOU so much !
    – test me
    Commented Sep 7, 2016 at 20:45

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