马豫宛的技术小窝 Java and Python Coder

配置SSH远程登录

2017-12-10


前言

为了方便Host与Guest间的文件交互,我采取SSH方式从Host机器远程登录Guest,可以远程操作guest系统,以及向guest系统传送文件。

实验环境

  • QEMU虚拟机版本:1.0
  • Host操作系统:32位Ubuntu desktop 12.04.5
  • Guest虚拟机操作系统:32位的Ubuntu 9.04

1 ,在guest系统中安装openssh-server。

sudo apt-get install openssh-server

2 ,启动QEMU虚拟机时添加端口重定向参数hostfwd=tcp::2222-:22(注意不要漏掉-号以及:的个数),将Guest的22端口重定向到Host的2222端口。在host通过ssh远程登录quest: 例如,我启动虚拟机的命令如下:

qemu-system-i386 -redir tcp:2222::22 -hda ~/images/ubuntu904-server.qcow2 -show-cursor -enable-kvm -usbdevice tablet

  • show-cursor:虚拟机中的鼠标显示
  • enable-kvm:加速启动
  • usbdevice tablet:解决虚拟机中鼠标偏移问题

3 ,在Host机器上查看端口2222是否处于监听状态:

netstat -apn grep 2222

(Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) tcp 0 0 0.0.0.0:2222 0.0.0.0:* LISTEN 3132/qemu-system-i3

4, 然后就可以通过SSH访问本机的2222端口来远程登录Guest机器了。username是登录Guest机器所使用的用户名。

ssh -p 2222 username@localhost

5, 在host主机向guest系统传送文件

scp -P 2222 procinfo-ubuntu-hardy.tar.gz username@localhost:~


Comments

Content