0

I would like to SSH into my RaspberryPi connected with Ethernet cable using Ubuntu OS.

I believe that the Pi device is indeed connected to my Laptop, because:

  • after running

    ifconfig eth0
    

    command I get the result that

    inet addr:10.42.0.1
    
  • Then running

    ping 10.42.0.1
    

    with the Ethernet cable plugged in I get such results:

    PING 10.42.0.1 (10.42.0.1) 56(84) bytes of data.
    64 bytes from 10.42.0.1: icmp_seq=1 ttl=64 time=0.031 ms
    64 bytes from 10.42.0.1: icmp_seq=2 ttl=64 time=0.030 ms
    ...
    6 packets transmitted, 6 received, 0% packet loss, time 4997ms
    

    whereas running the same command with PC and Pi disconnected the results are:

    PING 10.42.0.1 (10.42.0.1) 56(84) bytes of data.
    From 10.128.128.128 icmp_seq=1 Packet filtered
    From 10.128.128.128 icmp_seq=2 Packet filtered
    From 10.128.128.128 icmp_seq=3 Packet filtered
    3 packets transmitted, 0 received, +3 errors, 100% packet loss, time 2000ms
    

Finally, I want to connect SSH to the device by running the command:

sudo ssh [email protected]

which, when the cable is plugged in reports:

ssh: connect to host 10.42.0.1 port 22: Connection refused

whereas, when the cable is plugged off reports:

ssh: connect to host 10.42.0.1 port 22: No route to host

Do these results mean that there is a successfull connection between two devices (my laptop and RaspberryPi) and that they are actually able to communicate?

If yes, how to proceed to ssh from Laptop into RaspberryPi?

Some of the issues I thought of are:

  • I am running incorrect command (i.e. it should be something different than

    sudo ssh [email protected]
    
  • some firewall or antivirus blocks the connection

could it be one of these?

3 Answers 3

2

Connection refused likely indicates that the port is being blocked.

If you have access to the pi, you may want to check the iptables rules:

    iptables -L

Or to flush the current rules..

    iptables -F

It could also be that SSH has been configured to run on a different port, in which case you could use something like nmap to investigate.

By default Raspbian has SSH enabled on initial install, on port 22, so it could mean that SSH simply isn't running.

4
  • So looking at your answer, does it mean that there should be an SSH program running on the actual Pi device? If I can't work on the pi directly (i.e. don't have keyboard / screen / mouse connected), can I somehow remotely (from my Laptop) check whether I am able to ssh to RaspberryPi? Commented Jan 20, 2016 at 23:50
  • If you are using the latest Raspbian release, SSH should be enabled by default. You could perform further investigation with a tool like nmap, or (if you haven't already) reboot it and hope for the SSHD service to start :) Commented Jan 20, 2016 at 23:52
  • Thx for your help so far, If you don't mind, I will ask more: after running nmap -p 22 -sV 10.42.0.1, I got the answer that Nmap scan report for 10.42.0.1 Host is up (0.000028s latency). PORT STATE SERVICE VERSION 22/tcp closed ssh so I assume, that ssh connection is prohibited, right? Would the best thing to do in this case is to get monitoring equipment (e.g. go to the lab and plug in screen, keyboard and mouse), from the RaspberryPi device itself start the ssh server, and make sure that it will start each time the Pi is booted? Commented Jan 20, 2016 at 23:59
  • @mercury0114 Using a screen/keyboard/mouse is certainly one solution that would allow you to bring up SSH or diagnose the issue. It isn't the only one though. If you do not mind losing data, or have a spare SD card, then you can install Raspbian Jessie onto it which will have SSH enabled by default. I'm not to sure if things like NOOBS, or previous releases have it enabled by default or not (YMMV). Commented Jan 22, 2016 at 0:24
0

Silly thought perhaps: where are you executing your ifconfig eth0 command? It looks like you're running it on your laptop, in which case 10.42.0.1 is your laptop's ip address, and you are trying to ssh to yourself. You need to know the ip address of the Pi, and ssh to that. It doesn't really explain why the ping changes when the cable is disconnected though, so this may be a red herring.

4
  • You seem to be right :-). I did execute ifconfig eth0 command. This morning I checked the IP address from the actual Pi and it was different. But how can I remotely obtain IP address of RasberryPi connected through Ethernet, given that IP changes each time the chip is rebooted? Commented Jan 21, 2016 at 9:21
  • If the IP changes every time, this means it must be getting it from a DHCP server. I'm stretching my knowledge here, but in many setups, the DHCP server (or another server somewhere) may be providing a dynamic DNS service, so you could look up the Pi's address using its name. Find the name by typing "hostname" on the Pi itself, and look it up from your laptop just by doing "ping PiName" (where "PiName" is the name you discovered). If you don't have a dynamic DNS, then this may be more difficult...
    – NiDaPo
    Commented Jan 21, 2016 at 9:30
  • hostname of the device is "raspberrypi", but then executing command ping raspberrypi on my laptop (with the Pi connected through ethernet) gave result "unknown host raspberry"... Also, in the lab each time I reboot RaspberryPi, it assigns the same IP address 10.42.0.21 to which I can ssh. Could I guess that back home on different network, the RaspberryPi will also get assigned the same address 10.42.0.21 and that I would be able to SSH into it? Commented Jan 21, 2016 at 14:07
  • No, it is very unlikely that you will get the same address when installed on a different network. The address will be assigned by your local DHCP server, which is probably provided by the router that connects you to your phone line, cable, or whatever. If you can't ping raspberrypi at home (it's worth trying), then try browsing to your router's address (192.168.0.1 is likely, but they do differ) and see if you can find a list of connected devices that tells you the IP addresses assigned.
    – NiDaPo
    Commented Jan 22, 2016 at 8:36
0

Ok, so I finally managed to:

  • 1) Connect RaspberryPi with laptop using crossover cable.
  • 2) SSH into RaspberryPi and get virtual terminal on my Laptop.
  • 3) Have Wifi on the virtual terminal.
  • 4) Have Wifi on my PC, Linux OS.

Here are instructions that worked for me:

From PC go to networks tab (on the top right), then click Edit Connections. In Ethernet, click on Wired connection 1 (or however the cable connection will be called on your laptop), then click Edit.... Go to IPv4 settings and set Method to be Shared to other computers.

Now go back to Network Connections tab, find your Wi-fi connection, click Edit... go to IPv4 settings again and make sure that the Method is set to Automatic (DHCP).

Then connect your RaspberryPi and Laptop with crossover cable, and boot the RaspberryPi up. A message Connected to wired connection 1 might appear briefly on the top right corner.

Finally, open the terminal, type

ssh [email protected]

and hope that the terminal asks for a password. If you succeed up to here, the most of the work is done. Enter the RaspberryPi password (try raspberry if you don't know it) and you will get a virtual shell of RaspberryPi.

Checking that Wi-Fi connection has been established one can in the SSH'ed shell type

ping 8.8.8.8

to check for arriving packets. If that succeeds type

ping [SomeWebsiteName]

to check that DNS works.

If you failed to get "enter password" request, some of the problems can be:

  • The /etc/network/interfaces files. My files are as follows.

    In Linux Laptop:

    auto lo
    iface lo inet loopback
    

    On Raspbian:

    # Note some lines might not be required
    
    auto lo
    iface lo inet loopback
    
    auto eth0
    allow-hotplug eth0
    iface eth0 inet manual
    
    auto wlan0
    allow-hotplug wlan0
    iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
    
    auto wlan1
    allow-hotplug wlan1
    iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
    
  • ssh program is not installed.

  • [email protected] does not detect the Pi's IP address.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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