Remember SSH Passphrase for Git on Ubuntu on Windows
October 09, 2016
Having to constantly retype your SSH private key passphrase to use Git is annoying, and there are a number of articles out there about how to get around the issue.
Problem is, most of the recommendations on the Windows side assume you’re using Git Bash, so you’re only using the shell emulator for Git. They haven’t been updated for Ubuntu on Windows* where you are probably using Bash for lots of things, not just Git, and it would be just as annoying to have to enter your SSH private key passphrase every time you open Bash as it would be to have to enter your passphrase every time you use a Git command.
Create a shell script in your home directory. I called mine sshagent.sh
(or nano sshagent.sh, etc.)
Paste in the code to spin up your SSH agent
Note that those are tic marks in the first line, not apostrophes.
eval `ssh-agent -s`
Make the script executable
chmod +x ~/sshagent.sh
Extra important – you have to run the script in your current shell
a. This tripped me up for a while. If you were to run this as a regular Bash script using ./sshagent.sh or ~/sshagent.sh, it’ll execute as its own program, and your current interactive terminal won’t know about it.
b. You can read more about this method here: http://unix.stackexchange.com/questions/43882/using-to-execute-files-in-bash
(That is dot space and then your file path and name. Dot space dot slash sshagent.sh would work as well if you’re currently in your home directory . ./sshagent.sh)
Now, you can start Bash normally, and it won’t bug you about your SSH passphrase at startup. If you do need to use Git, you can run your little script with . ~/sshagent.sh
It’ll ask for your passphrase, and then you won’t have to mess with it again.
And that is how you spend hours consolidating two commands into one. Happy coding!
* Ubuntu on Windows is probably the greatest decision Microsoft has made since Windows 7. If you aren’t using it, you should.
Jeff Robertson is a digital marketer and an online development expert with experience stretching back to dial-up. He is partner and Chief Technology Officer at 9thWonder, where he helps bridge the gap between the technical and marketing worlds, as well as oversees technical infrastructure.
American Heart Association Launches #ShowUsYourGood Campaign