Skip to content

Commit

Permalink
ssh-config: handle cases where there is no IdentityFile
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dustymabe committed Feb 12, 2018
1 parent bb57bbe commit 63e61bc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
9 changes: 7 additions & 2 deletions lib/vagrant-sshfs/cap/guest/linux/sshfs_forward_mount.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 7 additions & 0 deletions lib/vagrant-sshfs/cap/host/darwin/sshfs_reverse_mount.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 7 additions & 2 deletions lib/vagrant-sshfs/cap/host/linux/sshfs_reverse_mount.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 63e61bc

Please sign in to comment.