无法使用 Qemu 从主机 ssh 到客户机

无法使用 Qemu 从主机 ssh 到客户机

我在主机和客户机上都使用 Ubuntu 18.04.2。我已经使用 libvirt 创建了虚拟机。在创建虚拟机期间,我没有使用 libvirt 从主机到客户机建立 ssh。我正在尝试使用以下 Qemu 命令运行虚拟机。我在命令中添加了 hostfwd 以通过 ssh 连接到客户机。我已经在客户机中设置了 ssh 服务器。但我无法使用 ssh 从主机连接到客户机。我该如何解决这个问题?

sudo qemu-system-x86_64 \
    -enable-kvm \
    -name guest=ubuntu18.04_VM_libvirt,debug-threads=on \
    -S \
    -machine pc-i440fx-bionic,accel=kvm,usb=off,vmport=off,dump-guest-core=off \
    -cpu Broadwell-noTSX-IBRS \
    -m 4096 \
    -realtime mlock=off \
    -smp 6,sockets=6,cores=1,threads=1 \
    -uuid ec642fe5-8e5c-4d4a-ada7-b8562396d477 \
    -no-user-config \
    -nodefaults \
    -chardev socket,id=charmonitor,path=/home/probir/Downloads/qemu_with_libvirt/monitor.sock,server,nowait \
    -mon chardev=charmonitor,id=monitor,mode=control \
    -rtc base=utc,driftfix=slew \
    -global kvm-pit.lost_tick_policy=delay \
    -no-hpet \
    -no-shutdown \
    -global PIIX4_PM.disable_s3=1 \
    -global PIIX4_PM.disable_s4=1 \
    -boot strict=on \
    -device ich9-usb-ehci1,id=usb,bus=pci.0,addr=0x5.0x7 \
    -device ich9-usb-uhci1,masterbus=usb.0,firstport=0,bus=pci.0,multifunction=on,addr=0x5 \
    -device ich9-usb-uhci2,masterbus=usb.0,firstport=2,bus=pci.0,addr=0x5.0x1 \
    -device ich9-usb-uhci3,masterbus=usb.0,firstport=4,bus=pci.0,addr=0x5.0x2 \
    -device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x6 \
    -drive file=/home/probir/Downloads/qemu_with_libvirt/ubuntu18.04.img,format=raw,if=none,id=drive-virtio-disk0 \
    -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x7,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 \
    -drive if=none,id=drive-ide0-0-0,readonly=on \
    -device ide-cd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
    -netdev bridge,id=hostnet0,br=virbr0 \
    -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:96:2f:7a,bus=pci.0,addr=0x3 \
    -chardev pty,id=charserial0 \
    -device isa-serial,chardev=charserial0,id=serial0 \
    -chardev spicevmc,id=charchannel0,name=vdagent \
    -device virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=com.redhat.spice.0 \
    -device usb-tablet,id=input0,bus=usb.0,port=1 \
    -spice port=5900,addr=127.0.0.1,disable-ticketing,image-compression=off,seamless-migration=on \
    -device qxl-vga,id=video0,ram_size=67108864,vram_size=67108864,vram64_size_mb=0,vgamem_mb=16,max_outputs=1,bus=pci.0,addr=0x2 \
    -device intel-hda,id=sound0,bus=pci.0,addr=0x4 \
    -device hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0 \
    -chardev spicevmc,id=charredir0,name=usbredir \
    -device usb-redir,chardev=charredir0,id=redir0,bus=usb.0,port=2 \
    -chardev spicevmc,id=charredir1,name=usbredir \
    -device usb-redir,chardev=charredir1,id=redir1,bus=usb.0,port=3 \
    -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x8  \
    -netdev user,id=netdev0,hostfwd=tcp:127.0.0.1:2222-:22 \
    -device virtio-net-pci,netdev=netdev0 \
    -msg timestamp=on 

运行 ssh 后我收到以下错误。

$sudo ssh -p2222 probir@localhost -vv
OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n  7 Dec 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "localhost" port 2222
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to localhost [127.0.0.1] port 2222.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
ssh_exchange_identification: read: Connection reset by peer

相关内容