├── README.md ├── autorun.reg └── sshagent.cmd /README.md: -------------------------------------------------------------------------------- 1 | ssh-agent script for Windows CMD.exe 2 | 3 | You hate entering your password over and over and over when you're using git in the Windows cmd.exe 4 | Command Processor, right? 5 | 6 | Me too. So, here's a script that will launch ssh-agent, or connect to an existing one. 7 | There's also a registry entry key that you can import, that will cause it to run the script automatically 8 | in every command processor you open. 9 | 10 | You probably DO NOT need to use the auto-start registry hack. If you place 11 | this script in your startup folder, it should successfully write the variables 12 | to your global registry, therefore allowing any further command shells 13 | that are spawned to know how to use the ssh-agent. 14 | 15 | **** WARNINGS **** 16 | 17 | IF YOU USE THE REGISTRY HACK TO AUTO-START THIS SCRIPT, YOU MUST EDIT THESE FILES AND PLACE THE CORRECT LOCATIONS TO YOUR FILES, OTHERWISE BAD THINGS MAY HAPPEN. 18 | 19 | **** Installation **** 20 | 21 | Place sshagent.cmd somewhere within your system. Edit it to change the SSH_BIN_PATH variable. 22 | 23 | If you want to use the registry entry, edit the autorun.reg file, and change the path listed in 24 | "AutoRun"="d:\\\\sshagent.cmd" to point to the location where your sshagent.cmd you will be using is. 25 | Then double-click the autorun.reg file. (Make sure you use double slashes in this file! 26 | If you screw up this file, I don't know what will happen. Maybe nothing, maybe you won't be able to 27 | start a command window again without undoing it) 28 | 29 | If you have git 1.7.0 for windows or better, and you are constantly nagged by github to enter 30 | credentials for https accesses, you might try: 31 | 32 | git config --global credential.helper wincred 33 | 34 | **** Caveats **** 35 | 36 | Nothing that I know of! 37 | 38 | **** License **** 39 | 40 | This is free. Plain-old free, public domain. As open as it gets. Do whatever you want with it. 41 | It'd be super nice, though, if you were to make any changes that someone else would find useful, if you 42 | contributed those as a pull request. Open source works best when everyone helps! 43 | 44 | And don't forget: Today, you should BE AWESOME. 45 | -------------------------------------------------------------------------------- /autorun.reg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericblade/ssh-agent-cmd/f374854d593aebaca59a60ebf5d9493bc5f9c3e9/autorun.reg -------------------------------------------------------------------------------- /sshagent.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem -- *** from http://github.com/ericblade/ssh-agent-cmd - free for all use. 3 | 4 | rem -- This prevents us from infinite looping at startup. 5 | rem -- Surprise! "FOR" runs a new command processor for every loop! Wow! 6 | rem -- So, this is put at the top to short circuit any additional executions that might happen 7 | rem -- as a side effect of other commands inside. 8 | IF DEFINED SSH_AGENT_SEARCHING GOTO :end 9 | set SSH_AGENT_SEARCHING=1 10 | 11 | rem -- *** SET SSH_BIN_PATH TO THE LOCATION WHERE YOUR SSH BINARIES ARE IF NOT INSTALLED WITH GIT IN 12 | rem -- *** THE NORMAL PLACE (\program files\ or \program files (x86)\) 13 | if not defined SSH_BIN_PATH ( 14 | echo Searching for SSH bin path... Define SSH_BIN_PATH to override. 15 | 16 | if exist "%ProgramFiles%\git\usr\bin\ssh-agent.exe" ( 17 | set SSH_BIN_PATH="%ProgramFiles%\git\usr\bin\" 18 | ) else if exist "%ProgramFiles(x86)%\git\usr\bin\ssh-agent.exe" ( 19 | set SSH_BIN_PATH="%ProgramFiles(x86)%\git\usr\bin\" 20 | ) 21 | 22 | if defined SSH_BIN_PATH ( 23 | setlocal enabledelayedexpansion 24 | echo Found !SSH_BIN_PATH!... 25 | endlocal 26 | ) 27 | ) 28 | 29 | IF NOT EXIST %SSH_BIN_PATH%\ssh-agent.exe ( 30 | echo "*** Unable to find ssh-agent.exe in %ProgramFiles%\git\usr\bin or %ProgramFiles(x86)%\git\usr\bin or %SSH_BIN_PATH%\. Check SSH_BIN_PATH." 31 | GOTO :exit 32 | ) 33 | 34 | rem -- NOTE: If you kill an agent, the socket file remains locked by Windows! Bad! 35 | rem -- This means you'll need to change the below filename if you want to run the 36 | rem -- script again without rebooting. 37 | rem -- ** NEW NOTE: This no longer seems to be the case in Windows 10 AU. Not sure when 38 | rem -- exactly that changed between 8.0 and 10AU, but it's a welcome fix! 39 | 40 | set SSH_AUTH_SOCK=%TEMP%\ssh-agent-socket.tmp 41 | 42 | :checkAgent 43 | SET "SSH_AGENT_PID=" 44 | rem -- Get a list of all running tasks, and search it for ssh-agent.exe, record that process id in 45 | rem -- SSH_AGENT_PID. 46 | rem -- Call cmd /c to get a known working tasklist command, because Take Command's "tasklist" is NOT format compatible with CMD.exe!! 47 | FOR /F "tokens=1-2" %%A IN ('cmd /c tasklist^|find /i "ssh-agent.exe"') DO @(IF %%A==ssh-agent.exe (call :agentexists %%B)) 48 | rem -- If no SSH_AGENT_PID found, then start a new instance of ssh-agent.exe 49 | IF NOT DEFINED SSH_AGENT_PID (GOTO :startagent) 50 | CALL :setregistry 51 | GOTO :end 52 | 53 | :doAdds 54 | rem -- Grab all the *_rsa.* files in %USERPROFILE% and add them to the agent, this will probably 55 | rem -- prompt you for passwords to those keys. 56 | FOR /R %USERPROFILE%\.ssh\ %%A in (*_rsa.) DO %SSH_BIN_PATH%\ssh-add %%A >nul 2>&1 57 | EXIT /b 58 | 59 | :agentexists 60 | SET SSH_AGENT_PID=%1 61 | GOTO :setregistry 62 | 63 | :startagent 64 | rem -- win 8.1 at least has these set as system, so you can't delete them 65 | attrib -s %SSH_AUTH_SOCK% >nul 2>&1 66 | del /f /q %SSH_AUTH_SOCK% >nul 2>&1 67 | %SSH_BIN_PATH%\ssh-agent -a %SSH_AUTH_SOCK% >nul 2>&1 68 | CALL :doAdds 69 | rem -- recheck the agent to make sure that it launched properly. 70 | rem -- Yes, I know this could cause an infinite loop if it can't find one and can't start one. 71 | rem -- If you find a common cause for this to be a problem, file a bug, or submit a pull 72 | rem -- request to fix it :-) 73 | GOTO :checkAgent 74 | 75 | :setregistry 76 | rem -- store these variables to the global environment -- note that this can and will NOT affect 77 | rem -- any open shells or other running programs. This also includes affecting new shells opened 78 | rem -- by already running programs, such as using the "New Tab" button in ConsoleZ. This will 79 | rem -- only take affect automatically in completely new processes. 80 | SetX SSH_AUTH_SOCK %SSH_AUTH_SOCK% >nul 2>&1 81 | SetX SSH_AGENT_PID %SSH_AGENT_PID% >nul 2>&1 82 | set SSH_AGENT_SEARCHING= 83 | GOTO :end 84 | 85 | :end 86 | IF /I "%1"=="-x" (EXIT) 87 | --------------------------------------------------------------------------------