How to modifycate ethe authorized_key


I am beginner in linux but i’d like to learn more about it
and all the time i have many problems trying to learn it.
for example, now I deleted the authorized_keys in my vagrant user fortunately I can log in because I had create a ssh keys and I can to log in with it, but I can’t log in with “vagrant ssh” and to learn I’d would like to fix it, I don’t want to destroy my VM, I know that I can log in with my key but i want to do it with vagrant ssh

best regard

Hi Irina,

Welcome to our forums.

From your description I gather you deleted the authorized_keys from within your virtual machine? In that case, the basic steps to repair would be:

  1. get the actual key that was deleted
  2. place it in the right place with the right filename and permissions

For 1.), there are some crossroads. Did you use your own public key as vagrant’s key, or it was the default, so-called “insecure vagrant key”? If so, the default key can be found in the installation bundle.

For 2.), you’ll need to put the key into a textfile called the same authorized_keys, which must be owned by the vagrant user within the VM, and file permission should be 600 (read/write only for owner). It also must be placed to the same directory, which is the hidden .ssh directory within the user’s home directory.

To set the file’s owner, you can use chown:

# chown vagrant: <filename-with-path>

To set the right file permissions, there is the chmod command:

# chmod 600 <filename-with-path>

Feel free to ask if some of the steps above should be further explained.