首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ssh‘身份验证失败.重试…’重复错误键错配,找不到修复

问ssh‘身份验证失败.重试…’重复错误键错配,找不到修复
EN

Stack Overflow用户
提问于 2016-07-29 12:51:44
回答 4查看 14.3K关注 0票数 5

我一直在经历一个令人恼火的问题,我无法回避。

在这个环境中,我正在尝试vagrant up一个centos7系统:

  • Windows 10
  • 超音波V(非周年更新版)
  • 码头形象"serveit/centos-7“或”bluefedora/hyperv-alpha-centos 7“
  • 安装了OpenSSH,配置了私钥

我的Vagrantfile的内容:

代码语言:javascript
复制
Vagrant.configure("2") do |config|
  #config.vm.box = "serveit/centos-7"
  config.vm.box = "bluefedora/hyperv-alpha-centos7"
  config.ssh.private_key_path = "~/.vagrant.d/insecure_private_key"
  config.ssh.forward_agent = true
end

在执行vagrant up时,我会得到这个错误

代码语言:javascript
复制
PS C:\Programs\vagrant_stuff\centos7> vagrant up
Bringing machine 'default' up with 'hyperv' provider...
==> default: Verifying Hyper-V is enabled...
==> default: Importing a Hyper-V instance
    default: Cloning virtual hard drive...
    default: Creating and registering the VM...
    default: Successfully imported a VM with name: vagrantbox
==> default: Starting the machine...
==> default: Waiting for the machine to report its IP address...
    default: Timeout: 120 seconds
    default: IP: 192.168.137.6
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 192.168.137.6:22
    default: SSH username: vagrant
    default: SSH auth method: private key
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.

我可以做vagrant ssh-config

代码语言:javascript
复制
Host default
  HostName 192.168.137.6
  User vagrant
  Port 22
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile C:/Users/Kareem/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL
  ForwardAgent yes

我在其他地方看到,我应该尝试vagrant halt和vagrant up来解决这个问题。这不管用。

我还删除了.vagrant.d/insecure_private_key文件,并看到它被重新创建了。没问题,这也是意料之中的。

此外,vagrant ssh还可以使用密码:

代码语言:javascript
复制
PS C:\Programs\vagrant_stuff\centos7> vagrant ssh
vagrant@192.168.137.6's password:
[vagrant@localhost ~]$

因此,因为我可以使用SSH,所以我决定检查.ssh/authorized_keys文件:

流浪汉@localhost ~$ cat ..ssh/授权密钥

代码语言:javascript
复制
[vagrant@localhost ~]$ cat /home/vagrant/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDIRcYs0HBn/BOjiKg9fGnoraVxRnnZk+6sM3waFFE1+U3aO8GQjRKxQsYgJNoyRmNVymzpP13kOoLodDsz
UKhdcO6dL+zAtmhsFTgmADMXxVzM3mfRWfPG2HdsU13Pof77A68Ln6z6X4jVG4cnsclYvz67Gudl7lZ9VI2TOdDn1V+7ZANlkGnqejIwA2RVWtYLgLQHU9p4
47nvRqId71XaG8BZpbONRzzrL49wWyjfc4h6SdaHVJZJB6kY+vkr31xw6TPIIlo2UHH7Ihlk6KADNo4wFJYF+ozIA7C792omzjN1zu1SayvCYNG21yZy/cCd
n2Hr158Jy83A9CslQPbT vagrant

Dafuq是这个密钥吗?!?!我很确定这不是对应于Vagrant的公钥。这也不是我的系统公钥。当我检查流浪公钥时,我得到以下信息:

代码语言:javascript
复制
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9H
ZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHi
lFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRd
K8jlqm8tehUc9c9WhQ== vagrant insecure public key

此外,如果我更新我的Vagrantfile以使用我的系统私钥:

代码语言:javascript
复制
  #config.ssh.private_key_path = "~/.vagrant.d/insecure_private_key"
  config.ssh.private_key_path = "~/.ssh/id_rsa"

我在VM中获得了一个不同的公钥,即流浪公钥

代码语言:javascript
复制
[vagrant@localhost ~]$ cat /home/vagrant/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9H
ZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHi
lFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRd
K8jlqm8tehUc9c9WhQ== vagrant insecure public key

我还看到,配置过程不会插入新的密钥。这一切似乎都是倒退的,我认为只有当我使用我的私钥时,才应该更新密钥,并且它应该使用我自己的密钥。

救命!

有人能帮我找出为什么会发生这种事吗?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2016-08-01 12:23:45

原来,Vagrant 1.8.5中有一个已知的bug (将在1.8.6中修复):

细节这里

如果您使用的是1.8.5,您可以使用PowerShell从PR PowerShell下载更新版本:

[IO.File]::WriteAllLines("C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.8.5\plugins\guests\linux\cap\public_key.rb", (Invoke-WebRequest -Uri https://raw.githubusercontent.com/Poohblah/vagrant/41063204ca540c44f9555bd11ba9e76c7307bec5/plugins/guests/linux/cap/public_key.rb).Content)

票数 7
EN

Stack Overflow用户

发布于 2016-09-23 04:41:31

在public_key.rb文件中,可以在第56行找到这些文件,并添加如下所示的chmod 0600 ~/.ssh/authorized_keys:

代码语言:javascript
复制
         if test -f ~/.ssh/authorized_keys; then

           grep -v -x -f '#{remote_path}' ~/.ssh/authorized_keys > ~/.ssh/authorized_keys.tmp

           mv ~/.ssh/authorized_keys.tmp ~/.ssh/authorized_keys
           chmod 0600 ~/.ssh/authorized_keys
         fi

         rm -f '#{remote_path}'

Windows:C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.8.5\plugins\guests\linux\cap\public_key.rb

mac的路径:/opt/vagrant/embedded/gems/gems/vagrant-1.8.5/plugins/guests/linux/cap/public_key.rb

票数 2
EN

Stack Overflow用户

发布于 2019-01-10 13:57:55

检查流浪实例中的权限:

代码语言:javascript
复制
chmod 600 /vagrant/.ssh/authorized_keys
chmod 700 /vagrant/.ssh
chmod 700 /vagrant        # important too! (for me that was a reason of same error)

ssh键将仅与正确的权限一起使用。

另外,作为解决办法,您可以添加到Vagrantfile中:

代码语言:javascript
复制
  config.ssh.username = "vagrant"
  config.ssh.password = "vagrant"
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38659379

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档