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.

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay