Probably a stupid question but

I have used the trusty64 box before with vagrant and was trying the xenial64 box but it doesn't accept the usual user: vagrant password: vagrant login?

  • 4
    It's a bug: bugs.launchpad.net/cloud-images/+bug/1569237 – user589808 Oct 2 '16 at 6:20
  • 1
    So what is the new user then? user: ubuntu password: ??? – KillerSnail Oct 2 '16 at 6:27
  • 8
    Anybody know the f***ing password for ubuntu user? – Victor Bocharsky Oct 12 '16 at 21:46
  • 3
    Short comment, because no accepted answer yet... You can find the PASS in the: ~/.vagrant.d/boxes/ubuntu-VAGRANTSLASH-xenial64/20170311.0.0/virtualbox/Vagrantfile, where "20170311.0.0" should be different directory name... so go to ~/.vagrant.d/boxes/ and find your box and vagrant file. – Minister Mar 16 '17 at 18:26
  • 2
    I switched to the bento/ubuntu-16.04 box and it solved a slew of problems. – jchook Apr 1 '17 at 21:21
up vote 29 down vote accepted

As mention by user @prometee in this launchpad discussion #1569237, you can find the password in:

~/.vagrant.d/ubuntu-VAGRANTSLASH-xenial64/20161221.0.0/virtualbox/Vagrantfile

or:

~/.vagrant.d/boxes/ubuntu-VAGRANTSLASH-xenial64/20161221.0.0/virtualbox/Vagrantfile

depending on your version of Vagrant. (Note the 20161221.0.0 part of the path will vary depending on when the box was downloaded. Also, there might be more than one in your directory.)

Here is mine (line 8):

# Front load the includes
include_vagrantfile = File.expand_path("../include/_Vagrantfile", __FILE__)
load include_vagrantfile if File.exist?(include_vagrantfile)

Vagrant.configure("2") do |config|
  config.vm.base_mac = "022999D56C03"
  config.ssh.username = "ubuntu"
  config.ssh.password = "fbcd1ed4fe8c83b157dc6e0f"

  config.vm.provider "virtualbox" do |vb|
     vb.customize [ "modifyvm", :id, "--uart1", "0x3F8", "4" ]
     vb.customize [ "modifyvm", :id, "--uartmode1", "file", File.join(Dir.pwd, "ubuntu-xenial-16.04-cloudimg-console.log") ]
  end
end

FYI, user @racb mention in the same discusison that the this bug report having been filed to ubuntu and so far no [...] decision has been made yet about it.

  • There is no file at that location for me – Felix Eve Feb 20 '17 at 22:49
  • 2
    I found it at ~\.vagrant.d\boxes\ubuntu-VAGRANTSLASH-xenial64\20170331.0.0\virtualbox\Vagrantfile (in Windows) – Rob H Apr 5 '17 at 12:52
  • Worked perfectly. My path was ~/.vagrant.d/boxes/ubuntu-VAGRANTSLASH-xenial64/20170317.0.0/virtualbox but got the idea where to look for the password. – Ariful Haque Aug 17 '17 at 8:06
  • 1
    This answer must be the accepted answer! – Sangar82 Aug 23 '17 at 10:44
  • 1
    -Is it safe to change the username and password to "vagrant:vagrant" there?- Update: Nope; vagrant reload will ask for a password for vagrant@127.0.0.1 and will not accept the value you used there. – Juha Untinen Sep 1 '17 at 16:57

I banged my head against the wall for half a day yesterday until I realised I was running an old version of Virtualbox (5.0.x) and Vagrant (1.8.0)

Updated to VirtualBox 5.1.x and Vagrant 1.8.7 and got better results

Basically the ubuntu/xenial32 and ubuntu/xenial64 images are flawed as they don't come with the vagrant user out of the box.

This is against the Vagrant specifications

I ended up using v0rtex/xenial64 as recommended in this bug report. Not sure why canonical is not fixing this

My vagrant file is as follows

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.box = "v0rtex/xenial64"

  config.vm.network :private_network, ip: "10.10.10.10"

  config.ssh.username = 'vagrant'
  config.ssh.password = 'vagrant'

  config.vm.provider :virtualbox do |vb|
     vb.name = "supercool"
     vb.customize ["modifyvm", :id, "--memory", "768"]
     vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
  end

end

If you still want to use the canonical provided images it is possible using the following approach

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.box = "ubuntu/xenial64"

  config.vm.network :private_network, ip: "10.10.10.10"

  config.ssh.insert_key = true
  config.ssh.forward_agent = true

  config.vm.provider :virtualbox do |vb|
     vb.name = "supercool"
     vb.customize ["modifyvm", :id, "--memory", "768"]
     vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
  end

end

If you do that the /vagrant folder will be owned by ubuntu:ubuntu instead of vagrant:vagrant. If you have scripts relying on the vagrant user to be there they will break

It has been fixed at last (2018/01/13): https://bugs.launchpad.net/cloud-images/+bug/1569237/comments/111

You may want to run vagrant box update and then vagrant destroy.

  • You can also add this to your Vagrant file: config.vm.box_check_update = true config.vm.box_version = "20180112.0.0" – ojrac Jan 31 at 16:27

A way is to install expect and initiate a password change. The example below sets the password ubuntu to user ubuntu.

Vagrant.configure("2") do |config|
    apt-get install -y expect
    echo '#!/usr/bin/expect
      set timeout 20
      spawn sudo passwd ubuntu
      expect "Enter new UNIX password:" {send "ubuntu\\r"}
      expect "Retype new UNIX password:" {send "ubuntu\\r"}
      interact' > change_ubuntu_password
    chmod +x change_ubuntu_password
  ./change_ubuntu_password
end

The new ubuntu/xenial64 image doesn't come with a default username and password. However you can ssh using an ssh-key generated in your vagrant folder.

Let's say your Vagrantfile is at /vagrant/vm01/Vagrantfile, the ssh-key would be in /vagrant/vm01/.vagrant/machines/..../private_key

You can login to your vagrant vm using this private_key. If the guest machine ask for the key's passphrase, just hit ENTER (specifying a blank passphrase). For example, on my Mac:

ssh -i /vagrant/vm01/.vagrant/..../private_key <your vm ip> <your vm port>

If you still want to log in using username and password, after logging in using the private_key, you can add your own user for logging in later:

# create a user for log in
sudo useradd yourusername

# specify a password
sudo passwd yourusername
# then type your password when prompted

# add the user to sudo group
sudo adduser yourusername sudo    

# create a home folder for your user
sudo mkdir /home/yourusername

# add a shell command for your user (normally /bin/bash)
sudo vim /etc/passwd
# find yourusername line, and add /bin/bash to the end.
# the end result would look like this:
yourusername:x:1020:1021::/home/yourusername:/bin/bash

Now you can ssh using the new username and password.

You can output OpenSSH valid configuration to connect to the machine by typing vagrant ssh-config from within your Vagrantfile folder. The output will show you that password authentication is disabled, however you can point to the private key file:

Host default
  HostName 127.0.0.1
  User ubuntu
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /path/to/project/folder/.vagrant/machines/default/virtualbox/private_key
  IdentitiesOnly yes
  LogLevel FATAL

Now you can:

ssh -i /path/to/project/folder/.vagrant/machines/default/virtualbox/private_key ubuntu@machine-ip

If you're not interested in ubuntu/xenial64 box but any other 16.04 LTS box I used the bento one that works with the usual vagrant username and password:

config.vm.box = 'bento/ubuntu-16.04'
config.vm.box_version = "201708.22.0"

I'am using Vagrant on Windows and image of ubuntu/xenial64 no password configured for it.

  • Default UserName: vagrant
  • Default Host: 127.0.0.1:2222
  • Default SSH Key: C:/Vagrant/.vagrant/machines/default/virtualbox/private_key

You can login to your VM box via command:

 vagrant ssh

or by

ssh -i private_key vagrant:127.0.0.1 -p 2222

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.