Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vagrant : Permission denied (publickey)

I am getting Permission denied (publickey) error when doing ssh by ssh username@ip while ssh working when we are doing vagrant ssh

VagrantFile :

Vagrant.configure("2") do |config|
 config.vm.box = "ubuntu/xenial64"
 config.vm.network "forwarded_port", guest: 80, host: 8071
 config.vm.network "private_network", ip: "192.168.33.71"
end

I am trying ssh [email protected] on terminal

Getting Error : Permission denied (publickey)

like image 333
itsvks Avatar asked May 10 '18 10:05

itsvks


2 Answers

config.vm.synced_folder '.' and '/home/vagrant/' caused this problem.
Because the configure makes home directory on the host overwritten and destroy .ssh settings on the host.
I got the same problem a few seconds ago. I checked the .ssh was overwritten by Vagrant GUI.

In the summary, your synced folder overrides the .ssh folder in the virtual machine, so you cannot login with ssh.

The answer is from this issue.

like image 50
周左左 Avatar answered Sep 18 '22 10:09

周左左


Use the private key in your connection with the vagrant box

ssh -i .vagrant/machines/default/virtualbox/private_key [email protected]

like image 22
Moamen Abdelwahed Avatar answered Sep 18 '22 10:09

Moamen Abdelwahed