hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.05k stars 4.42k forks source link

vagrant ssh require password in Powershell 7 #13217

Open thaygiaoth opened 1 year ago

thaygiaoth commented 1 year ago

Environment:

Windows 11 install Powershell 7

vagrant up is OK in Powershell 7

But it can not ssh access by key authen to VM

vagrant ssh vagrant@127.0.0.1's password:

Default Powershell in Windows 11 can: vagrant ssh by key authen

Tks

chrisroberts commented 1 year ago

Hi there,

Thank you for opening an issue, however, there is not enough information to reproduce or provide a recommendation. When you first open an issue, a template is pre-filled in the box. That template provides instructions to collect your host and guest information, Vagrantfile, the version of Vagrant, and the debug output. Without that information it is very challenging for us to assist you.

Please supply that information here or open a new issue. Thank you!

bradleysmith commented 4 months ago

Whilst I cannot post debug output due to the use of private repos and sensitive contents I can confirm that this minimal vagrantfile exhibits the issue when using Powershell 7.4.1 (NOTE it is fine under Windows Powershell) on Windows 11:

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

Vagrant.configure("2") do |config|
  config.vm.box = "bento/ubuntu-22.04"
  config.vm.provider "vmware_desktop" do |v|
    v.gui = true
    v.vmx["memsize"] = "8192"
    v.vmx["numcpus"] = "2"
  end
end

The vagrant up output under Windows Powershell contains this:

    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...

Whereas under Powershell 7.4.1 we get this:

    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: Machine booted and ready!

Note the two missing lines after Inserting generated public key...

Expected behavior

Vagrant generates new key pair, copies public key to vagrant box' authorized_keys and stores private key on host.

Actual behavior

Vagrant generates new key pair but does NOT copy public key to vagrant box' authorized_keys (the original vagrant insecure public key remains in there) but does change to using private generated key. As such a vagrant ssh command will ask for a password.