-
-
Save Shoozza/8fe8b0c85fa89cd3b1c4 to your computer and use it in GitHub Desktop.
@ECHO OFF | |
REM Set default sock file | |
SET SSH_AUTH_SOCK=/tmp/ssh-agent.sock | |
REM Check socket is available | |
IF NOT EXIST "%TMP%\ssh-agent.sock" GOTO:RUNAGENT | |
REM Check if an ssh-agent is running | |
FOR /f "tokens=*" %%I IN ('ps ^| grep ssh-agent ^| sed "s/^ *\([0-9]\+\) .*/\1/"') DO SET VAR=%%I | |
IF "%VAR%" == "" GOTO:RUNAGENT | |
REM Check if socket file is valid | |
ssh-add -l 1> NUL 2>&1 | |
IF ERRORLEVEL 1 GOTO:RUNAGENT | |
GOTO:ADDKEYS | |
:RUNAGENT | |
REM Remove old socket file | |
rm -f /tmp/ssh-agent.sock | |
REM Run ssh-agent and save (last) PID in VAR | |
SET VAR= | |
FOR /f "tokens=*" %%J IN ('ssh-agent -a /tmp/ssh-agent.sock') DO FOR /f "tokens=*" %%K IN ('echo %%J ^| grep "SSH_AGENT_PID" ^| sed "s/^SSH_AGENT_PID=\([0-9]\+\); .*/\1/"') DO SET VAR=%%K | |
:ADDKEYS | |
SET SSH_AUTH_PID=%VAR% | |
REM Check if ssh keys are known | |
SET KEYS= | |
FOR /f "tokens=*" %%I IN ('DIR /B "%HOME%\.ssh\*_rsa"') DO CALL:CHECKKEY %%I | |
REM Add missing ssh keys at once | |
IF NOT "%KEYS%" == "" ssh-add %KEYS% | |
GOTO:END | |
REM Functions | |
REM Check if ssh key has to be added | |
:CHECKKEY | |
SET VAR= | |
FOR /f "tokens=*" %%J IN ('ssh-add -l ^| grep soldat_rsa') DO SET VAR=%%J | |
IF "%VAR%" == "" SET KEYS=%KEYS% "%HOME%\.ssh\%1" | |
GOTO:EOF | |
:END | |
@ECHO ON |
Thanks :)
How do I make this work?
@Shoozza You sir sure deserve an award.
First time worked. After I restart cmder, got
bind: Address already in use
unix_listener: cannot bind to path: /tmp/ssh-agent.sock
Error connecting to agent: Connection refused
Error connecting to agent: Connection refused
exit /b
PS: I amd using {cmd} and {minnty}/git-bash at same time, git-bash also start ssh-agent.
Hi, Please bear with me, I am a beginner, I have Cmder in my wincdows 7, I use ssh IPaddress to connect to our servers, I have always to enter the password,
please is the above script for the same reason to do ssh IP and you don't need to enter the password ?
If so can you please show me the steps ?
Thanks, your help is appreciated.
@Shoozza can you please shed some light on what we are supposed to put that script? I have the latest stable version of Cmder installed, but each time I do a git push
or git pull
I'm asked for my SSH key. I believe your script fixes that, but I'm not sure what to do with your script. Any n00b friendly instructions would be greatly appreciated.
@Ciwan1859 with the newest version of Cmder, in:
[your cmder folder]\config\user-profile.cmd
you can just uncomment the line:
call "%GIT_INSTALL_ROOT%/cmd/start-ssh-agent.cmd"
by removing the :: in front of it and it should start working when you restart cmder.
@Tsarpf thank you, I uncommented that, and now when I open Cmder, it says ssh is open.
Where do I need to upload my .ppk
keys for the SSH to look them up?
@Ciwan1859 with the newest version of Cmder, in:
[your cmder folder]\config\user-profile.cmd
you can just uncomment the line:
call "%GIT_INSTALL_ROOT%/cmd/start-ssh-agent.cmd"
by removing the :: in front of it and it should start working when you restart cmder.
it work
thanks :)
Hey everyone since this script is not really necessary for cmder,
I decided to fix and update this script to work with MSYS2 (and possibly cygwin).
Cmder provides a start-ssh-agent script from git-for-windows by default.
Updated and extended the script:
Add license
Add kill command
Add verbose output
Add help/usage info
Add version/license info
Add dependency check support
Add support for adding all kinds of ssh keys
Add comments
Add support for checking already set SSH_AUTH_SOCK before using DEFAULT_AUTH_SOCK
Modify use ECHO, for faster output
Fix don't leak/overwrite environment variables except SSH_AUTH_SOCK and SSH_AGENT_PID if successfull
Fix check for the sock file in the correct folder (/tmp != %TEMP%)
Fix valid sock file check needs to check with fingerprint instead of non working path
Have fun ;)
Thanks for doing all the %%work%% 😄