ccontavalli / ssh-ident

Different agents and different keys for different projects, with ssh.
Other
965 stars 71 forks source link

Confusion of filename with hostname #35

Open HaleTom opened 7 years ago

HaleTom commented 7 years ago

I'm using ssh-ident via a symlink. It confuses a filename with a hostname:

$ ls -l ~/bin/scp
lrwxrwxrwx 1 ravi ravi 18 Nov 24  2016 /home/ravi/bin/scp -> /usr/bin/ssh-ident
$ # Doesn't work:
$ ~/bin/scp stignoreandroid jnanidroid:ext
All keys already loaded
ssh: Could not resolve hostname stignoreandroid: Name or service not known
$ # But the unwrapped scp DOES work, with the same syntax
$ /usr/bin/scp stignoreandroid jnanidroid:ext
stignoreandroid                            100%  451     3.4KB/s   00:00    
$ 
HaleTom commented 6 years ago

I'm finding it hard to believe that a basic functionality of scp is broken - ie, copying a file to a remote server.

Surely there must be a work-around for this?

I updated the example in the top post to highlight that scp works but using ssh-ident doesn't.

HaleTom commented 6 years ago

Work around:

alias scp='BINARY_SSH=/usr/bin/scp scp'

Or to enable use from inside scripts, call the following script ~/bin/ssh-ident-wrapper, and symlink it as ~/bin/scp: and ~/bin/ssh:

#!/bin/bash
# Wrapper to make ssh-ident work properly.
# See https://github.com/ccontavalli/ssh-ident/issues/35
set -euo pipefail

name=$(basename "$0")

# Assume that this script is in the path before anything else.
# Take the 2nd command as the one to execute
binary=$(which -a "$name" | sed -n '2p')

BINARY_SSH="$binary" ssh-ident "$@"

Questions

  1. Why is this workaround required?
  2. Why doesn't setting $BINARY_DIR make any difference?
HaleTom commented 6 years ago

Would checking argv[0] == scp allow a work-around?