From 63e61bc3165d96127e29d59b66599b302390a165 Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Sun, 11 Feb 2018 18:17:24 -0500 Subject: [PATCH] ssh-config: handle cases where there is no IdentityFile In some cases there may be no IdentityFile you are using to ssh into the guest (one example is using AWS provider and the remote AMI already has the user's SSH key embedded in it by the cloud provider). Handle this case. Thanks to Michael P Reilly (https://github.com/arcege) for providing this patch in the issue (#78). Fixes #78. --- lib/vagrant-sshfs/cap/guest/linux/sshfs_forward_mount.rb | 9 +++++++-- lib/vagrant-sshfs/cap/host/darwin/sshfs_reverse_mount.rb | 7 +++++++ lib/vagrant-sshfs/cap/host/linux/sshfs_reverse_mount.rb | 9 +++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/vagrant-sshfs/cap/guest/linux/sshfs_forward_mount.rb b/lib/vagrant-sshfs/cap/guest/linux/sshfs_forward_mount.rb index 4dc4a16..6b072ba 100644 --- a/lib/vagrant-sshfs/cap/guest/linux/sshfs_forward_mount.rb +++ b/lib/vagrant-sshfs/cap/guest/linux/sshfs_forward_mount.rb @@ -206,13 +206,18 @@ def self.sshfs_slave_mount(machine, opts, hostpath, expanded_guest_path) sshfs_cmd+= sshfs_opts + ' ' + sshfs_opts_append + ' ' # The ssh command to connect to guest and then launch sshfs - # Note the backslash escapes for IdentityFile - handles spaces in key path ssh_opts = opts[:ssh_opts] ssh_opts+= ' -o User=' + machine.ssh_info[:username] ssh_opts+= ' -o Port=' + machine.ssh_info[:port].to_s - ssh_opts+= ' -o "IdentityFile=\"' + machine.ssh_info[:private_key_path][0] + '\""' ssh_opts+= ' -o UserKnownHostsFile=/dev/null ' ssh_opts+= ' -F /dev/null ' # Don't pick up options from user's config + if machine.ssh_info.key?(:private_key_path) and + machine.ssh_info[:private_key_path] and + machine.ssh_info[:private_key_path][0] + # Add IdentityFile since there is one + # Note the backslash escapes for IdentityFile - handles spaces in key path + ssh_opts+= ' -o "IdentityFile=\"' + machine.ssh_info[:private_key_path][0] + '\""' + end # Use an SSH ProxyCommand when corresponding Vagrant setting is defined if machine.ssh_info[:proxy_command] diff --git a/lib/vagrant-sshfs/cap/host/darwin/sshfs_reverse_mount.rb b/lib/vagrant-sshfs/cap/host/darwin/sshfs_reverse_mount.rb index 78ae760..afe1cb9 100644 --- a/lib/vagrant-sshfs/cap/host/darwin/sshfs_reverse_mount.rb +++ b/lib/vagrant-sshfs/cap/host/darwin/sshfs_reverse_mount.rb @@ -74,6 +74,13 @@ def self.sshfs_mount(machine, opts) ssh_opts+= ' -o "IdentityFile=\"' + machine.ssh_info[:private_key_path][0] + '\""' ssh_opts+= ' -o UserKnownHostsFile=/dev/null ' ssh_opts+= ' -F /dev/null ' # Don't pick up options from user's config + if machine.ssh_info.key?(:private_key_path) and + machine.ssh_info[:private_key_path] and + machine.ssh_info[:private_key_path][0] + # Add IdentityFile since there is one + # Note the backslash escapes for IdentityFile - handles spaces in key path + ssh_opts+= ' -o "IdentityFile=\"' + machine.ssh_info[:private_key_path][0] + '\""' + end ssh_opts_append = opts[:ssh_opts_append].to_s # provided by user diff --git a/lib/vagrant-sshfs/cap/host/linux/sshfs_reverse_mount.rb b/lib/vagrant-sshfs/cap/host/linux/sshfs_reverse_mount.rb index 8fdaefa..8d2cddf 100644 --- a/lib/vagrant-sshfs/cap/host/linux/sshfs_reverse_mount.rb +++ b/lib/vagrant-sshfs/cap/host/linux/sshfs_reverse_mount.rb @@ -67,12 +67,17 @@ def self.sshfs_mount(machine, opts) opts[:ssh_opts]+= ' -o ServerAliveInterval=30 ' # send keepalives # SSH connection options - # Note the backslash escapes for IdentityFile - handles spaces in key path ssh_opts = opts[:ssh_opts] ssh_opts+= ' -o Port=' + machine.ssh_info[:port].to_s - ssh_opts+= ' -o "IdentityFile=\"' + machine.ssh_info[:private_key_path][0] + '\""' ssh_opts+= ' -o UserKnownHostsFile=/dev/null ' ssh_opts+= ' -F /dev/null ' # Don't pick up options from user's config + if machine.ssh_info.key?(:private_key_path) and + machine.ssh_info[:private_key_path] and + machine.ssh_info[:private_key_path][0] + # Add IdentityFile since there is one + # Note the backslash escapes for IdentityFile - handles spaces in key path + ssh_opts+= ' -o "IdentityFile=\"' + machine.ssh_info[:private_key_path][0] + '\""' + end ssh_opts_append = opts[:ssh_opts_append].to_s # provided by user