passwordless ssh to another user instead of vagrant

496 views
Skip to first unread message

Shash

unread,
Jul 5, 2015, 3:36:57 PM7/5/15
to vagra...@googlegroups.com
Hi All,

I am new to this group and I have been trying out vagrant from past couple of months.

 I would like to have a passwordless ssh to another user in the vagrant guest. I tried a lot looking into various forums but in vain.

Can someone explain me here how to get this done.

Thanks!
Shash

Alvaro Miranda Aguilera

unread,
Jul 5, 2015, 5:08:09 PM7/5/15
to vagra...@googlegroups.com
Hello,

You require 2 options.

1. user + vagrant insecure key
2. user + known password

Documentation is here:
https://docs.vagrantup.com/v2/vagrantfile/ssh_settings.html

Option 1.

in the Vagrantfile you need to add:
config.ssh.username = user

in the base box under this user you need to add the vagrant insecure
key, which is what vagrant use to connect:

Assuming the box is linux, these are the commands I use to add vagrant
and to include the ssh key. Please modify to suit your box:

"useradd vagrant",
"cp /etc/sudoers /etc/sudoers.orig",
"sed -i -e '/# %wheel\tALL=(ALL)\tNOPASSWD: ALL/a
%vagrant\tALL=(ALL)\tNOPASSWD: ALL' /etc/sudoers",
"mkdir ~vagrant/.ssh",
"chmod 700 ~vagrant/.ssh",
"echo 'ssh-rsa
AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ==
vagrant insecure public key' > ~vagrant/.ssh/authorized_keys",
"chmod 600 ~vagrant/.ssh/authorized_keys",
"chown -R vagrant: ~vagrant/.ssh"


Option 2.

In the Vagrantfile add:
config.ssh.username = user
config.ssh.password = somepassword

Let me know if you run into any issues.

Alvaro
> --
> This mailing list is governed under the HashiCorp Community Guidelines -
> https://www.hashicorp.com/community-guidelines.html. Behavior in violation
> of those guidelines may result in your removal from this mailing list.
>
> GitHub Issues: https://github.com/mitchellh/vagrant/issues
> IRC: #vagrant on Freenode
> ---
> You received this message because you are subscribed to the Google Groups
> "Vagrant" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to vagrant-up+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/vagrant-up/5686270f-c2c1-4c2e-b46c-08638177655d%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Shash

unread,
Jul 6, 2015, 5:06:19 AM7/6/15
to vagra...@googlegroups.com
Hi,

I would like to use my own key.


What I have done so far

    Created a user in my guest machine.
    Created ssh key in my host using ssh-keygen
    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' 'sh...@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!

Alvaro Miranda Aguilera

unread,
Jul 6, 2015, 6:47:53 PM7/6/15
to vagra...@googlegroups.com
Hello,

Once you add the key to the box, and then update the vagrant, do a vagrant ssh

also add:
config.ssh.insert_key = false

it should work,

but it won't work on new boxes, since the user/key doesn't exist on the base box

what you need to do once you add the key to the box, is repackage and
create a new box

make sense?


On Mon, Jul 6, 2015 at 9:06 PM, Shash <skmur...@gmail.com> wrote:
> Hi,
>
> I would like to use my own key.
>
>
> What I have done so far
>
> Created a user in my guest machine.
> Created ssh key in my host using ssh-keygen
> Copied the ssh key to the guest using ssh-copy-id -p 2222 -i sh...@127.0.0.1
> https://groups.google.com/d/msgid/vagrant-up/9efc16d1-a1d2-4634-8371-8d403b0c39ef%40googlegroups.com.

Shash

unread,
Jul 7, 2015, 6:23:18 AM7/7/15
to vagra...@googlegroups.com
Hi Alvaro,

Its still not working.

In your expert opinion, can you please let me know where I am going wrong?

Thanks

Alvaro Miranda Aguilera

unread,
Jul 7, 2015, 5:43:48 PM7/7/15
to vagra...@googlegroups.com
I am not expert :)

I am not sure where the error can be, since if you can ssh directly to
the box, then after updating the Vagrantfile it should work

If you are open to a different approach, think you should build your
base box, and there you can use the user/pass/sshkey you want

if you are not going to use vagrant user, then later you need to
distribute or use your project file /Vagrantfile and that box

can you share what are the requirements for said box?

packer is a tool to build boxes, also made by hashicorp packer.io

there is an online tutorial that use the packer build in atlas that I
will suggest to run:
https://atlas.hashicorp.com/tutorial/packer-vagrant/0
> https://groups.google.com/d/msgid/vagrant-up/4ff938e7-21bc-4a55-9e5f-33cab61e5e1d%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages