vagrant asks password at only the first time 'vagrant up'

。_饼干妹妹 提交于 2019-12-22 06:37:50

问题


I made my custom vagrant box for CentOS 6.6. My question is why vagrant always requires password when I 'vagrant up' at only first time. Here is the console log:

$ vagrant up
Bringing machine 'ns' up with 'virtualbox' provider...
==> ns: Clearing any previously set forwarded ports...
==> ns: Clearing any previously set network interfaces...
==> ns: Preparing network interfaces based on configuration...
    ns: Adapter 1: nat
    ns: Adapter 2: hostonly
==> ns: Forwarding ports...
    ns: 22 => 2222 (adapter 1)
==> ns: Running 'pre-boot' VM customizations...
==> ns: Booting VM...
==> ns: Waiting for machine to boot. This may take a few minutes...
    ns: SSH address: 127.0.0.1:2222
    ns: SSH username: vagrant
    ns: SSH auth method: private key
    ns: Warning: Connection timeout. Retrying...
    ns: Warning: Connection timeout. Retrying...
    ns: Warning: Remote connection disconnect. Retrying...
Text will be echoed in the clear. Please install the HighLine or Termios libraries to suppress echoed text.
vagrant@127.0.0.1's password: 

As you see, vagrant asks password. It continues after I type it. After that, vagrant never ask it whenever I do 'vagrant up'. This occurs at only the first time 'vagrant up'. I wonder something of my custom box's setting, maybe ssh, is wrong but don't understand where the problem is.

Can anybody guess the possible causes?

Environment: the version of vagrant is 1.7.2. Host OS is ubuntu 15.04 and Guest OS is CentOS 6.6.


回答1:


Vagrant asks for the password when it can't login automatically. The most obvious reason is that Vagrant does not have the required user key for the user vagrant. Then your entering the correct password and vagrant exchanges the key. Afterwards this does not appear anymore. This key exchange is manager per instance, so if you destroy/delete the instance then next time your ask again to login manually.

Vagrant offers an insecure key on Github and any distributed public available Vagrant box is packaged with it. You can put this key by executing this inside the machine:

wget https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub -O /home/vagrant/.ssh/authorized_keys

The other way is to use your own private key and configure the Vagrantfile to use the specific key: Vagrant SSH Config

Vagrant itself will recognize and exchange the insecure key immediately and exchange it for a secure one. Therefore, you have to set this key with Hashicorp Packer.




回答2:


You may also want to try the default vagrant password: vagrant.




回答3:


I entered the password "vagrant" when this happened to me and got right in. See this Vagrant Github issue. Also see this stackoverflow question.



来源:https://stackoverflow.com/questions/31306192/vagrant-asks-password-at-only-the-first-time-vagrant-up

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!