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?
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.
~/.vagrant.d/boxes/ubuntu-VAGRANTSLASH-xenial64/20170317.0.0/virtualbox
but got the idea where to look for the password.
Aug 17, 2017 at 8:06
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
.
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
I'm using Vagrant on Windows and image of ubuntu/xenial64; no password is configured for it.
You can login to your VM box via this command:
vagrant ssh
or with:
ssh -i private_key [email protected] -p 2222
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"
After vagrant up
to start a virtual machine, you can vagrant ssh
to login.
Run vagrant help
for more information.
~/.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.bento/ubuntu-16.04
box and it solved a slew of problems.