user1157885 user1157885 - 2 months ago 18
Linux Question

Accidentally deleted authorized_keys on vagrant box

I accidentally deleted my

authorized_keys
file on my vagrant box and I can't SSH into it anymore but I still have a console connected to it.

How do I go about re-making this folder so it allows me to connect again?

I have my
.d.vagrant/insecure_private_key
on my host machine, do I need to create a public key of that and move that over or do i need to move the private key over too?

Answer

run vagrant sshh-config to review which private key the VM is using

If you're using the vagrant insecure key, you can

  1. create the ~/.ssh/authorized_keys with 600 mode
  2. download the vagrant public key into this file

If you have used your own private key, repeat the steps but create the public key from your key.

You dont need to move the private key, it must stay local and is only needed for you to login into the VM (unless you ssh from the VM into other servers like github or other ssh which will need the key, but thats another thing)

Comments