流浪者计算机无法通过ssh与我新创建的用户进行身份验证

时间:2018-09-12 11:29:47

标签: ruby ssh vagrant vagrantfile

我的vagrantfile看起来像这样:

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

vagrant_home = "/home/vagrant/"
local_share = "#{ENV['HOME']}"

unless Vagrant.has_plugin?("vagrant-vbguest")
  puts "Vagrant plugin 'vagrant-vbguest' is not installed!"
  puts "Execute: vagrant plugin install vagrant-vbguest"
end

unless Vagrant.has_plugin?("vagrant-sshfs")
  puts "Vagrant plugin 'vagrant-sshfs' is not installed!"
  puts "Execute: vagrant plugin install vagrant-sshfs"
end

Vagrant.configure("2") do |stage|
    stage.vm.box = "centos/7"
    stage.vm.hostname = "HSS-IAAS-VB"
    stage.vm.box_check_update = true
    stage.vm.network "private_network", :type => 'dhcp'
    stage.vm.provider "virtualbox" do |vb|
      vb.name = "centos7-dev"
      vb.gui = false
      vb.memory = "1024"
    stage.ssh.keys_only = false
    stage.ssh.username = "#{ENV['USER']}"
    stage.ssh.forward_agent    = true
    stage.ssh.insert_key       = true
    stage.ssh.private_key_path =  "#{ENV['HOME']}/.ssh/id_rsa" , "/home/#{ENV['USER']}/.ssh/id_rsa
    stage.vm.provision :shell, privileged: false do |s|
      ssh_pub_key = File.readlines("#{Dir.home}/.ssh/id_rsa.pub").first.strip
      s.inline = <<-SHELL
        echo #{ssh_pub_key} >> #{ENV['home']}.ssh/authorized_keys
        sudo bash -c \"echo #{ssh_pub_key} >> #{ENV['home']}/.ssh/authorized_keys\"
      SHELL
    end
  end
end

我的问题是,当我运行此vagrantfile时,收到一条错误消息,指出以下内容:default: Warning: Authentication failure. Retrying...,如果以调试模式运行,我只会看到一堆超时。

我要做的只是创建一个“无用的”用户,而不是创建一个与主机上的用户相同的用户,方法是使用#{ENV['USER']}并让该用户立即成为能够运行vagrant ssh,并且如果其主机用户是test.user,则来宾用户将是test.user ..

vagrant ssh-config是:

Host default
  HostName 127.0.0.1
  User aaron.west
  Port 2200
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /Users/aaron.west/.ssh/id_rsa
  IdentityFile /Users/aaron.west/.ssh/id_rsa
  LogLevel FATAL

感谢所有帮助:)

1 个答案:

答案 0 :(得分:0)

我相信您必须在Vagrant机器上创建一个新用户。根据{{​​3}}设置的文档,听起来好像该设置实际上无法创建用户。如果该框是使用 vagrant 以外的其他用户名创建的,则它只能帮助您告诉Vagrant以哪个用户身份连接。

在供应期间,您可能需要使用useradd