'ubuntu' 用户在 ubuntu/bionic64 18.04 box 上使用 Vagrant ssh

Vagrant ssh with 'ubuntu' user on ubuntu/bionic64 18.04 box

我正在尝试以 ubuntu 用户身份在 ubuntu/bionic64 盒子版本 上进行 ssh 20181024.0.0,使用这个 Vagrant 文件:

# -*- 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 upvagrant 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 用户身份通过​​ ssh 进入虚拟机,就可以更改用户,但我希望自动完成,就像使用 [=44= 时的情况一样]ubuntu/xenial64 版本 20171011.0.0 默认配置。

有什么解决方法吗?

Vagrant 版本: 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...

说明基于https://openedx.atlassian.net/wiki/spaces/OXA/pages/157802739/Vagrant+is+stuck+Authentication+failure.+Retrying...

简而言之

  1. 在 Vagrantfile
  2. 中评论 config.ssh.username = "ubuntu"
  3. vagrant up \\ 使用默认的 vagrant 用户设置 VM
  4. 从命令 vagrant ssh-config
  5. 的结果中获取 IdentityFile 路径值
  6. 生成密钥ssh-keygen -y -f <!!path-from-IdentityFile!!>,复制此密钥
  7. vagrant ssh \\ 你将在 vagrant 用户下授权一段时间
  8. sudo -u ubuntu bash\\更改用户
  9. vim ~/.ssh/authorized_keys,从 4.
  10. 添加密钥
  11. 退出虚拟机
  12. 在 Vagrantfile
  13. 中取消注释 config.ssh.username = "ubuntu"
  14. vagrant reload
  15. vagrant ssh \\ 您现在将在 ubuntu 用户下进行授权