首页 文章

如何通过SSH访问Raspberry Pi Zero

提问于
浏览
2

我'm trying to remotely access my Raspberry Pi Zero using SSH. The raspberry'的操作系统是 Raspbian Jessy Lite (所以没有桌面环境,只有命令行) . 我使用 Android phone with USB-tethering 将覆盆子连接到Internet(覆盆子pi零没有让它工作)所以运行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)

我正在尝试从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

但这会导致错误: ****

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

我使用以下命令在raspberry上启用了SSH:

raspi-config

在树莓上运行ssh命令,但是当我在linux计算机中使用它时会超时 . 我也尝试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

另外,这是文件/ 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: 我做了JNevill所说的并尝试将我的debian电脑连接到手机网络,因为手机只有一个我通过蓝牙连接的USB端口 . 但我仍然有同样的错误 . 我还尝试使用Port Forwarder应用程序将2222端口转发到覆盆子中的22,以便在运行命令时:

ssh pi@192.168.1.46 -p 2222

Android手机应该转发到树莓的22端口(我也尝试转发22到22,但我收到一个错误:“EACCESS:权限被拒绝”) . 这样做我也有一个连接超时 . 也许是因为当我使用命令时应用程序无法运行:

ssh root@192.168.1.46 -p 2222

我得到一个不同的错误:连接被拒绝 . 它没有为什么 .

1 回答

  • 3

    192.168.42.172 是从手机分配给pi的本地IP . 在这种情况下,手机充当路由器,并将IP发送给通过网络共享连接到它的计算机 .

    因此,除非您的计算机也连接到手机的网络,否则它无法看到它 . 相反,您必须使用手机的WAN IP,手机必须将端口22流量路由到该LAN IP上的PI .

    最重要的是,你最好的选择是使用wifi加密狗将你的Debian盒连接到同一个网络,这样你就可以通过它的LAN IP直接引用它 .

    如果您仍想使用Android Tethering路线,可以查看应用程序like this one以进行端口转发 . 你'll need to forward port 22 to your Pi Zero and also get your Android phone'的IP . 为此,只需在手机上访问http://www.whatip.com这样的网站即可 .

    一旦您在手机上设置端口22的端口转发,您就可以通过SSH连接到手机的IP,它将端口22的流量路由到Pi,您将被设置 .

相关问题