DEV Community

Cover image for Solve "vagrant@127.0.0.1: Permission denied (publickey)" error
Sergio Peris
Sergio Peris

Posted on • Edited on • Originally published at sertxu.dev

Solve "vagrant@127.0.0.1: Permission denied (publickey)" error

When we move a Vagrant VM from one computer to another, we encounter the "Permission denied (publickey)" error.

This error occurs when Vagrant cannot access the guest machine using its SSH private key.

To solve this we should go to the folder where the Vagrantfile is located, next we should access the following folders.

Note: The path might be slightly different if you're not using VirtualBox as your provider.

.vagrant\machines\default\virtualbox
Enter fullscreen mode Exit fullscreen mode

In this folder you will find a file named "private_key", you should delete it.

Next, open your provider software, Virtualbox, and boot your VM.

Once it's booted, access the terminal and execute the following commands:

cd ~/.ssh
curl https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub > authorized_keys
Enter fullscreen mode Exit fullscreen mode

This will allow using the Vagrant's default public key when accessing the guest.

Let's try it, we execute the following Vagrant command:

vagrant reload
Enter fullscreen mode Exit fullscreen mode

Once Vagrant tries to boot the guest, a new SSH key will be generated in order to replace the default one.

With these few steps, we will be able to use as usual our guest machine.

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs