目录

vagrant up Authentication failure. Retrying

文章简介:ubuntu 22.04 vagrant up Authentication failure. Retrying, vagrant ssh 可以登录进 vm 问题处理

问题现象

vagrant up 会报错 default: Warning: Authentication failure. Retrying....

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
$ vagrant init ubuntu/jammy64 # ubuntu 22.04

$ vagrant up

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'rockylinux/9'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'rockylinux/9' version '1.0.0' is up to date...
==> default: Setting the name of the VM: network_default_1670762466033_92955
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (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:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Authentication failure. Retrying...
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$ vagrant --debug up
...
D, [2022-08-18T08:41:57.807561 #278356] DEBUG -- net.ssh.authentication.session[20120]: allowed methods: publickey
D, [2022-08-18T08:41:57.807635 #278356] DEBUG -- net.ssh.authentication.methods.none[20134]: none failed
D, [2022-08-18T08:41:57.807714 #278356] DEBUG -- net.ssh.authentication.session[20120]: trying publickey
D, [2022-08-18T08:41:57.809423 #278356] DEBUG -- net.ssh.authentication.agent[20148]: connecting to ssh-agent
D, [2022-08-18T08:41:57.809776 #278356] DEBUG -- net.ssh.authentication.agent[20148]: sending agent request 1 len 48
D, [2022-08-18T08:41:57.810239 #278356] DEBUG -- net.ssh.authentication.agent[20148]: received agent packet 5 len 1
D, [2022-08-18T08:41:57.810303 #278356] DEBUG -- net.ssh.authentication.agent[20148]: sending agent request 11 len 0
D, [2022-08-18T08:41:57.810656 #278356] DEBUG -- net.ssh.authentication.agent[20148]: received agent packet 12 len 841
D, [2022-08-18T08:41:57.811330 #278356] DEBUG -- net.ssh.authentication.methods.publickey[20170]: trying publickey (dd:3b:b8:2e:85:04:06:e9:ab:ff:a8:0a:c0:04:6e:d6)
D, [2022-08-18T08:41:57.811474 #278356] DEBUG -- socket[2010c]: using encrypt-then-mac
D, [2022-08-18T08:41:57.811624 #278356] DEBUG -- socket[2010c]: queueing packet nr 5 type 50 len 352
D, [2022-08-18T08:41:57.811724 #278356] DEBUG -- socket[2010c]: sent 420 bytes
D, [2022-08-18T08:41:57.819401 #278356] DEBUG -- socket[2010c]: read 100 bytes
D, [2022-08-18T08:41:57.819740 #278356] DEBUG -- socket[2010c]: received packet nr 5 type 51 len 32
D, [2022-08-18T08:41:57.819872 #278356] DEBUG -- net.ssh.authentication.session[20120]: allowed methods: publickey
E, [2022-08-18T08:41:57.819952 #278356] ERROR -- net.ssh.authentication.session[20120]: all authorization methods failed (tried none, publickey)

DEBUG ssh: == Net-SSH connection debug-level log END ==
 INFO ssh: SSH not ready: #<Vagrant::Errors::SSHAuthenticationFailed: 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.>
...

vagrant ssh 可以登录

1
2
3
4
$ journalctl -u sshd -f -n 1000
Dec 11 12:42:49 10.0.2.15 sshd[1466]: userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms [preauth]
Dec 11 12:42:49 10.0.2.15 sshd[1466]: Connection closed by authenticating user vagrant 10.0.2.2 port 58914 [preauth]
Dec 11 12:42:49 10.0.2.15 sshd[1458]: pam_unix(sshd:session): session opened for user vagrant(uid=1000) by (uid=0)

可以看到错误原因是 userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms.

处理方法

ubuntu 22.04

需要预先准备两个 terminal: term1 和 term2.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# term1:
vagrant up # 执行完后切换到 term2

# term2:
vagrant ssh
echo 'PubkeyAcceptedKeyTypes=+ssh-rsa' >> /etc/ssh/sshd_config
systemctl restart sshd

# term1
# 可以看到日志, 可以看到问题已经解决了

==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    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: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => /Volumes/code/

rocylinux 9

1
update-crypto-policies --set LEGACY

原因

TODO

https://github.com/hashicorp/vagrant/issues/12840 https://bugzilla.redhat.com/show_bug.cgi?id=2061607 https://bbs.archlinux.org/viewtopic.php?id=270005

总结

TODO

ref