0

I have a new user in my vagrant box(trusty64) and I am trying to ssh into it. Instead of logging into vagrant user after vagrant up, I want to login to my username.

What I have done so far

  1. Created a user in my guest machine.
  2. Created ssh key in my host using ssh-keygen
  3. Copied the ssh key to the guest using ssh-copy-id -p 2222 -i shash@127.0.0.1

and the part of the Vagrantfile looks like this

  config.vm.box = "ubuntu/trusty64"
  config.ssh.username = "shash"
  config.ssh.forward_agent = true
  config.ssh.private_key_path = "~/.ssh/authorized_keys"

I can use ssh -p '2222' 'shash@127.0.0.1' to login directly but when I give vagrant up I keep getting the following error

default: Warning: Connection timeout. Retrying...
default: Warning: Authentication failure. Retrying...
default: Warning: Authentication failure. Retrying...

Any help in sorting out this is really appreciated.Thanks!

2

config.ssh.private_key_path should point to your private key file (usually ~/.ssh/id_rsa — the name of the file is displayed when you run ssh-keygen), not ~/.ssh/authorized_keys.

  • May you complete your answer by adding the instruction about how to find and change it? – Mostafa Ahangarha Apr 2 '16 at 16:43
0

An alternative way to accomplish this is adding the following to the bottom of ~vagrant/.bashrc:

ssh chsc
exit

If you want avoid the trouble of creating and installing an SSH key, you can use su instead; however this does not allow ssh inside the Vagrant box to use your SSH forward agent if you need to connect to external servers from within the box:

sudo su chsc
exit

When making such changes to ~vagrant/.bashrc you risk locking yourself out of the shell if you make an error. I recommend keeping an open terminal logged in as vagrant, until you have ensured that everything works. If something goes wrong, just rename .bashrc (mv .bashrc .bashrc-bak).

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.