-
-
Save Shoozza/8fe8b0c85fa89cd3b1c4 to your computer and use it in GitHub Desktop.
@ECHO OFF | |
REM ssh-agent already running? | |
SET VAR= | |
for /f "tokens=*" %%i in ('ps x ^| grep ssh-agent') do set VAR=%%i | |
IF NOT "%VAR%" == "" GOTO:GETPID | |
REM start ssh-agent | |
ssh-agent -a /tmp/ssh-agent.sock | grep -v echo | sed -e "s/^/@set /" | sed -e "s/;.*$//" - > call.cmd | |
CALL call.cmd | |
DEL call.cmd | |
GOTO:CHECKS | |
:GETPID | |
REM Get SSH_AUTH_SOCK and SSH_AGENT_PID from running ssh-agent | |
SET VAR= | |
for /f "tokens=*" %%i in ('ps x ^| grep ssh-agent ^| sed "s/^ *\([0-9]\+\) .*/\1/"') do set VAR=%%i | |
SET SSH_AUTH_SOCK=/tmp/ssh-agent.sock | |
SET SSH_AGENT_PID=%VAR% | |
:CHECKS | |
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%% 😄