简体   繁体   中英

How to access the Raspberry Pi Zero though SSH

I'm trying to remotely access my Raspberry Pi Zero using SSH. The raspberry's OS is Raspbian Jessy Lite (so no desktop enviornment, only the command line). I connected the raspberry to the Internet using an Android phone with USB-tethering (the raspberry pi zero doesn't have an ethernet port, I tried with a Zydas WiFi dongle but I couldn't make it work) so running ifconfig outputs:


lo      Link encap:Local loopback
        inet addr:127.0.0.1  Mask:255.0.0
        inet6 addr: ::1/128 Scope:Host
        UP LOOPBACK RUNNING  MTU:65536  Metric:1
        RX packets:0 errors:0 dropped:0 overruns:0 frame:0
        TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
        collisions:0 txqueuelen:1
        RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

usb0 Link encap:Ethernet HWaddr 02:64:78:7c:65:6f inet addr:192.168.42.172 Bcast:192.168.42.255 Mask:255.255.255.0 inet6 addr: fe80::64:78ff:fe7c:656f/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:68 errors:0 dropped:0 overruns:0 frame:0 TX packets:111 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:5959 (5.8 KiB) TX bytes:18109 (17.6 KiB)

I'm trying to access the raspberry from a linux computer (running debian 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt25-2 (2016-04-08) x86_64 GNU/Linux ), I use the command:

ssh pi@192.168.42.172

But that results in an error:

ssh: connect to host 192.168.42.172 port 22: Connection timed out

I have enabled SSH on the raspberry using the command:

raspi-config

Running the ssh command on the raspberry works but it times out when I use it in the linux computer. I also tried to ping the raspberry, this is the result:


debian:~$ ping 192.168.42.172
PING 192.168.42.172 (192.168.42.172) 56(84) bytes of data.
^C
--- 192.168.42.172 ping statistics ---
844 packets transmitted, 0 received, 100% packet loss, time 843007ms

Also, here is the file /etc/network/interfaces:


auto lo
iface lo inet loopback

iface eth inet maual

allow-hotplug usb0
iface usb0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

UPDATE: I did what JNevill said and tried connecting my debian computer to the phone's network, since the phone only has one USB port I connected through bluetooth. But I still got the same error. I also tried to use the Port Forwarder app to forward the 2222 port to the 22 in the raspberry so that when I run the command:

ssh pi@192.168.1.46 -p 2222

The Android phone should be forwarding that to the raspberry's 22 port (I also tried forwarding 22 to 22 but I got an error: "EACCESS: Permission denied"). Doing that I also got a Connection Timeout. Maybe it's because the app is not working, when I use the command:

ssh root@192.168.1.46 -p 2222

I get a different error: Connection refused . It doesn't even prompt for a password. Also, the Android phone is not rooted, so maybe that's why.

192.168.42.172 is a local IP that is assigned to the pi from your phone. The phone is acting as a router in this instance and giving out IP's to computers that are connected to it via tethering.

So unless your computer is also connected to the phone's network, it's not going to be able to see it. Instead you would have to hit your phone's WAN IP and the phone would have to route port 22 traffic over to the PI on that LAN IP.

Utlimately, your best bet is to get the pi connected to the same network your Debian box is on using a wifi dongle so you can refer to it directly by it's LAN IP.

If you still want to go the Android Tethering route you can check out an app like this one to do the port forwarding. You'll need to forward port 22 to your Pi Zero and also get your Android phone's IP. To get that, just go to a site like http://www.whatip.com on your phone.

Once you have port forwarding for port 22 set up on your phone then you can SSH to the phone's IP and it will route the port 22 traffic over to the Pi and you'll be set.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM