Authentication failure when using vagrant up with a barebones custom package - authentication

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. For now, I have simply used the official ubuntu/xenial64 Vagrant box, and provisioned it so that nginx is installed. You can find my step-by-step guide to this here.
My customized box works fine. I use vagrant package --output nginx.box and then vagrant box add nginx nginx.box to add my custom box to my Vagrant Install. It is when I try creating a new box from the custom package that my problem appears.
I create a new directory and use vagrant init nginx to create a clone of my custom box, but when I use vagrant up, Vagrant fails to
authenticate:
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection reset. Retrying...
default: Warning: Remote connection disconnect. Retrying...
default: Warning: Connection reset. Retrying...
default: Warning: Remote connection disconnect. Retrying...
default: Warning: Connection reset. Retrying...
default: Warning: Remote connection disconnect. Retrying...
default: Warning: Connection reset. Retrying...
default: Warning: Remote connection disconnect. Retrying...
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...
If I connect to the VM through VirtualBox Manager, I'm asked to authenticate, and using the login and password "vagrant" fails.
I've looked at this question and this other question which describe similar symptoms, but I haven't yet found a solution to my problem in the answers. When I run vagrant up --debug, I get this output repeating after the VM has spun up. The key passage seems to be:
DEBUG ssh: == Net-SSH connection debug-level log END ==
INFO ssh: SSH not ready: #<Vagrant::Errors::SSHAuthenticationFailed:
SSH authentication failed! This is typically caused by the public/private
keypair for the SSH user not being properly set on the guest VM. Please
verify that the guest VM is setup with the proper public key, and that
the private key path for Vagrant is setup properly as well.>
What do I need to do before I package my custom box so that any developer will be able to use it without performing any voodoo on the public and private keys?

This box is password authenticated, when you install the box, you can check its Vagrantfile for the password (on my Mac, I will see the file at ~/.vagrant.d/boxes/ubuntu-VAGRANTSLASH-xenial64/20170116.1.0/virtualbox)
config.ssh.username = "ubuntu"
config.ssh.password = "95bf98670a543bcd7bdd576c"
The easiest would probably to repackage this same file when you build your own box (see https://www.vagrantup.com/docs/cli/package.html#vagrantfile-file), so on your step
Repackage as a new Vagrant Box:
vagrant package --output nginx.box
I would run
vagrant package --vagrantfile <path_to_original_box_vagrantfile> --output nginx.box

Related

Custom Vagrant SSH in Windows

I am trying to setup a new linux project using vagrant. I want to be able to ssh into the vagrant box with putty because it has copy paste capabilities. This is what I have done so far:
Navigated to the projects destination
In the command prompt typed
vagrant init
I changed the following in the Vagrantfile:
config.vm.box = "base"
to
config.vm.box = "ubuntu/xenial64"
I then added the following lines into the Vagrantfile:
config.vm.network "private_network", ip: "192.168.10.12"
config.ssh.username = "test"
config.ssh.password = "password"
I saved the Vagrantfile
Then in the command prompt I typed
vagrant up
This what comes up in the command prompt:
==> default: Importing base box 'ubuntu/xenial64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/xenial64' is up to date...
==> default: A newer version of the box 'ubuntu/xenial64' is available! You currently
==> default: have version '20170822.0.0'. The latest is version '20170919.0.0'. Run
==> default: `vagrant box update` to update.
==> default: Setting the name of the VM: geoserver_default_1505948268591_35426
==> default: Fixed port collision for 22 => 2222. Now on port 2201.
==> 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) => 2201 (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:2201
default: SSH username: test
default: SSH auth method: password
default: Warning: Remote connection disconnect. Retrying...
default: Warning: Authentication failure. Retrying...
Text will be echoed in the clear. Please install the HighLine or Termios libraries to suppress echoed text.
test#127.0.0.1's password:password
test#127.0.0.1's password:password
default: Warning: Authentication failure. Retrying...
Text will be echoed in the clear. Please install the HighLine or Termios libraries to suppress echoed text.
test#127.0.0.1's password:
test#127.0.0.1's password:
default: Warning: Authentication failure. Retrying...
Text will be echoed in the clear. Please install the HighLine or Termios libraries to suppress echoed text.
test#127.0.0.1's password:vagrant
test#127.0.0.1's password:vagrant
... I want a few minutes
default: Warning: Authentication failure. Retrying...
Text will be echoed in the clear. Please install the HighLine or Termios libraries to suppress echoed text.
test#127.0.0.1's password: default: Warning: Connection timeout. Retrying...
Text will be echoed in the clear. Please install the HighLine or Termios libraries to suppress echoed text.
test#127.0.0.1's password:Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.
If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.
If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.
If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.
I try and connect to the machine through putty with the following setting and I get a Network error: Connection timed out:
Host Name: 192.168.10.12
Port 2201
Connection Type: SSH
I try and connect to the machine through putty with the following setting and I get connect to the machine but I am prompted for a username and password:
Host Name: 127.0.0.1
Port 2201
Connection Type: SSH
The username/password combination I try is:
login as: test
password: password
I get an Access denied
login as: ubuntu
password: vagrant
I get an Access denied
How do I setup vagrant so that I can ssh in with putty?
Thank you for any and all help!
There's no test user in the VM so you cannot login with this user, you would first have to create a test user account with the password and then you will be able to connect.
The ubuntu password for this box is 95bf98670a543bcd7bdd576c. You will find this information in the box's Vagrantfile, on Mac its located under ~/.vagrant.d/boxes/ubuntu-VAGRANTSLASH-xenial64/20170116.1.0/virtualbox/Vagrantfile
You can just remove username/password information from your Vagrantfile and you will login automatically when running vagrant ssh

Unable to use vagrant ssh on a custom box

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

Login into Vagrant without keys, and without vagrant user default password

I on purpose messed up with auth keys, and also deleted the password for user vagrant which was also vagrant
Now when I vagrant up it stops here
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Authentication failure. Retrying...
default: Warning: Authentication failure. Retrying...
And can't login in any way. Can I use somehow provision to reset my password, or push another auth key?
VirtualBox: 5.0.24
Vagrant: 1.8.1
Someone adviced to boot a live system and chroot into broken system and change password. Trying now
Open VirtualBox application.
Show wanted machine window.
There you have login prompt.
Enter root as login and vagrant as password.
Logged in. Change whatever you want.
Using ssh -p 2222 root#127.0.0.1 and using vagrant password does not work.

Cannot make Vagrant SSH key-using connection in base initializing (authorized_keys permission issue)

I've tried to wake up base VM bento/centos-67.
$ vagrant version
Installed Version: 1.8.5
Latest Version: 1.8.5
You're running an up-to-date version of Vagrant!
$ vagrant init bento/centos-6.7; vagrant up --provider virtualbox; vagrant up
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'bento/centos-6.7'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'bento/centos-6.7' is up to date...
==> default: Setting the name of the VM: bento_default_1473166306806_14580
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 (guest) => 2200 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2200
default: SSH username: vagrant
default: SSH auth method: private key
default:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it's present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
default: Warning: Authentication failure. Retrying...
default: Warning: Authentication failure. Retrying...
default: Warning: Authentication failure. Retrying...
But in the same time I can use vagrant ssh with password vagrant.
So, what's wrong?..
Linked questions: #1
(Also reported the issue to chef)
Fix
The problem is: ~/.ssh/authorized_keys file with the public key which has 644 permissions but must be 600
$ ssh vagrant#127.0.0.1 -p 2200 # use password "vagrant"
[vagrant#localhost ~]$ chmod 600 ~/.ssh/authorized_keys
Now vagrant ssh can be used without asking.
The question is why it doesn't work from the box? What's went wrong? I have teach it how to define authorized_keys file properly? oO
Maybe this related to the vagrant bug.
It is definitely the Vagrant bug you are linking to and not the Bento box. I am the Bento box maintainer and we've dropped back to Vagrant 1.8.4 in our pipelines.

Vagrant ssh 'Authentication failure. Retrying…' repeated error - keys mismatch, cant find fix

I've been experiencing an irritating issue that I cant get around.
I am trying to vagrant up a centos7 system in this environment:
Windows 10
Hyper-V (not anniversary update version)
Docker image "serveit/centos-7" or "bluefedora/hyperv-alpha-centos7"
OpenSSH installed, private key configured
The contents of my Vagrantfile:
Vagrant.configure("2") do |config|
#config.vm.box = "serveit/centos-7"
config.vm.box = "bluefedora/hyperv-alpha-centos7"
config.ssh.private_key_path = "~/.vagrant.d/insecure_private_key"
config.ssh.forward_agent = true
end
I am getting this error when doing a vagrant up:
PS C:\Programs\vagrant_stuff\centos7> vagrant up
Bringing machine 'default' up with 'hyperv' provider...
==> default: Verifying Hyper-V is enabled...
==> default: Importing a Hyper-V instance
default: Cloning virtual hard drive...
default: Creating and registering the VM...
default: Successfully imported a VM with name: vagrantbox
==> default: Starting the machine...
==> default: Waiting for the machine to report its IP address...
default: Timeout: 120 seconds
default: IP: 192.168.137.6
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 192.168.137.6:22
default: SSH username: vagrant
default: SSH auth method: private key
default:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it's present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
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...
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...
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...
default: Warning: Authentication failure. Retrying...
default: Warning: Authentication failure. Retrying...
default: Warning: Authentication failure. Retrying...
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.
If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.
If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.
If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.
I can do an vagrant ssh-config:
Host default
HostName 192.168.137.6
User vagrant
Port 22
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile C:/Users/Kareem/.vagrant.d/insecure_private_key
IdentitiesOnly yes
LogLevel FATAL
ForwardAgent yes
I saw elsewhere that I should try vagrant halt and vagrant up to fix the issue. This didn't work.
I also deleted the .vagrant.d/insecure_private_key file and saw it was recreated. No problem, that's also expected.
Also vagrant ssh works with password:
PS C:\Programs\vagrant_stuff\centos7> vagrant ssh
vagrant#192.168.137.6's password:
[vagrant#localhost ~]$
So because I could SSH, I decided to check the .ssh/authorized_keys file:
[vagrant#localhost ~]$ cat .ssh/authorized_keys
[vagrant#localhost ~]$ cat /home/vagrant/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDIRcYs0HBn/BOjiKg9fGnoraVxRnnZk+6sM3waFFE1+U3aO8GQjRKxQsYgJNoyRmNVymzpP13kOoLodDsz
UKhdcO6dL+zAtmhsFTgmADMXxVzM3mfRWfPG2HdsU13Pof77A68Ln6z6X4jVG4cnsclYvz67Gudl7lZ9VI2TOdDn1V+7ZANlkGnqejIwA2RVWtYLgLQHU9p4
47nvRqId71XaG8BZpbONRzzrL49wWyjfc4h6SdaHVJZJB6kY+vkr31xw6TPIIlo2UHH7Ihlk6KADNo4wFJYF+ozIA7C792omzjN1zu1SayvCYNG21yZy/cCd
n2Hr158Jy83A9CslQPbT vagrant
Dafuq is this key?!?!
I'm quite sure this is not the public key that corresponds to Vagrant. This is also not my system public key. When I check the Vagrant Public key I get this:
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9H
ZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHi
lFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRd
K8jlqm8tehUc9c9WhQ== vagrant insecure public key
Furthermore, if I update my Vagrantfile to use my system private key:
#config.ssh.private_key_path = "~/.vagrant.d/insecure_private_key"
config.ssh.private_key_path = "~/.ssh/id_rsa"
I get a different public key in the VM, which is the Vagrant Public key:
[vagrant#localhost ~]$ cat /home/vagrant/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9H
ZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHi
lFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRd
K8jlqm8tehUc9c9WhQ== vagrant insecure public key
I also see that the provisioning process does not insert a new key. This all seems backwards, I thought that the key should only be updated if I use my private key, and that it should use my own.
HELP!
Can anyone help me find out why this is happening?
Turns out, there is a known bug in Vagrant 1.8.5 (Will be fixed in 1.8.6):
Details here
If you are using 1.8.5, you can download the updated version from PR #7611 using PowerShell:
[IO.File]::WriteAllLines("C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.8.5\plugins\guests\linux\cap\public_key.rb", (Invoke-WebRequest -Uri https://raw.githubusercontent.com/Poohblah/vagrant/41063204ca540c44f9555bd11ba9e76c7307bec5/plugins/guests/linux/cap/public_key.rb).Content)
Inside public_key.rb file find those at line 56 and append chmod 0600 ~/.ssh/authorized_keys like so:
if test -f ~/.ssh/authorized_keys; then
grep -v -x -f '#{remote_path}' ~/.ssh/authorized_keys > ~/.ssh/authorized_keys.tmp
mv ~/.ssh/authorized_keys.tmp ~/.ssh/authorized_keys
chmod 0600 ~/.ssh/authorized_keys
fi
rm -f '#{remote_path}'
Path for Windows: C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.8.5\plugins\guests\linux\cap\public_key.rb
Path for mac: /opt/vagrant/embedded/gems/gems/vagrant-1.8.5/plugins/guests/linux/cap/public_key.rb
check permissions inside vagrant instance:
chmod 600 /vagrant/.ssh/authorized_keys
chmod 700 /vagrant/.ssh
chmod 700 /vagrant # important too! (for me that was a reason of same error)
ssh keys will be used only with right permissions.
Also, as workaround, you can add to the Vagrantfile:
config.ssh.username = "vagrant"
config.ssh.password = "vagrant"
SSH into the vagrant machine and give this privilege.
vagrant#localhost:chmod 600 ~/.ssh/authorized_keys.
exit out comeback to the host and hit "vagrant reload"
It works!!!
I saw similar issue recently on Ubuntu. I canceled using ctrl-c and typed in vagrant up and it worked fine.
My setup:
rm -rf Vagrantfile
vagrant init --box-version 20220405.0.0 ubuntu/jammy64
vagrant up
My vagrant version is 2.2.6