Permission denied with Vagrant
Asked Answered
D

13

15

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?

Derisible answered 20/7, 2018 at 7:52 Comment(0)
N
34

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

Namangan answered 20/9, 2018 at 18:34 Comment(3)
Can you explain what does the Upper part of code do?Talky
@SaadAhmed vagrantup.com/docs/other/…Namangan
Just an FYI to people - I’ve experienced odd issues with Ctrl+C behaviour with the Vagrant shipped SSH client (using this described method). Adjusting the file permissions on the private key fixes Win10/11 OpenSSH support.Possessive
N
7

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"
Nonplus answered 10/5, 2019 at 8:37 Comment(2)
This is because you replaced the ".ssh" folder with your own, now there are no authorized keys in the vm, making the vagrant private key in host machine useless.Nationality
Thanks. This solution worked with vagrant 2.2.19 and virtualbox 6.1.36 on Windows 10.Drumfire
B
4

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.

Brey answered 20/9, 2021 at 11:20 Comment(0)
C
2

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

Christi answered 4/11, 2022 at 4:7 Comment(0)
P
1

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*'
Perla answered 8/3, 2020 at 15:35 Comment(0)
A
1

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

Affinal answered 6/10, 2020 at 23:37 Comment(0)
D
1

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
Durarte answered 17/9, 2021 at 6:0 Comment(0)
M
1

[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

Merell answered 20/3, 2023 at 9:46 Comment(0)
F
0

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.

enter image description here

Flournoy answered 14/4, 2023 at 7:10 Comment(0)
P
0

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.

Possessive answered 21/8, 2023 at 11:17 Comment(0)
L
0

ssh -i ~/.vagrant.d\insecure_private_key -p 2222 vagrant@localhost

Lionize answered 23/12, 2023 at 20:2 Comment(0)
H
0
# 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
Herrod answered 25/12, 2023 at 19:22 Comment(1)
Thank you for your interest in contributing to the Stack Overflow community. This question already has quite a few answers—including one that has been extensively validated by the community. Are you certain your approach hasn’t been given previously? If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient. Can you kindly edit your answer to offer an explanation?Curriery
V
0

Just use Windows PowerShell it worked.

vagrant ssh node
Villainy answered 1/3 at 13:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.