vagrant ssh on a custom box requires a password

2,347 views
Skip to first unread message

James Newton

unread,
Aug 28, 2017, 7:41:38 AM8/28/17
to Vagrant
Hello helpful Vagrant experts!

I'm new to Vagrant, so I'm taking baby steps to make sure that I understand the process. I want to ensure that I can create a custom package before I start doing any serious development in the virtual machine.

I've created a custom Vagrant package, and I am having an issue with `vagrant ssh`, where it asks for a password:

$ vagrant ssh
==> default: The machine you're attempting to SSH into is configured to use
==> default: password-based authentication. Vagrant can't script entering the
==> default: password for you. If you're prompted for a password, please enter
==> default: the same password you have configured in the Vagrantfile.
ubu...@127.0.0.1's password: |

There is no such request from the customized box from which the package was made.
 
On my development machine, the username and password are set in the file at `home/blackslate/.vagrant.d/boxes/nginx/0/virtualbox/include/_Vagrantfile`:

# 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 = "022185D04910"
  config.ssh.username = "ubuntu"
  config.ssh.password = "27f8dbe40a2e195f6bd6434a"

  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

The username/password appear to be used correctly during the `vagrant up` process, but are not being accessed during `vagrant ssh`. I have posted a question about this on StackOverflow. It would probably be best to discuss the issue there, and to report back in this thread when the issue has been resolved.

Thanks in advance for any enlightenment that you can give me,

James

Alvaro Miranda Aguilera

unread,
Aug 28, 2017, 7:59:52 AM8/28/17
to vagra...@googlegroups.com
Hello

THE Vagrant way is to add the known vagrant public ssh key, that will be replaced on first on first boot.

So, if you are starting with a box that you will repackage the best is to add

config.ssh.insert_key = false 

to that intermediate box, so the ssh key won't be replaced.

Alvaro.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/76aefa2d-18c0-413e-915b-db52f615a9cf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alvaro

James Newton

unread,
Aug 28, 2017, 8:47:25 AM8/28/17
to Vagrant
On Monday, 28 August 2017 14:59:52 UTC+3, Alvaro Miranda Aguilera wrote:
THE Vagrant way is to add the known vagrant public ssh key, that will be replaced on first on first boot.

So, if you are starting with a box that you will repackage the best is to add

config.ssh.insert_key = false 

to that intermediate box, so the ssh key won't be replaced.

Hello Alvaro,

Thank you for your reply. I must have misunderstood your instructions, because I have failed to get this to work.
  • I added `config.ssh.insert_key = false` to the Vagrantfile for the box that I subsequently package. (Is this what you call "that intermediate box"?) I then created the package and added it to the Vagrant Install, then created a new instance of the box from the package. However, I was still asked for a password when I used `virtual ssh`.
  • I manually added  `config.ssh.insert_key = false` to the Vagrantfile for this new box, but again `virtual ssh` asked me for a password.
I am guessing that the missing step is "add the known vagrant public ssh key", but I am not sure exactly what you mean by this. Where do I add what from where?

Thanks in advance for any clues you can give me.

James

Alvaro Miranda Aguilera

unread,
Aug 28, 2017, 10:09:14 AM8/28/17
to vagra...@googlegroups.com
hello

Say you you start with a working box.

lets say . hashicorp/precise64

you want to do something and then package, this is what I meant by intermediate box

on this intermediate box, if you add config.ssh.insert_key = false it wont change the ssh and the packaged box will be able to just use the same known key

try to create a new box from a working base box using config.ssh.insert_key = false

the new box should ssh and provision without problems

after that, you can just provision this intermediate box in the way you require and then package it.

Hope this helps

Alvaro

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Alvaro

James Newton

unread,
Aug 28, 2017, 11:17:11 AM8/28/17
to Vagrant
Hi Alvaro,

I am very grateful for your efforts to help me understand what is going on.

It seems that I have followed all the steps you describe, and yet I am still asked for a password when I run `vagrant ssh` on the new box (the one created from the package). I'm using ubuntu/xenial64.

When I look in ~/.vagrant.d/boxes/, I find two directories:  ubuntu-VAGRANTSLASH-xenial64 and custom (which contains my package). The most obvious difference between these two directories as that there are two extra items in the custom folder:
  • A file named vagrant_private_key
  • Afolder named include which contains a file named _Vagrantfile
This _Vagrantfile contains the following text:

# 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 = "022185D04910"
  config.ssh.username = "ubuntu"
  config.ssh.password = "27f8dbe40a2e195f6bd6434a"

  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

From your explanations, I understand the ubuntu/xenial64 box contains a default username and password pair, that the config.ssh.insert_key = false directive in the Vagrantfile for the intermediate box should prevent the package from creating its own key, so that the default username and password pair from the ubuntu/xenial64 box is used instead. But if my understanding is correct then there should be no vagrant_private_key in the custom directory.

I have provided a detailed description of all the steps that I am taking here.

I would appreciate it if your could show me where my logic is faulty.

Thanks in advance,

James

Alvaro Miranda Aguilera

unread,
Aug 29, 2017, 4:44:28 AM8/29/17
to vagra...@googlegroups.com
Can you try other box?

ie

hashicorp/precise64  ?


That box doesn't include any password:

0 kikitux ~ (master *) $ cat ~/.vagrant.d/boxes/hashicorp-VAGRANTSLASH-precise64/1.1.0/virtualbox/Vagrantfile 

Vagrant::Config.run do |config|

  # This Vagrantfile is auto-generated by `vagrant package` to contain

  # the MAC address of the box. Custom configuration should be placed in

  # the actual `Vagrantfile` in this box.

  config.vm.base_mac = "080027880CA6"

end


# Load include vagrant file if it exists after the auto-generated

# so it can override any of the settings

include_vagrantfile = File.expand_path("../include/_Vagrantfile", __FILE__)

load include_vagrantfile if File.exist?(include_vagrantfile)

0 kikitux ~ (master *) $ 



if you want a more modern box try this:


https://app.vagrantup.com/cbednarski


You can also build your own box once you get the scripts in place:


ie, using packer.io and this :


https://github.com/kikitux/virtualbox-ovf/tree/master/xenial64


alvaro.


--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Alvaro

Reply all
Reply to author
Forward
0 new messages