7

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!

A complete set-up guide would be really helpful

Shash
  • 4,160
  • 8
  • 43
  • 67

2 Answers2

1

The vagrant file will access that users home directory when you specify '~'.

config.ssh.private_key_path = "/home/shash/.ssh/authorized_keys"

Give that a go!

goodroot
  • 71
  • 5
1

Add it to the Vagrantfile:

Vagrant.configure("2") do |config|
  config.ssh.private_key_path = "~/.ssh/id_rsa"
  config.ssh.forward_agent = true
end
  1. config.ssh.private_key_path is your local private key
  2. Your private key must be available to the local ssh-agent. You can check with ssh-add -L, if it's not listed add it with ssh-add ~/.ssh/id_rsa
  3. Don't forget to add you public key to ~/.ssh/authorized_keys on the Vagrant VM. You can do it copy-and-pasting or using a tool like ssh-copy-id

https://stackoverflow.com/a/23554973/3563993

Community
  • 1
  • 1
shilovk
  • 11,718
  • 17
  • 75
  • 74