如何在 VirtualBox 中从一个 Raspberry PI SSH 到一个 Raspberry PI 运行

How to SSH from one Raspberry PI to a Raspberry PI running inside VirtualBox

我在 192.168 上有一个 Raspberry PI 运行。1.xx 我正在尝试从这个 PI 通过 SSH 连接到 VirtualBoxVM 中的第二个 PI 运行。

在 VM 上(使用 NAT)我通过以下方式启用了端口转发:

主机端口 -> 2222 访客端口 -> 22

然而,当我尝试从 PI1 ssh 到 PI2 时:

 ssh -p 2222 pi@localhost -vvvv

我收到以下错误:

debug1: connect to address 127.0.0.1 port 2222: Connection refused
ssh: connect to host localhost port 2222: Connection refused

我可以从我的 MBP SSH 进入 PI2(所以我知道 SSH 设置正确),但不能从 PI1。我不明白为什么 PI2 只拒绝来自 PI1 的连接?

运行 ifconfig 在 PI2:

eth0  Link encap:Ethernet  HWaddr 08:00:27:41:cb:b4
      inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0

lo    Link encap:Local Loopback
      inet addr:127.0.0.1  Mask:255.0.0.0

您正在将端口 2222 从主机的网络接口转发到 VM。

您正在尝试从您的另一台计算机连接到 localhost 上的端口 2222。

您需要连接到主机上的端口 2222,而不是您的其他计算机。

ssh -p 2222 pi@ip_of_macbook_pro -vvvv