vagrantfile
目录输入vagrant ssh
可以登陆,是因为vagtant创建虚拟机的时候生成了非对称加密的公私钥
,公钥上传到了虚拟机,私钥保存在宿主机中。# 查看当前虚拟机的配置,可以看到`PasswordAuthentication no` 密码登陆被禁止,`IdentityFile` 私钥地址
Administrator@ADMINIS-AL9GNP3 MINGW64 /e/code/test/vm/data2
$ vagrant ssh-config
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile C:/Users/Administrator/.vagrant.d/boxes/traefik_box/0/virtualbox/vagrant_private_key
IdentitiesOnly yes
LogLevel FATAL
Administrator@ADMINIS-AL9GNP3 MINGW64 /e/code/test/vm/data2
# 尝试使用密钥文件和用户名登陆
$ ssh -i C:/Users/Administrator/.vagrant.d/boxes/traefik_box/0/virtualbox/vagrant_private_key vagrant@127.0.0.1 -p 2222
Welcome to Ubuntu 16.04.7 LTS (GNU/Linux 4.4.0-210-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
UA Infra: Extended Security Maintenance (ESM) is not enabled.
0 updates can be applied immediately.
88 additional security updates can be applied with UA Infra: ESM
Learn more about enabling UA Infra: ESM service for Ubuntu 16.04 at
https://ubuntu.com/16-04
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
Last login: Thu Jun 16 07:31:35 2022 from 10.0.2.2
vagrant@swarm4:~$
# PasswordAuthentication 修改为yes
sudo sed -i "52c PasswordAuthentication yes" /etc/ssh/sshd_config
# 重启加载最新配置
sudo service sshd restart
Administrator@ADMINIS-AL9GNP3 MINGW64 /e/code/test/vm/data2
$ ssh vagrant@127.0.0.1 -p 2222
vagrant@127.0.0.1's password:
Welcome to Ubuntu 16.04.7 LTS (GNU/Linux 4.4.0-210-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
UA Infra: Extended Security Maintenance (ESM) is not enabled.
0 updates can be applied immediately.
88 additional security updates can be applied with UA Infra: ESM
Learn more about enabling UA Infra: ESM service for Ubuntu 16.04 at
https://ubuntu.com/16-04
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
Last login: Mon Jun 20 06:39:45 2022 from 10.0.2.2
vagrant@swarm4:~$
找到宿主机的用户目录下面的.ssh
目录,我的是在这里C:\Users\Administrator\.ssh
,新建config.txt
文件,把vagrant ssh-config
输入的配置复制粘贴到config.txt
,修改Host
为一个自己喜欢的名称。
Host vagrant-ssh
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile C:/Users/Administrator/.vagrant.d/boxes/traefik_box/0/virtualbox/vagrant_private_key
IdentitiesOnly yes
LogLevel FATAL
# 使用ssh Host(之前指定的Host)
Administrator@ADMINIS-AL9GNP3 MINGW64 /e/code/test/vm/data2
$ ssh vagrant-ssh
Welcome to Ubuntu 16.04.7 LTS (GNU/Linux 4.4.0-210-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
updates can be applied immediately.
additional security updates can be applied with UA Infra: ESM Learn more about enabling UA Infra: ESM service for Ubuntu 16.04 at https://ubuntu.com/16-04 Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Mon Jun 20 06:44:22 2022 from 10.0.2.2 vagrant@swarm4:~$