Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Private key to connect to the machine via SSH must be owned by the user running Vagrant

Tags:

ssh

vagrant

I am trying to follow this vagrant tutorial. I get error after my first two command. I wrote these two command from command line

$ vagrant init hashicorp/precise64
$ vagrant up

After I ran vagrant up command I get this message.

The private key to connect to the machine via SSH must be owned
by the user running Vagrant. This is a strict requirement from
SSH itself. Please fix the following key to be owned by the user
running Vagrant:

/media/bcc/Other/Linux/vagrant3/.vagrant/machines/default/virtualbox/private_key

And then if I run any command I get the same error. Even if I run vagrant ssh I get the same error message. Please help me to fix the problem.

I am on linux mint and using virutal box as well.


2 Answers

Exactly as the error message tells you:

The private key to connect to the machine via SSH must be owned by the user running Vagrant.

Therefore check permissions of file using

stat /media/bcc/Other/Linux/vagrant3/.vagrant/machines/default/virtualbox/private_key

check what user you are running using

id

or

whoami

and then modify owner of the file:

chown `whoami` /media/bcc/Other/Linux/vagrant3/.vagrant/machines/default/virtualbox/private_key

Note that this might not be possible if your /media/bbc/ is some non-linux filesystem that does not support linux permissions. In that case you should choose more suitable location for you private key.

like image 200
Jakuje Avatar answered Dec 06 '25 07:12

Jakuje


Jakuje has the correct answer - if the file system you are working on supports changing the owner.

If you are trying to mount the vagrant box off of NTFS, it is not possible to change the owner of the key file.

If you want to mount the file on NTFS and you are running a local instance you can try the following which worked for me:

Vagrant Halt

[remove the vagrant box]

[Add the following line to Vagrantfile]

config.ssh.insert_key=false

[** you may need to remove and clone your project again]

Vagrant Provision

This solution may not be suitable for a live instance - it uses the default insecure ssh key. If you require more security you might be able to find a more palatable soultion here https://www.vagrantup.com/docs/vagrantfile/ssh_settings.html

like image 24
Chris McCowan Avatar answered Dec 06 '25 07:12

Chris McCowan