My vagrant was working perfectly fine last night. I've just turned the PC on, hit vagrant up, and this is what I get:
vagrant up
Bringing machine 'machine1' up with 'virtualbox' provider...
==> machine1: Checking if box 'puphpet/ubuntu1404-x64' is up to date...
==> machine1: Clearing any previously set forwarded ports...
==> machine1: Clearing any previously set network interfaces...
==> machine1: Preparing network interfaces based on configuration...
machine1: Adapter 1: nat
machine1: Adapter 2: hostonly
==> machine1: Forwarding ports...
machine1: 22 (guest) => 9180 (host) (adapter 1)
machine1: 22 (guest) => 2222 (host) (adapter 1)
==> machine1: Running 'pre-boot' VM customizations...
==> machine1: Booting VM...
==> machine1: Waiting for machine to boot. This may take a few minutes...
machine1: SSH address: 127.0.0.1:2222
machine1: SSH username: vagrant
machine1: SSH auth method: private key
machine1: Warning: Remote connection disconnect. Retrying...
machine1: Warning: Remote connection disconnect. Retrying...
machine1: Warning: Authentication failure. Retrying...
machine1: Warning: Authentication failure. Retrying...
machine1: Warning: Authentication failure. Retrying...
machine1: Warning: Authentication failure. Retrying...
machine1: Warning: Authentication failure. Retrying...
machine1: Warning: Authentication failure. Retrying...
machine1: Warning: Authentication failure. Retrying...
machine1: Warning: Authentication failure. Retrying...
When I tried to connect I see this:
Using username "vagrant".
Server refused our key
vagrant#127.0.0.1's password:
But my key file didn't change. There is similar question Vagrant stuck connection timeout retrying but there is other reason and it not helped me.
There is ssh-config
> vagrant ssh-config
Host machine1
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile "C:/puphpet/puphpet/files/dot/ssh/id_rsa"
IdentityFile "C:/Users/alexk/.vagrant.d/insecure_private_key"
IdentitiesOnly yes
LogLevel FATAL
Add the following line of code to C:\HashiCorp\vagrant\embedded\gems\gems\vagrant-1.8.5\plugins\guests\linux\cap\public_key.rb:
chmod 0600 ~/.ssh/authorized_keys
Original block:
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
fi
New block:
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
I had the same problem and found the above solution here.
Related
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.
I have an Ubuntu 16.04 LTS and three Vagrant/VirtualBox VMs that need to be turned on at the same time
When I installed Vagrant with VirtualBox, the first day, SSH connection was going correctly. At the following day I obtained this at the three machines (Here is an example of one of them):
xxxx-callserver#xxxxcallserver-Precision-WorkStation-T5400:~/VM$ vagrant up vvs --provision
Bringing machine 'vvs' up with 'virtualbox' provider...
==> vvs: Checking if box 'dmservices/fedora17-x86_64' is up to date...
==> vvs: Clearing any previously set forwarded ports...
==> vvs: Clearing any previously set network interfaces...
==> vvs: Preparing network interfaces based on configuration...
vvs: Adapter 1: nat
vvs: Adapter 2: hostonly
==> vvs: Forwarding ports...
vvs: 22 (guest) => 2222 (host) (adapter 1)
==> vvs: Running 'pre-boot' VM customizations...
==> vvs: Booting VM...
==> vvs: Waiting for machine to boot. This may take a few minutes...
vvs: SSH address: 127.0.0.1:2222
vvs: SSH username: vagrant
vvs: SSH auth method: password
vvs: Warning: Remote connection disconnect. Retrying...
vvs: Warning: Authentication failure. Retrying...
Until it triggers a Time Out
And when I try to vagrant ssh vvs, with or without --plain:
==> vvs: The machine you're attempting to SSH into is configured to use
==> vvs: password-based authentication. Vagrant can't script entering the
==> vvs: password for you. If you're prompted for a password, please enter
==> vvs: the same password you have configured in the Vagrantfile.
Permission denied (publickey).
This the part of the Vagrantfile for that machine (the only differences between the three machines is the name, the ip (inside the same network 192.168.33.0/24) and that the other two are debian/jessie64):
Vagrant.configure("2") do |config|
...
...
config.vm.define "vvs" do |vvs|
vvs.vm.hostname = "vvs"
vvs.vm.box = "dmservices/fedora17-x86_64"
vvs.vm.network "private_network", ip: "192.168.33.4"
vvs.ssh.username = "vagrant"
vvs.ssh.password = "vagrant"
vvs.vm.synced_folder "/home/xxxx-callserver/NetBeansProjects", "/NetBeansProjects", create: true, type: "virtualbox"
vvs.vm.provider "virtualbox" do |v|
v.memory = 2048
v.cpus = 2
v.customize ["modifyvm", :id, "--vram", "64"]
end
end
Thanks in advance and ask me for more info if needed
EDIT: Output of vagrant ssh-config
Host avaya
HostName 127.0.0.1
User vagrant
Port 2201
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /home/xxxx-callserver/VM/.vagrant/machines/avaya/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
Host videogateway
HostName 127.0.0.1
User vagrant
Port 2200
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /home/xxxx-callserver/VM/.vagrant/machines/videogateway/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
Host vvs
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentitiesOnly yes
LogLevel FATAL
Please check whether you explicitly forwarding each of your Vagrant guest port 22 to different host port. I am not familiar with vagrant script, but you really need a line to explicitly specify different port, because default Vagrant always map 22 to 2222. For multiple VM. This mean only the first vagrant VM will map it correct, the rest will failed. In Vagrantfile, you need something like this for each guest machine.
# avaya
config.vm.network :forwarded_port, id: 'ssh', guest:22, host: 2201,
# videogateway
config.vm.network :forwarded_port, id: 'ssh', guest:22, host: 2200,
# vvs
config.vm.network :forwarded_port, id: 'ssh', guest:22, host: 2222,
Since you already have the first VM setup the port forwarding from 22 to 2222, all the 3 VM will failed change the port forwarding map. Perhaps you should consider change host vvs forwarding to different host port, so it will not conflict with future adhoc vagrant startup that use the default power forwarding.
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.
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
I have problems to run Vagrant with Docker. The issue is the rsync of the shared folders.
WDFM32388067A:vagranttest d022051$ vagrant up
Bringing machine 'default' up with 'docker' provider...
==> default: Docker host is required. One will be created if necessary...
default: Vagrant will now create or start a local VM to act as the Docker
default: host. You'll see the output of the `vagrant up` for this VM below.
default:
default: Importing base box 'hashicorp/boot2docker'...
default: Matching MAC address for NAT networking...
default: Checking if box 'hashicorp/boot2docker' is up to date...
default: Setting the name of the VM: docker-host_default_1438155600426_39792
default: Clearing any previously set network interfaces...
default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Forwarding ports...
default: 2375 => 2375 (adapter 1)
default: 22 => 2222 (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: docker
default: SSH auth method: password
default: Warning: Connection timeout. Retrying...
default: Machine booted and ready!
==> default: Syncing folders to the host VM...
default: Installing rsync to the VM...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
rsync --help
Stdout from the command:
Stderr from the command:
sh: rsync: not found
default: The previous process exited with exit code 1.
default: The previous process exited with exit code 1.
From the error message it is not clear whether ssh or rsync is the issue. Maybe it is because ssh is timing out. I tried all possible ssh options but nothing did work out. For example I set an config.ssh.private_key_path but still the error message was exactly the same. Has anybody had similar issues?
I was also stuck with hashicorp/boot2docker. Moving to mitchell/boot2docker didn't help, either, but I found that
https://vagrantcloud.com/dduportal/boxes/boot2docker
works well (and is more up-to-date).