From ea4dad14da8e7ad60c7b2e7eaaef9e138b7da563 Mon Sep 17 00:00:00 2001 From: Jan Schulz Date: Mon, 8 Aug 2016 12:36:43 +0200 Subject: [PATCH 1/2] Allow for additional files for ssh-add According to the docs, ssh-add only adds certain keyfiles. > ssh-add adds private key identities to the authentication agent, ssh-agent(1). > When run without arguments, it adds the files ~/.ssh/id_rsa, ~/.ssh/id_dsa, > ~/.ssh/id_ecdsa and ~/.ssh/identity. Sometimes there is the need to add more keyfiles. This is now possible by setting the SSH_ADD_ADDITIONAL_KEYFILES environment variable to the comma separated list of additional keyfiles in ~/.ssh/ ```bat set "SSH_ADD_ADDITIONAL_KEYFILES=keyfile1_rsa,keyfile2_rsa2" start-ssh-agent ``` Signed-off-by: Jan Schulz --- mingw-w64-git/start-ssh-agent.cmd | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/mingw-w64-git/start-ssh-agent.cmd b/mingw-w64-git/start-ssh-agent.cmd index 626dd1b3dc60c..aca0f525d8696 100644 --- a/mingw-w64-git/start-ssh-agent.cmd +++ b/mingw-w64-git/start-ssh-agent.cmd @@ -70,10 +70,31 @@ @ECHO. done ) @"!SSH_ADD!" + @IF [!SSH_ADD_ADDITIONAL_KEYFILES!] NEQ [] @( + @SET KEYS= + @FOR %%I IN (!SSH_ADD_ADDITIONAL_KEYFILES!) DO @CALL :CHECKKEY %%I + IF NOT [!KEYS!] == [] @"!SSH_ADD!" !KEYS! + ) @ECHO. ) ) +@GOTO :ssh-agent-done + + +@REM Functions +@REM Check if ssh key has to be added +:CHECKKEY +@ssh-add -l | @FINDSTR /c:"%1" > NUL +@IF ERRORLEVEL 1 @( + @IF EXIST "%HOME%\.ssh\%1" @( + @SET KEYS='%HOME%\.ssh\%1' %KEYS% + ) ELSE ( + @echo Key '%1' not found. + ) +) +@GOTO :EOF + :ssh-agent-done :failure From cf72f51dccff2e03e96190991e8c6854ecbba833 Mon Sep 17 00:00:00 2001 From: Jan Schulz Date: Mon, 8 Aug 2016 15:29:20 +0200 Subject: [PATCH 2/2] Allow full paths to keyfile in SSH_ADD_ADDITIONAL_KEYFILES you can now also pass in a full path: set "SSH_ADD_ADDITIONAL_KEYFILES=C:\Users\jschulz\.ssh\id_rsa2,id_rsa3" ssh-add does a check if the file exist, so our check for existence now only makes it easier for the user to specify a keyfile: * if %USERPROFILE%\.ssh\ exist, use that path * else assume that is a full path Signed-off-by: Jan Schulz --- mingw-w64-git/start-ssh-agent.cmd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mingw-w64-git/start-ssh-agent.cmd b/mingw-w64-git/start-ssh-agent.cmd index aca0f525d8696..b97494a3ba0c1 100644 --- a/mingw-w64-git/start-ssh-agent.cmd +++ b/mingw-w64-git/start-ssh-agent.cmd @@ -90,7 +90,8 @@ @IF EXIST "%HOME%\.ssh\%1" @( @SET KEYS='%HOME%\.ssh\%1' %KEYS% ) ELSE ( - @echo Key '%1' not found. + @REM Assume full path... + @SET KEYS='%1' %KEYS% ) ) @GOTO :EOF