Vagrant SSH authentication failure

242 views
Skip to first unread message

Nicola

unread,
Feb 4, 2015, 9:16:55 AM2/4/15
to vagra...@googlegroups.com
Hi to all, this is my first message.
My first deploy of vagrant is a Freebsd box for HyperV. The box if, vagrant up goes up but when the script vagrant is on:

freebsd10: IP: 172.16.0.10
freebsd10: Waiting for machine to boot. This may take a few minutes...
freebsd10: SSH address: 172.16.0.10:22
freebsd10: SSH username: vagrant
freebsd10: SSH auth method: private key
freebsd10: Warning: Authentication failure. Retrying...
freebsd10: Warning: Authentication failure. Retrying...
freebsd10: Warning: Authentication failure. Retrying...

The ssh connection doesn't work. And then config.vm.hostname doesn't work. if i try to connect to the vm via putty the connection is ok but via vagrant no.

Any ideas?

Thanks a lot
Nicola

Bogdan B

unread,
Feb 4, 2015, 10:08:48 AM2/4/15
to vagra...@googlegroups.com
Hi,
Try connecting to ssh using command line with -v ( or -vvv) option.
It might be that your key file has wrong permissions (needs to be read only)

--
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nicola

unread,
Feb 4, 2015, 10:23:46 AM2/4/15
to vagra...@googlegroups.com
Also the ssh connection via username and password in vagrant (vagrantfile) doesn't work, but in putty with the same credential the connection is ok.

Bogdan B

unread,
Feb 4, 2015, 10:31:15 AM2/4/15
to vagra...@googlegroups.com
Do a ssh -vvv vag...@172.16.0.10 and check the output.

Nicola

unread,
Feb 4, 2015, 10:45:08 AM2/4/15
to vagra...@googlegroups.com
The host machine is a windows server, I've not ssh in windows. In other unix server the connection is ok via password but not via key. The problem in vagrant remains.

Alvaro Miranda Aguilera

unread,
Feb 4, 2015, 3:20:44 PM2/4/15
to vagra...@googlegroups.com
On Thu, Feb 5, 2015 at 4:45 AM, Nicola <nickw...@gmail.com> wrote:
> n other unix server the connection is ok via password but not via key.

Hello:

2 things.

A. Can be an issue with the key on the box.

check if there is a file called .ssh/authorized_keys in the home of
the vagrant user, and the content is the same like this:

https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub

must be 1 line.


then chek the permissions, usually this will fix if there is a
permissions issue:

chown -R vagrant:vagrant ~vagrant/.ssh/
chmod -R 600 ~vagrant/.ssh/
chmod 700 ~vagrant/.ssh

and try again.

If still doesn't work.

B. if you can connect with user and password you can tell vagrant to use that

check this:
https://docs.vagrantup.com/v2/vagrantfile/ssh_settings.html

basically add to your vagrantfile:

config.ssh.password = "password"

Alvaro.

Nicola

unread,
Feb 5, 2015, 4:39:55 AM2/5/15
to vagra...@googlegroups.com
Thanks Alvaro, now it's ok. The problem is the ssh key in the vagrant's home. Another question. I't's possible to generate a random hostname using the vagrantfile?

Nicola

Alvaro Miranda Aguilera

unread,
Feb 5, 2015, 5:16:56 AM2/5/15
to vagra...@googlegroups.com
On Thu, Feb 5, 2015 at 10:39 PM, Nicola <nickw...@gmail.com> wrote:
> nother question. I't's possible to generate a random hostname using the

Hello,

Not sure what you mean by random,. can you give an example? say
4345234534523462345623456235 ??

Vagrantfile is ruby code, so some basic ruby can be used inside.

you can setup the hostname with

config.vm.hostname = "myawesomebox"

that will set the hostname inside the box.

I use this to set the time stamp as part of the name of the vm in the
gui for virtualbox:

vm_name_app = "collaba" do |config|
config.vm.hostname = "#{vm_name_app}.racattack"
config.vm.provider :virtualbox do |vb|
vb.name = vm_name_app + "." + Time.now.strftime("%y%m%d%H%M")
end
end

if a timestamp works for you, since you won't be starting 2 vms at the
same time, you may try that

config.vm.hostname = Time.now.strftime("%y%m%d%H%M%S")


if this doesn't work for you.. provide an example of what you mean by
random.. on the mailing list are very clever guys that have high
ruby-fu, so they can provide some better ideas

Alvaro.

Nicola

unread,
Feb 5, 2015, 5:26:38 AM2/5/15
to vagra...@googlegroups.com
For random I mean a type that:

config.vm.hostname = "vagrant_dev#{rand(01..99)}.local.domain}". It's possible?

Thanks a lot Alvaro
Nicola

Alvaro Miranda Aguilera

unread,
Feb 5, 2015, 5:40:26 AM2/5/15
to vagra...@googlegroups.com
On Thu, Feb 5, 2015 at 11:26 PM, Nicola <nickw...@gmail.com> wrote:
> config.vm.hostname = "vagrant_dev#{rand(01..99)}.local.domain}"

Yeah that works, you have an extra } at the end.

take note the Vagrantfile is read top to botton and when you start
using blocks the vagrantfile can be read serveral times, specially if
you later puts loops, etc

so I would use something like this to make sure the name is set once
for each read, so the variable have the same value if you end using
that on multiples lines of the Vagrantfile later

Vagrant.configure(2) do |config|
vm_name ||= "vagrant_dev#{rand(01..99)}.local.domain"
config.vm.box = "kikitux/oracle6"
config.vm.hostname = vm_name
end

Alvaro

Nicola

unread,
Feb 5, 2015, 6:03:29 AM2/5/15
to vagra...@googlegroups.com
This is the result:

vm:
* The hostname set for the VM should only contain letters, numbers,
hyphens or dots. It cannot start with a hyphen or dot.

I've tried that script in a lot of different way, but I've always an error.

Nicola

Alvaro Miranda Aguilera

unread,
Feb 5, 2015, 6:41:44 AM2/5/15
to vagra...@googlegroups.com
replace _ with - on the name


Vagrant.configure(2) do |config|
vm_name ||= "vagrant-dev#{rand(01..99)}.local.domain"
config.vm.box = "kikitux/oracle6"
config.vm.hostname = vm_name
end


Nicola

unread,
Feb 5, 2015, 6:49:34 AM2/5/15
to vagra...@googlegroups.com
Nope. I've tried in more way, but the error is the same.

Alvaro Miranda Aguilera

unread,
Feb 5, 2015, 6:57:57 AM2/5/15
to vagra...@googlegroups.com
Strange, works for me

can you send your vagrantfile in a zip? or put in a gist/pastebin?

this my test


[root@ml330 random]# cat Vagrantfile

Vagrant.configure(2) do |config|
vm_name ||= "vagrant-dev#{rand(01..99)}.local.domain"
config.vm.box = "kikitux/oracle6"
config.vm.hostname = vm_name
end
[root@ml330 random]#


[root@ml330 random]# vagrant ssh -c "hostname"
vagrant-dev76.local.domain
Connection to 127.0.0.1 closed.
[root@ml330 random]#

vagrant reload

then

[root@ml330 random]# vagrant ssh -c "hostname"
vagrant-dev82.local.domain
Connection to 127.0.0.1 closed.
[root@ml330 random]#

Nicola

unread,
Feb 5, 2015, 8:04:19 AM2/5/15
to vagra...@googlegroups.com
Attached you can find the file.
Thanks
vagrantfile.zip

Alvaro Miranda Aguilera

unread,
Feb 5, 2015, 3:44:31 PM2/5/15
to vagra...@googlegroups.com
ok, you have a typo

"vagrant-symfony2{rand(01..99)}.local.domain"

that 2 should be #

try this:

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(2) do |config|

# Every Vagrant virtual environment requires a box to build off of.
config.vm.define :freebsd10 do |freebsd10|
#freebsd10.vm.box = "symfony2"
freebsd10.vm.box = "kikitux/oracle7"
#vm_name ||= "vagrant-symfony2{rand(01..99)}.local.domain"
vm_name ||= "vagrant-symfony#{rand(01..99)}.local.domain"
puts vm_name
freebsd10.vm.hostname = vm_name
end

config.vm.network "forwarded_port", guest: 80, host: 8080

config.ssh.username = "vagrant"
config.ssh.insert_key = 'true'

end

Nicola

unread,
Feb 6, 2015, 5:04:48 AM2/6/15
to vagra...@googlegroups.com
Yeaah, now it's ok.
Now work on versioning of the my custom box.

Thanks a lot
Nicola
Reply all
Reply to author
Forward
0 new messages