【问题标题】:vagrant custom ssh key authentication failurevagrant 自定义 ssh 密钥认证失败
【发布时间】:2020-05-16 13:50:35
【问题描述】:

下面是我的 Vagrantfile

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

#Virtualbox host and vagrant host/network confs
#
Vagrant.configure("2") do |config|
  config.vm.define "slave" do |slave|
    slave.vm.box = "centos/7"
    slave.vm.hostname = "slave.ansible.com"
    slave.vm.network :private_network, ip: "192.168.99.102"
    slave.ssh.insert_key = false
    slave.vm.boot_timeout = 800
    slave.ssh.private_key_path = ["keys/id_rsa_slave"]
    slave.vm.provision "file", source: "keys/id_rsa_slave.pub", destination: "~/.ssh/authorized_keys"
  end

    config.vm.provider "virtualbox" do |vb|
      vb.cpus = "1"
      vb.memory = "512"
    end

这个 Vagrantfile 位于我的主目录 (/user/gokul/slave) 下的 slave 文件夹中,在此之下,我有具有以下键和适当权限的键目录

(base) Gokul:slave gokul$ ls -lt keys/
total 16
-rw-------  1 gokul  gokul   565 May 16 18:30 id_rsa_slave.pub
-rw-------  1 gokul  gokul  2590 May 16 18:30 id_rsa_slave

keys目录的权限也可以

(base) Gokul:slave gokul$ ls -ld keys/
drwx------  4 gokul  gokul  128 May 16 18:30 keys/

现在我运行下面的命令来启动我的 vagrant box

流浪

此时它挂起,无法进行身份验证

==> master: Waiting for machine to boot. This may take a few minutes...
    master: SSH address: 127.0.0.1:2200
    master: SSH username: vagrant
    master: SSH auth method: private key
    master: Warning: Authentication failure. Retrying...
    master: Warning: Authentication failure. Retrying...

SSH authentication failed! This is typically caused by the public/private
keypair for the SSH user not being properly set on the guest VM. Please
verify that the guest VM is setup with the proper public key, and that
the private key path for Vagrant is setup properly as well.

启用调试后,我还可以看到它获取了我要求的私钥,但是,它未能成功进行身份验证,并因上述错误而失败。

【问题讨论】:

    标签: ssh vagrant private-key vagrantfile public-key


    【解决方案1】:

    想通了。我正在使用的自定义密钥应附加到默认的 vagrant 密钥 - ~/.vagrant.d/insecure_private_key

    所以这个配置

    slave.ssh.private_key_path = ["keys/id_rsa_slave"]
    

    应该改为

    slave.ssh.private_key_path = ["keys/id_rsa_slave", "~/.vagrant.d/insecure_private_key"]
    

    做出这个改变后,我跑了

    流浪

    而且成功了。

    【讨论】:

      猜你喜欢
      • 2023-03-18
      • 2015-01-16
      • 1970-01-01
      • 2014-05-20
      • 1970-01-01
      • 2010-11-19
      • 2021-03-16
      • 2011-11-17
      • 2020-07-15
      相关资源
      最近更新 更多