简体   繁体   English

如何通过SSH访问Raspberry Pi Zero

[英]How to access the Raspberry Pi Zero though SSH

I'm trying to remotely access my Raspberry Pi Zero using SSH. 我正在尝试使用SSH远程访问我的Raspberry Pi Zero。 The raspberry's OS is Raspbian Jessy Lite (so no desktop enviornment, only the command line). 树莓派的操作系统是Raspbian Jessy Lite (因此没有桌面环境,只有命令行)。 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: 我使用具有USB绑定功能的Android手机将树莓派连接到Internet(树莓派零零没有以太网端口,我尝试使用Zydas WiFi加密狗,但我无法使其工作),因此运行ifconfig输出:


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: 我正在尝试从Linux计算机(运行debian 3.16.0-4-amd64#1 SMP Debian 3.16.7-ckt25-2(2016-04-08)x86_64 GNU / Linux )访问树莓派,我使用以下命令:

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: 我已经使用以下命令在树莓派上启用了SSH:

raspi-config

Running the ssh command on the raspberry works but it times out when I use it in the linux computer. 在树莓派上运行ssh命令是可行的,但是当我在Linux计算机中使用它时,它会超时。 I also tried to ping the raspberry, this is the result: 我也尝试ping通覆盆子,这是结果:


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: 另外,这是文件/ 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. 更新:按照JNevill所说的做了,并尝试将我的debian计算机连接到手机的网络,因为手机只有一个USB端口,我是通过蓝牙连接的。 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: 我还尝试使用端口转发器应用程序将2222端口转发到树莓派中的22,以便在运行命令时:

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"). Android手机应该将其转发到树莓派的22端口(我也尝试将22转发到22,但出现错误:“ EACCESS:权限被拒绝”)。 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. 另外,Android手机并非扎根,所以这可能就是原因。

192.168.42.172 is a local IP that is assigned to the pi from your phone. 192.168.42.172是从电话分配给pi的本地IP。 The phone is acting as a router in this instance and giving out IP's to computers that are connected to it via tethering. 在这种情况下,电话将充当路由器,并通过网络共享将IP分发给与其连接的计算机。

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. 取而代之的是,您必须点击电话的WAN IP,电话必须将端口22流量路由到该LAN IP上的PI。

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. 最好,最好的选择是使用wifi加密狗将pi连接到与Debian机盒所处的同一网络,因此您可以直接通过其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. 如果您仍然想使用Android网络共享路线,则可以签出类似该应用的应用进行端口转发。 You'll need to forward port 22 to your Pi Zero and also get your Android phone's IP. 您需要将端口22转发到Pi Zero,还需要获取Android手机的IP。 To get that, just go to a site like http://www.whatip.com on your phone. 为此,只需在手机上访问http://www.whatip.com这样的网站即可。

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. 一旦在手机上设置了端口22的端口转发功能,就可以SSH到手机的IP,它将端口22的流量路由到Pi,您将被设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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