SSH auth方法:VirtualBox中的私钥调用登录

时间:2017-05-05 08:49:40

标签: vagrant

我在Windows上遇到了vagrant的问题。运行vagrant up,它在SSH身份验证时停止,似乎在VirtualBox控制台中请求SSH登录凭据。

Windows 8.1控制台输出

C:\Users\leke\dev\Learning PHP 7>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'ubuntu/trusty32' is up to date...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 80 (guest) => 8080 (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:22
    default: SSH username: vagrant
    default: SSH auth method: private key

Oracle VM VirtualBox输出

Ubuntu 14.04.5 LTS vagrant-ubuntu-trusty-32 tty1 
vagrant-ubuntu-trusty-32 login: 

如果我使用私钥认证,我不需要输入凭证(我不知道)。

这是我的设置,取自学习PHP 7

一书

流浪文件

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "ubuntu/trusty32"
  config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1", id: 'ssh'
  config.vm.provision "shell", path: "provisioner.sh"
end

provisioner.sh

#!/bin/bash

sudo apt-get install python-software-properties -y
sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php -y
sudo apt-get update
sudo apt-get install php7.0 php7.0-fpm php7.0-mysql -y
sudo apt-get --purge autoremove -y
sudo service php7.0-fpm restart

sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password root'
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password root'
sudo apt-get -y install mysql-server mysql-client
sudo service mysql start

sudo apt-get install nginx -y
sudo cat > /etc/nginx/sites-available/default <<- EOM
server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /vagrant;
    index index.php index.html index.htm;

    server_name server_domain_or_IP;

    location / {
        try_files \$uri \$uri/ /index.php?\$query_string;
    }

    location ~ \.php\$ {
        try_files \$uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)\$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
        include fastcgi_params;
    }
}
EOM
sudo service nginx restart

之后我收到超时错误消息。我需要做什么才能使vagrant up命令通过私钥传递身份验证并希望正确执行?注意,已安装git并且Windows路径变量中存在ssh.exe。谢谢。

修改:我设法找到凭据vagrantvagrant,但登录到VM框终端后,Windows控制台仍然卡在同一个地方。

更新

添加

config.vm.provider 'virtualbox' do |vb|
    vb.customize ['modifyvm', :id, '--cableconnected1', 'on']
end

给了我另一个问题。当我更改端口时,它会再次给我这个消息,或者给我原始问题。

C:\Users\leke\dev\Learning PHP 7>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/trusty32'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/trusty32' is up to date...
==> default: A newer version of the box 'ubuntu/trusty32' is available! You currently
==> default: have version '20170502.0.0'. The latest is version '20170504.0.0'. Run
==> default: `vagrant box update` to update.
==> default: Setting the name of the VM: LearningPHP7_default_1494189218317_29456
==> default: Clearing any previously set forwarded ports...
Vagrant cannot forward the specified ports on this VM, since they
would collide with some other application that is already listening
on these ports. The forwarded port to 3344 is already in use
on the host machine.

To fix this, modify your current project's Vagrantfile to use another
port. Example, where '1234' would be replaced by a unique host port:

  config.vm.network :forwarded_port, guest: 80, host: 1234

Sometimes, Vagrant will attempt to auto-correct this for you. In this
case, Vagrant was unable to. This is usually because the guest machine
is in a state which doesn't allow modifying port forwarding. You could
try 'vagrant reload' (equivalent of running a halt followed by an up)
so vagrant can attempt to auto-correct this upon booting. Be warned
that any unsaved work might be lost.

2 个答案:

答案 0 :(得分:0)

我已经看到了这一点。对我来说,事实上虚拟盒子没有被旋转,并且电缆连接了#34;。您可以在设置&gt; network&gt; advanced中进行检查。  https://github.com/mitchellh/vagrant/issues/7648

将此添加到您的Vagrantfile应解决该问题

config.vm.provider 'virtualbox' do |vb| vb.customize ['modifyvm', :id, '--cableconnected1', 'on'] end

答案 1 :(得分:0)

对我有用的解决方案:

  • 重新安装virtualbox和流浪汉

  • 以管理员身份打开Windows CMD

    'path'
  • 重启PC