Re: Feature request for ssh-add

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

 



On Aug 10, 2016, at 17:24, Darren Tucker <dtucker@xxxxxxxxxx> wrote:
> 
> On Thu, Aug 11, 2016 at 1:29 AM, Loganaden Velvindron
> <loganaden@xxxxxxxxx> wrote:
> [...]
>> Instead of specifying each key file, a single file such as .config
>> would contain:
>> AgentDefaultKey ~/.ssh/client1_rsa.private ~/.ssh/client2_ed25519
>> ~/.ssh/client3_ed25519.
> 
> You can do that with a trivial shell wrapper:
> 
> function ssh-add() { if [ -z "$@" ];then /usr/bin/ssh-add `cat
> ~/.ssh/keylist`; else /usr/bin/ssh-add $@; fi ; }

This may not do exactly what you mean, depending on the user's shell; there are idiosyncrasies surrounding "$@", among other things. 

This would be more likely to work correctly:

ssh-add() {
  if [ $# -eq 0 ]; then
    /usr/bin/ssh-add `cat "$HOME/.ssh/keylist"`
  else
    /usr/bin/ssh-add "$@"
  fi
}

Basically, "$@" (with double quotes) expands to "$1" "$2" ... "$n". Some shells don't like more than one argument after a -z test.  Some shells also expand "$@" to "" (an empty string) if no arguments are provided, while others (e.g., bash) expand it to nothing (not even an empty string). Using the quoted form after the ssh-add command ensures that arguments containing whitespace are preserved.  Likewise, not all shells like a tilde ('~') for $HOME, and quoting it ensures that home directories containing whitespace work correctly. 

Handling whitespace in the names of key files in ~/.ssh/keyfiles is left as an exercise for the reader, as is handling alternate locations of ssh-add. :)

Otherwise, I concur as well; this should not be first-class functionality of ssh-add. 

-- 
jim knoble

_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@xxxxxxxxxxx
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev



[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux