12

I tried to use SSH to reach my Pi 3

ssh pi@192.168.100.3 

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

test me
  • 125
  • 1
  • 1
  • 6
  • 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 Sep 07 '16 at 03: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 Sep 07 '16 at 04:49
  • @Milliways no I am not using MATE but Ubuntu 16.04 LTS. and I did not create a user pi – test me Sep 07 '16 at 09:16
  • @BJBlack the port is listening, can please explain what do you mean by 'bounce the service' ? – test me Sep 07 '16 at 09: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 Sep 07 '16 at 09:26
  • @BJBlack I wrote like that here by a mistake – test me Sep 07 '16 at 09:57
  • Alrighty. You've checked the listener (there is one in netstat) and the firewall (port's open), so the network outside the pi is the only other hole. What IP are you ssh'ing from? Another 192.168.100.x? Otherwise, check "ssh pi@localhost" from the pi itself. – BJ Black Sep 07 '16 at 10:03
  • @BJBlack Thank you sir , but I do not have a monitor for my Pi I am trying to setup by my PC – test me Sep 07 '16 at 10:25
  • I'm confused then. If you can't log onto your pi at all, where are the ufw, service status, and netstat info coming from? – BJ Black Sep 07 '16 at 10:28
  • I am connecting my pi to the router, and I got the ip from sudo nmap -sn 192.168.100.* and now I am lost. but I really appreciate your help – test me Sep 07 '16 at 10:42

5 Answers5

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.

Jacobm001
  • 11,898
  • 7
  • 46
  • 56
RPi-Coder
  • 201
  • 2
  • 3
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 pi@raspberrypi.local

r_19
  • 171
  • 1
  • 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 – walnut_salami Nov 09 '21 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.

Aurora0001
  • 6,308
  • 3
  • 23
  • 38
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.

King Midas
  • 208
  • 1
  • 2
  • 13
  • If local connection is not working but it is installed, check if the server is running with ps -e | grep ssh. – King Midas Sep 07 '16 at 05: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 Sep 07 '16 at 09: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 Sep 07 '16 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 Sep 07 '16 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 Sep 07 '16 at 20:45
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.

Varad A G
  • 848
  • 6
  • 17
  • 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 Sep 07 '16 at 09:46
  • @testme what's the user you have used to login to Ubuntu Mate 16.04 – Varad A G Sep 07 '16 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 Sep 07 '16 at 10:23
  • @testme can you add the output of 'id' command from your Ubuntu 16.04 LTS. – Varad A G Sep 07 '16 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 Sep 07 '16 at 10:36
  • @testme did you try ssh jojo@192.168.100.3. if not can can you try once and then if you still face issue we can dig in more. – Varad A G Sep 07 '16 at 10:49
  • I did it, and this is the result ssh: connect to host 192.168.100.3 port 22: Connection refuse – test me Sep 07 '16 at 10:52
  • I am sorry but how can I find it ? – test me Sep 07 '16 at 11:02
  • I am from which machine you are trying to ssh (windows/linux) machine. just to understand the environment. – Varad A G Sep 07 '16 at 11:06
  • ah okay, I am trying from linux – test me Sep 07 '16 at 11:07
  • can you type the below commands (cd; cd .ssh; ls) and paste the output. – Varad A G Sep 07 '16 at 11:09
  • sure :jojo@jojo-Latitude-E5430-non-vPro:~$ cd; cd .ssh; ls known_hosts jojo@jojo-Latitude-E5430-non-vPro:~/.ssh$ – test me Sep 07 '16 at 11:11
  • @testme can you execute the cat known_hosts and paste the output. – Varad A G Sep 07 '16 at 11:13
  • sure jojo@jojo-Latitude-E5430-non-vPro:~/.ssh$ cat known_hosts |1|zuxX56GiXGymVkRBRbHGCSCP5BY=|jbWSNMDFnsbBuBOgfIav0G7WZGs= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJBgKrY57hBH/J9TjYMS9Hx9jW/lKG9jUb7zkgGyMWbi1y692ANLP38hF3n0JDY7DYDSqcFg/BpcdTDFtf+hjQ0= |1|z/w8DyCaSZNC5TDNb+jwcYydZjw=|gCEHs+uMN901nmbj0EQsrKmEGYY= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJBgKrY57hBH/J9TjYMS9Hx9jW/lKG9jUb7zkgGyMWbi1y692ANLP38hF3n0JDY7DYDSqcFg/BpcdTDFtf+hjQ0= jojo@jojo-Latitude-E5430-non-vPro:~/.ssh$ cat known_hosts – test me Sep 07 '16 at 11:17
  • @testme do the following steps 1. cp known_hosts /tmp; 2. vi known_hosts; 3. delete all the contents from the file; 4. ssh jojo@192.168.100.3 and let me know – Varad A G Sep 07 '16 at 11:18
  • Sir, in step 3 I do not know how can delete them ?https://s12.postimg.io/kdc23qrd9/Screenshot_from_2016_09_07_14_26_47.png – test me Sep 07 '16 at 11:28
  • just press "dd" on your keyboard to delete the content once you are inside the file after second command. Keep pressing "dd" untill all the content is deleted. once deleted press "Esc" on your keyboard ":wq!" and "Enter" – Varad A G Sep 07 '16 at 11:30
  • I deleted them I and I typed ':wq!' then pressed 'Enter'..and the output for step 4 is ssh: connect to host 192.168.100.3 port 22: Connection refused – test me Sep 07 '16 at 11:36
  • @testme can you paste the out of this command: cat known_hosts – Varad A G Sep 07 '16 at 11:37
  • there is no output – test me Sep 07 '16 at 11:38
  • @tstme Looks like this issue is tied up to this file. usually it works when you clean up this file and then new keys come in. I am going off for sometime. Hope it would work for you. – Varad A G Sep 07 '16 at 11:38
  • Thank YOU so much for trying to help me ! I hope it would work too – test me Sep 07 '16 at 11:54
  • @testme Can you try this command. I had a similar issue today and I fixed it by running the command on my raspberry pi "sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT" and sudo service sshd restart – Varad A G Sep 08 '16 at 07:11
  • It worked finally, the problem was from the Pi, sorry for taking you time, and thank you again. – test me Sep 08 '16 at 09:58
  • @testme Good to hear that. – Varad A G Sep 08 '16 at 10:30