Danilo Radenovic
Danilo Radenovic

Reputation: 1029

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

I am trying to ssh as ubuntu user on ubuntu/bionic64 box version 20181024.0.0, using this Vagrant file:

# -*- 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

When doing vagrant up and vagrant ssh, I am logged in as vagrant user. If this line is added:

config.ssh.username = 'ubuntu'

to get a Vagrantfile like this:

# -*- 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

and running vagrant up, I'm getting the authentication error message:

default: Warning: Authentication failure. Retrying...

I have also tried adding this line

config.ssh.insert_key = 'true'

But that doesn't work either.

I am aware that the user can be changed once ssh'd into the vm as vagrant user, but I'd like that to be done automatically, as is the case when using ubuntu/xenial64 version 20171011.0.0 with default configuration.

Any ideas how to workaround this?

Vagrant version: 2.2.0

VirtualBox version: 5.2.20 r125813

The whole output is:

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...

Upvotes: 0

Views: 3171

Answers (1)

Vadim
Vadim

Reputation: 642

instruction based on https://openedx.atlassian.net/wiki/spaces/OXA/pages/157802739/Vagrant+is+stuck+Authentication+failure.+Retrying...

in short

  1. comment config.ssh.username = "ubuntu" in Vagrantfile
  2. vagrant up \\ setup VM with default vagrant user
  3. get IdentityFile path value from result of command vagrant ssh-config
  4. generate key ssh-keygen -y -f <!!path-from-IdentityFile!!>, copy this key
  5. vagrant ssh \\ you will auth under vagrant user for a while
  6. sudo -u ubuntu bash \\ change user
  7. vim ~/.ssh/authorized_keys, add key from 4.
  8. exit from VM
  9. uncomment config.ssh.username = "ubuntu" in Vagrantfile
  10. vagrant reload
  11. vagrant ssh \\ you will auth under ubuntu user now

Upvotes: 3

Related Questions