1

I have successfully created a custom Vagrant box, based on the official ubuntu/xenial64 Vagrant box, but I get this message when I attempt to use 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.

The only change to the box is to provision it with NginX. I then use...

vagrant package --vagrantfile <path_to_vagrantfile> --output nginx.box

... where <path_to_vagrantfile> is, in my case, /home/blackslate/.vagrant.d/boxes/ubuntu-VAGRANTSLASH-xenial64/20170822.0.0/virtualbox/Vagrantfile. I follow this with:

vagrant box add nginx nginx.box

I then create a new directory and use vagrant init nginx to create a new instance of the box. The whole process is described in this question.

When I use vagrant up, all appears to be running as expected:

vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'nginx'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: Custom_default_1503826905856_10643
==> 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: password
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /home/blackslate/repos/Vagrant/Custom

However, vagrant ssh provokes the message at the beginning of this question. When I try to ssh in manually, using "ubuntu" as the ssh user and "vagrant" as the password, I get this:

ssh ubuntu@127.0.0.1
The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:PSnauymZfKi1HIRIKfez5wAnpPFJW9h3eC+TzxiiIWA.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added '127.0.0.1' (ECDSA) to the list of known hosts.
ubuntu@127.0.0.1's password: 
Permission denied, please try again.
ubuntu@127.0.0.1's password: 

I get a similar result if I try ssh vagrant@127.0.0.1:

ssh vagrant@127.0.0.1
vagrant@127.0.0.1's password: 
Permission denied, please try again.
vagrant@127.0.0.1's password: 

The same is true if I open the VirtualBox GUI and talk to the VM directly.

I have tried following the instructions here, but I'm guessing that this refers to an older version of Vagrant.

I am hoping that I will be able to make changes at the package stage, so that when I distribute the custom Vagrant box to other developers, vagrant ssh just works, with no need to massage any files beforehand.

James Newton
  • 6,623
  • 8
  • 49
  • 113
  • try `ssh -p 2222 ubuntu@127.0.0.1` –  Aug 27 '17 at 10:11
  • That gives me the same result: request to add `'[127.0.0.1]:2222' (ECDSA) to the list of known hosts`, followed by `Permission denied, please try again.` It looks as if the VM is expecting a password that I don't know. – James Newton Aug 27 '17 at 10:14
  • this is weird, vagrant is able to ssh-in during vagrant up. can you check the password is correct in your vagrantfile box file ? and try enter the password (should be 95bf98670a543bcd7bdd576c) ; if you're using ssh command directly you need to give the right username (which is ubuntu in this box, vagrant user is not defined) – Frederic Henri Aug 27 '17 at 10:48
  • `config.ssh.username = "ubuntu"` `config.ssh.password = "27f8dbe40a2e195f6bd6434a"` – James Newton Aug 27 '17 at 11:08
  • This works: `ssh -p 2222 ubuntu@127.0.0.1` and then `ubuntu@127.0.0.1's password: 27f8dbe40a2e195f6bd6434a` – James Newton Aug 27 '17 at 11:13
  • It sounds as if `vagrant up` is using the stored password, but `vagrant ssh` does not have access to it. The password is stored in the file in the `include` folder at `/home/blackslate/.vagrant.d/boxes/nginx/0/virtualbox/include/_Vagrantfile `. What can I do, when packaging, to make this password available to `vagrant ssh`? – James Newton Aug 27 '17 at 11:27
  • can you run `vagrant ssh --debug` and check if something is wrong from there (the merge of Vagrantfile should be correct - you can also try to copy username/password from `_include/Vagrantfile` to your project Vagrantfile but I doubt this would work) – Frederic Henri Aug 27 '17 at 16:16

1 Answers1

0

Try using the Oracle Virtual Box Manager to log in directly console instead of with ssh. Thereupon may edit the sshd config file and allow the passoword authentication. Restart SSHD service.

diesel10
  • 1
  • 4