无法通过 SSH 连接到运行 dropbear sshd 的 QEMU 虚拟机 [英] Cannot SSH into QEMU virtual machine running dropbear sshd

查看:26
本文介绍了无法通过 SSH 连接到运行 dropbear sshd 的 QEMU 虚拟机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经建立了一个模拟 vexpress-a9 机器的 QEMU 虚拟机.我使用 buildroot 创建了 initrd 系统,并且使用了 buildroot 下载的 codesourcery 交叉编译器作为编译 Linux 内核的设置的一部分.这就是我调用 qemu 的方式

I have set up a QEMU virtual machine emulating the vexpress-a9 machine. I've used buildroot to create the initrd system and I've used the codesourcery cross-compiler that buildroot downloads as part of it's setup to compile the Linux Kernel. This is how I invoke qemu

qemu-system-arm -m 512 -M vexpress-a9-dtb linux-4.4.192/arch/arm/boot/dts/vexpress-v2p-ca9.dtb-内核linux-4.4.192/arch/arm/boot/zImage-initrd buildroot/output/images/rootfs.cpio-附加控制台=ttyAMA0,ip=dhcp"-net nic,model=lan9118-net 用户,hostfwd=tcp::2222-:22-nographic

它启动得很好.与网络相关的启动消息表明网络已初始化并且 dropbear sshd 已启动并运行:

It boots just fine. Network related boot messages that tell that the network has been initialized and dropbear sshd was brought up and running:

启动网络:OK启动 dropbear sshd: random: dropbear: 未初始化的 urandom 读取(读取 32 个字节,1 位可用熵)好的

但是eth0 接口必须手动分配一个IP.我在与我的 Linux 主机相同的子网中为它分配了一个未使用的 C 类地址,如下所示:

however the eth0 interface has to be assigned an IP manually. I assign it an unused class C address in the same subnet as my Linux host like so:

# ifconfig eth0 192.168.160.150 upsmsc911x 4e000000.ethernet eth0:SMSC911x/921x 标识为 0xa12a0000,IRQ:31

所以 ifconfig 现在显示:

# ifconfig
eth0      Link encap:Ethernet  HWaddr 52:54:00:12:34:56
          inet addr:192.168.160.150  Bcast:192.168.160.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  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:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:31

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          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)

netstat 告诉我我们正在监听端口 22:

netstat tells me that we are listening on port 22:

# netstat -tln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN

我什至可以像这样 ssh 到本地主机:

I can even ssh into localhost like so:

# ssh root@127.0.0.1
random: ssh: uninitialized urandom read (32 bytes read, 24 bits of entropy available)
random: dropbear: uninitialized urandom read (32 bytes read, 24 bits of entropy available)
random: dropbear: uninitialized urandom read (32 bytes read, 24 bits of entropy available)
random: dropbear: uninitialized urandom read (32 bytes read, 24 bits of entropy available)

Host '127.0.0.1' is not in the trusted hosts file.
(ecdsa-sha2-nistp256 fingerprint sha1!! de:cf:f8:b3:ac:4d:96:47:22:d7:76:a1:ea:11:3d:bc:ec:c6:71:9a)
Do you want to continue connecting? (y/n) y
root@127.0.0.1's password:
random: dropbear: uninitialized urandom read (32 bytes read, 26 bits of entropy available)

而在主机上,这是我尝试从 linux 主机通过 SSH 连接到此 VM 时所看到的:

whereas from the host this is what I see when I try to SSH into this VM from the linux host:

$ ssh -vvv root@192.168.160.150
OpenSSH_7.4p1 Debian-10+deb9u7, OpenSSL 1.0.2s  28 May 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "192.168.160.150" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to 192.168.160.150 [192.168.160.150] port 22.
debug1: connect to address 192.168.160.150 port 22: No route to host
ssh: connect to host 192.168.160.150 port 22: No route to host

我很乐意就此提供一些建议,因为我找不到其他可以尝试的方法

I would be pleased to have some pointers about this as I cannot find what else can be tried

更新 1: 在配置 buildroot 时包含 dhcpd.现在无论我是使用 dropbear 还是 openssh,日志消息都会出现直到

UPDATE 1: Included dhcpd while configuring buildroot. Now irrespective of whether I use dropbear or openssh, the log messages appear until

Starting dhcpcd...
no interfaces have a carrier <--- the problem
forked to background, child pid 746
smsc911x 4e000000.ethernet eth0: SMSC911x/921x identified at 0xa12a0000, IRQ: 31
Starting dropbear sshd: random: dropbear: uninitialized urandom read (32 bytes read, 2 bits of entropy available)
OK
random: dhcpcd: uninitialized urandom read (120 bytes read, 2 bits of entropy available)

此时它只是停止,我看不到登录提示.删除 dhcpd 并使用 dropbear 或 openssh 后,我可以再次看到登录提示(意味着所有 init 脚本运行完成),但再次没有任何类型的连接.我不明白为什么dhcpd世界上会认为我们没有载体(当它能够枚举和识别模拟的NIC卡时)

at which point it just kind of stops and I cannot see the login prompt. Upon removing dhcpd and using either dropbear or openssh, I can see the login prompt again (meaning all the init scripts run to completion) but again no connectivity of any kind. I can't understand why in the world does dhcpd thinks we have no carrier (when it is able to enumerate and identify the emulated NIC card)

UPDATE2:我尝试手动调用 udhcpc 以通过 DHCP 获取地址,但它确实获取了地址

UPDATE2: I've tried invoking udhcpc manually to obtain an address via DHCP and it does get an address

# udhcpc -S -a100
udhcpc: started, v1.31.0
udhcpc: sending discover
udhcpc: sending select for 10.0.2.15
udhcpc: lease of 10.0.2.15 obtained, lease time 86400
deleting routers
adding dns 10.0.2.3
# ifconfig
eth0      Link encap:Ethernet  HWaddr 52:54:00:12:34:56
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2360 (2.3 KiB)  TX bytes:1428 (1.3 KiB)
          Interrupt:31

但是主机仍然无法访问该机器.我是否需要从主机添加到此 VM 的手动路由?如果是,我该怎么做?QEMU 是否在主机上创建了一个虚拟接口(就像工作站一样)?

The machine is still however inaccessible from the host. Do I need to add a manual route to this VM from the host? If yes how do I do that? Does QEMU create a virtual interface on the host (like workstation does)?

推荐答案

昨天我花了几个小时尝试使用 的不同选项(即 -net-netdev)qemu-system-arm,但最后有用的是这个选项: -nic user,hostfwd=::2222-:22 我从 已删除功能页面(查看替换 -redir 选项).我还必须在主机的 SSH 配置文件中添加这 3 行:/etc/ssh/ssh_config

I spent hours yesterday trying different options (i.e. -net, -netdev) with qemu-system-arm, but finally what worked was this one option: -nic user,hostfwd=::2222-:22 Which I learned from the list of removed features page (look at replacement of -redir option). I also had to add these 3 lines in my host's SSH config file: /etc/ssh/ssh_config

Host localhost
PreferredAuthentications=password
PubkeyAuthentication=no

这篇关于无法通过 SSH 连接到运行 dropbear sshd 的 QEMU 虚拟机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆