10.10.16

Remember SSH Passphrase for Git on Ubuntu on Windows

BY JEFF ROBERTSON

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.

 

technology-785742_640.jpg

 

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.

The solution:

  1. Create a shell script in your home directory. I called mine sshagent.sh
    vi sshagent.sh
    (or nano sshagent.sh, etc.)
  2. 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`
    ssh-add
  3. Make the script executable
    chmod +x ~/sshagent.sh
  4. 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: ,br /> http://unix.stackexchange.com/questions/43882/using-to-execute-files-in-bash.
    ~/sshagent.sh

(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)

 

graphic-in-article.png

 

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
written by JEFF ROBERTSON

Jeff Robertson is an entrepreneur and an online development expert with experience stretching back to dial-up. He is a partner and VP of Technology & Operations at Carbon8. On the development side, he helps bridge the gap between the technical and marketing worlds, and oversees technical infrastructure. On the operations side, he helps optimize team processes, manages finances and buys emergency coffee if the supply runs low.

share this
iamges