环境
Product | Version |
---|---|
宿主机OS | Windows 11 |
虚拟机软件 | VirtualBox 7.0 |
虚拟机OS | Ubuntu Server 22.04 |
配置
- 配置 SSH 服务器允许远程登录
# 配置文件位置 /etc/ssh/sshd_config
# 添加如下两行(可通过解开注释的方式实现,模板里有对应配置)
Port 22
PasswordAuthentication yes
- 重启 SSH 服务
sudo systemctl restart ssh
- VirtualBox虚拟机网络配置
选中指定虚拟机->Settings->Network->Adapter 1-> Attached to: NAT -> Advanced -> Port Forwarding
Name | Protocal | Host IP | Host Port | Guest IP | Guest Port |
---|---|---|---|---|---|
SSH | TCP | 127.0.0.1 | 10022 | 10.0.2.15 | 22 |
注意: Host Port指定之后宿主机需要连接这个端口才能与虚拟机的SSH服务连接;Guess IP可以使用 ip address
命令查询