我正在尝试使用以下Vagrant文件在 ubuntu / bionic64 框版本 20181024.0.0 上以 ubuntu 用户的身份使用ssh:
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/bionic64"
config.vm.box_version = "20181024.0.0"
config.vm.network :private_network, ip: "192.168.24.25"
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "256"]
end
end
在执行vagrant up
和vagrant ssh
时,我以 vagrant 用户身份登录。如果添加此行:
config.ssh.username = 'ubuntu'
获得这样的Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/bionic64"
config.vm.box_version = "20181024.0.0"
config.vm.network :private_network, ip: "192.168.24.25"
config.ssh.username = "ubuntu"
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "256"]
end
end
并运行vagrant up
,我收到认证错误消息:
default: Warning: Authentication failure. Retrying...
我也尝试添加此行
config.ssh.insert_key = 'true'
但这也不起作用。
我知道,一旦以vagrant
用户身份将用户切换到vm后,就可以将其更改为用户,但是我希望该操作可以自动完成,就像使用 ubuntu / xenial64的情况一样版本 20171011.0.0 ,具有默认配置。
有什么办法解决此问题吗?
流浪版本:2.2.0
VirtualBox版本:5.2.20 r125813
整个输出是:
danilo$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/bionic64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/bionic64' is up to date...
==> default: Setting the name of the VM: ubuntu-bionic64_default_1540543288462_93774
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: hostonly
==> default: Forwarding ports...
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: ubuntu
default: SSH auth method: private key
default: Warning: Connection reset. Retrying...
default: Warning: Remote connection disconnect. Retrying...
default: Warning: Authentication failure. Retrying...
default: Warning: Authentication failure. Retrying...
default: Warning: Authentication failure. Retrying...
default: Warning: Authentication failure. Retrying...
default: Warning: Authentication failure. Retrying...
default: Warning: Authentication failure. Retrying...
default: Warning: Authentication failure. Retrying...
答案 0 :(得分:2)
简而言之
config.ssh.username = "ubuntu"
vagrant up
\\使用默认的无业游民用户设置VM IdentityFile
的结果中获取vagrant ssh-config
路径值ssh-keygen -y -f <!!path-from-IdentityFile!!>
,复制此密钥vagrant ssh
\\,您将在无业游民的用户下进行一段时间的身份验证sudo -u ubuntu bash
\\更改用户vim ~/.ssh/authorized_keys
,从4添加密钥。config.ssh.username = "ubuntu"
vagrant reload
vagrant ssh
\\您将立即在ubuntu用户下进行身份验证