如何通过主机从外部通过 SSH 连接到 VirtualBox 来宾? [英] How to SSH to a VirtualBox guest externally through a host?

查看:32
本文介绍了如何通过主机从外部通过 SSH 连接到 VirtualBox 来宾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Windows 7 机器上运行着 Ubuntu VM.如何设置它以便我可以通过 SSH 从外部访问网络服务器?

I have a Ubuntu VM running on my Windows 7 machine. How do I set it up so that I can access the webserver externally through SSH?

我找到了步骤(在 VirtualBox 主机和来宾 VM 之间设置 SSH 访问) 以便能够从我的主机 ssh 到我的来宾,但这仍然给我留下了通过路由器访问它的问题.

I found steps (Setup SSH access between VirtualBox Host and Guest VMs) to be able to ssh to my guest from my host, but that still leaves me with the problem of accessing it through my router.

我想我可以在我的 Windows 机器上安装一个 SSH 服务器,然后隧道几次(虽然我不是 100% 确定在本地、动态等方面使用什么,或者如何设置多个隧道?),但是有没有办法让我的路由器直接访问虚拟机,这样我就可以直接转发到它?

I suppose that I could install an SSH server on my Windows machine and then tunnel a few times (though I'm not 100% sure what to use in terms of local, dynamic, etc. or how to set up multiple tunnels?), but is there a way to make the VM directly accessible to my router so I could directly port forward to it?

推荐答案

登录来宾 Linux VirtualBox VM 的最佳方式是 端口转发.默认情况下,您应该已经有一个使用 NAT 的界面.然后转到网络设置并单击端口转发按钮.添加新的规则.作为规则名称,插入ssh".作为主机端口",插入 3022.作为访客端口",插入 22.规则的其他所有内容都可以留空.

The best way to login to a guest Linux VirtualBox VM is port forwarding. By default, you should have one interface already which is using NAT. Then go to the Network settings and click the Port Forwarding button. Add a new Rule. As the rule name, insert "ssh". As "Host port", insert 3022. As "Guest port", insert 22. Everything else of the rule can be left blank.

或从命令行

VBoxManage modifyvm myserver --natpf1 "ssh,tcp,,3022,,22"

其中myserver"是创建的 VM 的名称.检查添加的规则:

where 'myserver' is the name of the created VM. Check the added rules:

VBoxManage showvminfo myserver | grep 'Rule'

仅此而已!请确保您不要忘记在 VM 中安装 SSH 服务器:

That's all! Please be sure you don't forget to install an SSH server in the VM:

sudo apt-get install openssh-server

要通过 SSH 连接到来宾 VM,请编写:

To SSH into the guest VM, write:

ssh -p 3022 user@127.0.0.1

其中 user 是您在 VM 中的用户名.

Where user is your username within the VM.

这篇关于如何通过主机从外部通过 SSH 连接到 VirtualBox 来宾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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