在ubuntu / bionic64 18.04盒子上与'ubuntu'用户一起使用Vagrant ssh

时间:2018-10-26 08:10:51

标签: vagrant

我正在尝试使用以下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 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用户身份将用户切换到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...

1 个答案:

答案 0 :(得分:2)

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

简而言之

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