#4803 "vagrant up" uses personal SSH keys to access vm, and fails to mount via sshfs
Closed: Fixed a year ago by wombelix. Opened 4 years ago by sudoman.

I'm experimenting with using Vagrant to create a development environment. I ran into an issue with booting up the vm when I have my SSH key set in Pagure's Web interface.

In /home/vagrant/.ssh/authorized_keys:

ssh-rsa ... vagrant (the key intended for use for part of the 'vagrant up` process)
# gitolite start
command="/usr/share/gitolite3/gitolite-shell gitolite_rsa",... (used internally by Pagure)
command="/usr/share/gitolite3/gitolite-shell sudoman",....(my SSH key)
# gitolite end

My personal key was added to the authorized_keys file when I added it to my Pagure user keys via the Web interface. Now when I try to run vagrant up, Vagrant logs into the Vagrant user with my main SSH identity, and the command doesn't pass checks by gitolite-shell.

FATAL: unknown git/gitolite command: 'sudo -E sshfs :/home/andrew/.../pagure /home/vagrant/devel -o allow_other  -o noauto_cache  -o slave   '

I also get an error when I try to manually test logging in and running a command like so:

ssh -v -i ~/.vagrant.d/insecure_private_key vagrant@pagure-dev.example.com sshfs

debug1: Will attempt key: /home/andrew/.ssh/id_rsa RSA SHA256:.... agent
debug1: Will attempt key: /home/andrew/.vagrant.d/insecure_private_key  explicit

FATAL: unknown git/gitolite command: 'sshfs'

It looks like my personal key is used by default, even if I specify that a specific key should be used by SSH.

The way I'm working around this is to comment out my SSH key in the authorized_users file before shutting down, and uncommenting it after booting up.


I found a solution! I added the following ssh_opts_append statement to my Vagrantfile:

 config.vm.synced_folder ".", "/home/vagrant/devel",
+    ssh_opts_append: "-o IdentitiesOnly=yes -i ~/.vagrant.d/insecure_private_key",
     type: "sshfs"

Note that the key private I listed above does not match the public key in ~vagrant/.ssh/authorized_keys on the guest, so I copied over the public key from the root user to the vagrant user. It could be that I borked my installation, or that a different key is normally used. I'll try building the image again to see which key is normally used here.

It looks like this is the proper key: ./.vagrant/machines/pagure/libvirt/private_key, however it seems like it's unnecessary to specify it:

 config.vm.synced_folder ".", "/home/vagrant/devel",
+    ssh_opts_append: "-o IdentitiesOnly=yes",
     type: "sshfs"

I tested this on Debian 10. : ) I'm not sure how well that would work on Windows or macOS, if people are developing using those systems. :'(

If you've got a fix for this, feel free to send a PR. :smile:

Here's the pull request: #4804

Metadata Update from @wombelix:
- Issue close_status updated to: Fixed
- Issue status updated to: Closed (was: Open)

a year ago

Login to comment on this ticket.

Metadata