user1670773
user1670773

Reputation:

Private key to connect to the machine via SSH must be owned by the user running 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.

Upvotes: 3

Views: 5224

Answers (3)

elig
elig

Reputation: 3078

If you put vagrant data on NTFS you can use this trick to bypass the keyfile ownership/permissions check.

Copy your key file to $HOME/.ssh/ or where-ever on a suitable filesystem where you can set it to the correct ownership and permissions. Then simply create a symlink (!) to it inside the NTFS directory (where you have set $VAGRANT_HOME, for example) like this:

ln -sr $HOME/.ssh/your_key_file your_key_file

Upvotes: 0

Chris McCowan
Chris McCowan

Reputation: 487

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

Upvotes: 1

Jakuje
Jakuje

Reputation: 25956

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.

Upvotes: 7

Related Questions