Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to login to vagrant with vagrant up after setting up ssh keys

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 [email protected]

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' '[email protected]' 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

like image 518
Shash Avatar asked Jul 06 '15 04:07

Shash


2 Answers

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!

like image 118
goodroot Avatar answered Oct 01 '22 17:10

goodroot


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

like image 39
shilovk Avatar answered Oct 01 '22 19:10

shilovk