I have been trying to use add ssh key to vagrant VMs through this command.

ssh-copy-id -f -i .vagrant/machines/workers/virtualbox/private_key -o PasswordAuthentication=no vagrant@

The error is

/usr/bin/ssh-copy-id: ERROR: failed to open ID file .vagrant/machines/workers/virtualbox/private_key.pub'

The problem is I am assigning private_key but it is keep asking for .pub that doesn't exist. How can I force ssh to take private_key?

Also I tried to rename private_key to private_key.pub and it returns

vagrant@ Permission denied (publickey).

I just want to access to vagrant VM with command ssh vagrant@ password) instead of vagrant ssh workers

  • You should never ever under any circumstances copy your private key to any other server. This is not how key based authentication works. Renaming the privatekey to *.pub will not magically make it the publickey of the keypair. You may want to educate yourself and meet alice and bob before proceeding to setup technology that you do not understand yet. If you are missing the publickey, generate a new keypair with ssh-keygen. Nov 22, 2022 at 3:17

1 Answer 1


The answer is hidden from this post

The step I used is here

  1. If you are like me and tried a few commands, you might accidentally add the key to known host. Run vim /Users/[your user]/.ssh/known_hosts. Then delete all the known hosts with name command to delete a line is dd).
  2. vagrant ssh-config - I will get the info I need from this command. Choose which node you want to ssh to. Under the Host you want to, that's the information you need.
  3. Use the info in step 1 and compose the command like this [User]@[HostName] -p [Port] -i [IdentityFile]

Have fun!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.