Vagrant ssh authentication failure
Solution 1:
For general information: by default to ssh-connect you may simply use
user: vagrant
password: vagrant
https://www.vagrantup.com/docs/boxes/base.html#quot-vagrant-quot-user
First, try: to see what vagrant insecure_private_key
is in your machine config
$ vagrant ssh-config
Example:
$ vagrant ssh-config
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile C:/Users/konst/.vagrant.d/insecure_private_key
IdentitiesOnly yes
LogLevel FATAL
http://docs.vagrantup.com/v2/cli/ssh_config.html
Second, do:
Change the contents of file insecure_private_key
with the contents of your personal system private key
Or use: Add it to the Vagrantfile:
Vagrant.configure("2") do |config|
config.ssh.private_key_path = "~/.ssh/id_rsa"
config.ssh.forward_agent = true
end
-
config.ssh.private_key_path
is your local private key - Your private key must be available to the local ssh-agent. You can check with
ssh-add -L
. If it's not listed, add it withssh-add ~/.ssh/id_rsa
- Don't forget to add your public key to
~/.ssh/authorized_keys
on the Vagrant VM. You can do it by copy-and-pasting or using a tool like ssh-copy-id (user:root
password:vagrant
port: 2222)ssh-copy-id '-p 2222 [email protected]'
If still does not work try this:
Remove
insecure_private_key
file fromc:\Users\USERNAME\.vagrant.d\insecure_private_key
Run
vagrant up
(vagrant will be generate a newinsecure_private_key
file)
In other cases, it is helpful to just set forward_agent in Vagrantfile
:
Vagrant::Config.run do |config|
config.ssh.forward_agent = true
end
Useful:
Configurating git may be with git-scm.com
After setup this program and creating personal system private key will be in yours profile path: c:\users\USERNAME\.ssh\id_rsa.pub
PS: Finally - suggest you look at Ubuntu on Windows 10
Solution 2:
None of the above worked for me. Somehow the box had the wrong public key added in the vagrant user authorised_keys file.
If you can still ssh on the box with the vagrant password (password is vagrant), i.e.
ssh vagrant@localhost -p 2222
then copy the public key content from https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub to the authorised_keys file with the following command
echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" > .ssh/authorized_keys
When done exit the VM and try vagrant ssh again. It should work now.
Solution 3:
If you experience this issue on vagrant 1.8.5, then check out this thread on github:
https://github.com/mitchellh/vagrant/issues/7610
It's caused basically by a permission issue, the workaround is just
vagrant ssh
password: vagrant
chmod 0600 ~/.ssh/authorized_keys
exit
then
vagrant reload
FYI: this issue only affects CentOS, Ubuntu works fine.
Solution 4:
Run the following commands in guest machine/VM:
wget https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub -O ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chown -R vagrant:vagrant ~/.ssh
Then do vagrant halt. This will remove and regenerate your private keys.
(These steps assume you have already created or already have the ~/.ssh/ and ~/.ssh/authorized_keys directories under your home folder.)
Solution 5:
In my experience, this has been a surprisingly frequent problem with new vagrant machines. By far the easiest way to solve it, instead of altering the configuration itself, has been creating the required ssh keys manually on the client, then using the private key on the host.
- Log in to vagrant machine:
vagrant ssh
, use default passwordvagrant
. - Create ssh keys: for example,
ssh-keygen -t rsa -b 4096 -C "vagrant"
(as adviced by GitHub's relevant guide). - Rename the public key file (by default id_rsa.pub), overriding the old one:
mv .ssh/id_rsa.pub .ssh/authorized_keys
. - Reload ssh service in case needed:
sudo service ssh reload
. - Copy the private key file (by default id_rsa) to the host machine: for instance, use a fine combination of cat and clipboard,
cat .ssh/id_rsa
, paint and copy (better ways must exist, go invent one!). - Logout from the vagrant machine:
logout
. - Find the current private key used by vagrant by looking at its configuration:
vagrant ssh-config
(look for instance ÌdentityFile "/[...]/private_key". - Replace the current private key with the one you created at the host machine: for example,
nano /[...]/private_key
and paste from the clipboard, if all else fails. (Note, however, that if your private_key is not project specific but shared by multiple vagrant machines, you better configure the path yourself in order to not break other perfectly working machines! Changing the path is as simple as adding a lineconfig.ssh.private_key_path = "path/to/private_key"
into the Vagrantfile.) Furthermore, if you are using PuPHPet generated machine, you can store your private key to filepuphpet/files/dot/ssh/id_rsa
and it will be added to Vagrantfile's ssh config automatically. - Test the setup:
vagrant ssh
should now work.
Should that be the case, congratulate yourself, logout
, run vagrant provision
if needed and carry on with the meaningful task at hand.
If you still face problems, it may come handy to add verbose flag to ssh command to ease debugging. You can pass that (or any other option, for that matter) after double dash. For example, typing vagrant ssh -- -v
. Feel free to add as many v's as you need, each will give you more information.