Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vagrant ssh promtps for password

I have a strange problem with vagrant ssh. Similar questions, like Vagrant asks for password after SSH key update, or (vagrant & ssh) require password, or Vagrant ssh authentication failure do not help me.

So, the plot.

I have a virtual machine running Ubuntu 14.04.3. All setup was made according to this article: https://blog.engineyard.com/2014/building-a-vagrant-box.

Note: I can ssh to this virtual machine using Putty with vagrant's insecure_private_key (converted to *.ppk), which is located "C:/Users/Gino/.vagrant.d/insecure_private_key. Password is not promtped.

Then I packaged this virtual machine, init vagrant with this package and ran vagrant up. I got "Warning: Authentication failure. Retrying..." error. But nevertheless I could vagrant ssh to this machine, but it asked me a password. And if I tried to ssh to it using Putty with the necessary key (as in the first paragraph), it asked me for a password too.

I vagrant halted this machine, found it in VirtualBox VM's list and ran it manually. After that I tried to ssh to this machine using Putty with the same key and succeed - I could logon without any password.

Result of vagrant ssh-config, if needed:

h:\VagrantBoxes\main-server32>vagrant ssh-config
Host default
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile "C:/Users/Gino/.vagrant.d/insecure_private_key"
  IdentitiesOnly yes
  LogLevel FATAL

My Vagrantfile (it was generated automatically, almost nothing there, only a suggested line from comments was added):

Vagrant.configure(2) do |config|
  config.vm.box = "vagrant-main-server32"

  config.ssh.insert_key = false
end

So what's the mystery here? Why ssh using key works without vagrant up and fails and prompts for password with it?

Note. Another funny thing: it still can not authenticate during vagrant up. But if at the time when errors "authentication failure" appear I log in to vm through virtualbox, it also succeed to log in in the window with vagrant up. And then vagrant ssh works.

like image 666
Gino Pane Avatar asked Jan 04 '16 20:01

Gino Pane


People also ask

Why does vagrant ask for password?

One might ask why I am using these settings (because normally vagrant is the default username and password). The reason is because for some reason the box generate some random password and uses ubuntu has the username.

What is vagrant ssh password?

If Vagrant prompts you for a username and password, the username is vagrant and the password is vagrant .

What is root password of vagrant box?

Root Password: "vagrant"


1 Answers

I had the same issue with vagrant 1.8.1, on several boxes I use (ie: geerlingguy/centos6)

I didn't have any problem with Vagrant 1.7 on those boxes.

After some research on why i could not ssh in that box, it appears that /home/vagrant on the box had 755 permissions and ssh prevent authentication to user with those permissions

extract of /var/log/secure:

Jan 28 15:11:36 server sshd[11721]: Authentication refused: bad ownership or modes for directory /home/vagrant

To fix that vm, I only have to change the permissions /home/vagrant (did a chmod 700 on it) and now i can ssh directly into my boxes

I don't knwo how to fix it directly I think you should modify your box directly

Hope this helps!

edit: I thought it was a shared folder from the host but it's /vagrant that is shared not /home/vagrant

like image 200
Vince Macbuche Avatar answered Oct 21 '22 01:10

Vince Macbuche