Reputation: 6622
When I do a vagrant ssh
in my project on a windows 10 laptop I get this error:
[email protected]: Permission denied (publickey)
.
When I then delete .vagrant/machines/default/virtualbox/private_key
and do vagrant ssh
again, I get access to the VM.
But when I then exit the VM and do `vagrant halt', I get this error:
==> default: Attempting graceful shutdown of VM...
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...
translation missing: en.vagrant_ps.errors.powershell_error.powershell_error
It seems to me that it tries to add my SSH key, but something goed wrong. Any idea how I can solve this?
Upvotes: 15
Views: 36067
Reputation: 1
# i have resolved this error while adding the below lines in my vagrant file for ubuntu/jammy64 Vagrant box
config.ssh.private_key_path = "~/.vagrant.d/insecure_private_key"
config.ssh.insert_key = false
config.ssh.forward_agent = false
Upvotes: 0
Reputation: 519
ssh -i ~/.vagrant.d\insecure_private_key -p 2222 vagrant@localhost
Upvotes: 0
Reputation: 3592
There is a known problem which I’ve previously blogged about regarding the interaction of Vagrant and recent versions of Windows where the system (Windows) OpenSSH client is installed.
As others have suggested, you can ask Vagrant to use its own internally shipped SSH client - but I’ve found that to be buggy (particularly its handling of Ctrl+C
). Windows’ own SSH client only complains because of the open ownership of the SSH private key generated by Vagrant.
The following PowerShell (which I keep as fix_ssh.ps1
in the root of my Vagrant-powered codebase) resolves the problem. Credit to https://superuser.com/a/1329702 for the PS method of fixing the permissions.
Write-Host "Trying to retrieve Vagrant SSH details ... (this may take a moment)"
$VagrantSshKey = "$(vagrant ssh-config | Select-String -Pattern "^ IdentityFile ")".Split(" ")[3]
If (!$VagrantSshKey.EndsWith("private_key")) {
Write-Host "Could not determine Vagrant private SSH Key location. Unable to proceed."
Exit 1
}
Write-Host "Key location is: $VagrantSshKey"
Write-Host "Fixing key permissions..."
# Remove Inheritance:
icacls $VagrantSshKey /c /t /Inheritance:d
# Set Ownership to Owner:
icacls $VagrantSshKey /c /t /Grant:r ${env:UserName}:F
# Remove All Users, except for Owner:
icacls $VagrantSshKey /c /t /Remove:g Administrator "Authenticated Users" BUILTIN\Administrators BUILTIN Everyone System Users
# Verify:
icacls $VagrantSshKey
Write-Host "Fixed SSH private key permissions."
This is (more or less) equivalent to chmod 600
under Unix.
Upvotes: 0
Reputation: 1289
I faced this error on Windows 10.
I was able to resolve it by removing the Windows 10 built-in SSH client:
Go to
"Settings => Apps => Apps and Features => Optional Features".
and search for OpenSSH Client and then uninstall it.
Upvotes: 0
Reputation: 11
[email protected]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
I had the same issue with windows 10 OS,
I also had gitbash installed, so instead of using windows terminal, i used git bash and had access
Upvotes: 1
Reputation: 811
On Windows 10, when we try to login to the Virtual machine node (eg. node01) using
vagrant ssh node01
If you get the error
[email protected]: Permission denied (publickey)
Try to follow the steps below:
In the Power Shell, set the environmental variable VAGRANT_PREFER_SYSTEM_BIN to prefer using the local ssh instead of the packaged ssh (Read more about the variable here)
$Env:VAGRANT_PREFER_SYSTEM_BIN += 0
As per issue listed in Vagrant Github: [email protected]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
Once done, do the vagrant ssh to the vm which was not accessible earlier
Upvotes: 3
Reputation: 41
The solution provided by @rekinz works, but I want to add some further explanation.
set VAGRANT_PREFER_SYSTEM_BIN=0
Vagrant will default to using a system provided SSH on Windows. This environment variable can also be used to disable that behavior to force Vagrant to use the embedded SSH executable by setting it to 0.
I also used Vagrant halt to clean up a previous installation. And then, when I provisioned it again, I had got the same error as the OP.
I think the SSH provided by Windows is not working and using this VAGRANT_PREFER_SYSTEM_BIN
has reset the same.
Upvotes: 4
Reputation: 11
It works for me when I point to the private_key (check permission of it first )
ssh -i ${vagrant_home}/.vagrant/machines/default/virtualbox/private_key [email protected] -p 2222
Upvotes: 1
Reputation: 17749
You can also check the permission of the file
.vagrant/machines/default/virtualbox/private_key
In my case the permissions for this file were for an Unknown user (likely from a previous OS installation) - setting the permissions for this file to myself fixed the issue
Upvotes: 1
Reputation: 117
The problem can be that the sshClient windows feature intercepting the operation, try opening powershell as admin and run the following:
Remove-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
if that doesn't solve then install sshclient again
Get-WindowsCapability -Online | ? Name -like 'OpenSSH*'
Upvotes: 1
Reputation: 6622
you can simply run following command in your cmd:
set VAGRANT_PREFER_SYSTEM_BIN=0
vagrant ssh
successfully tested under the windows 10 with vagrant 2.1.5
you can also see: https://www.vagrantup.com/docs/other/environmental-variables.html#vagrant_prefer_system_bin
Upvotes: 35
Reputation: 89
I solved error:
[email protected]: Permission denied (publickey)
editing my Vagrantfile.
It seems Vagrant didn't like this configuration:
config.vm.synced_folder "app", "/home/vagrant"
Edited it to:
config.vm.synced_folder "app", "/vagrant"
Upvotes: 7