Welcome to Shaun Luttin's public notebook. It contains rough, practical notes. The guiding idea is that, despite what marketing tells us, there are no experts at anything. Sharing our half-baked ideas helps everyone. We're all just muddling thru. Find out more about our work at bigfont.ca.

Using SSH in Git for Windows with PowerShell

Tags: ssh, openssh, git, github, powershell, windows

This is a brain dump after having configured SSH in PowerShell with Git and GitHub.

Use the githubrsa SSH key outside of Git Shell

  • Install GitHub for Windows.
    • This will add two files to your ~.ssh directory.
    • Run dir ~.ssh to inspect.
  • Copy the public key to GitHub.
    • Run Get-Content ~.ssh\githubrsa.pub | clip.exe
    • Paste the public key into GitHub. Here’s how.
  • Add the key to the ssh-agent.
    • ssh-add ~.ssh\githubrsa
  • Change the remote origin URL to the git protocol
  • Hooray! Now you can push without hassle.

Navigation in Powershell

  • Windows tends to store SSH keys here C:\Users\%USER%.ssh
  • From PowerShell you can type cd ~\ to enter the current %USER% folder
  • So, typing ~\Documents takes you to C:\Users\%USER\Documents

Git for Windows and ssh-agent

  • msysgit is also known as Git for Windows
  • Its built in ssh-agent is OpenSSH (I think)

Some OpenSSH Commands

  • ssh-add
  • ssh-keygen
    • Generate a new key 
    • -t (specify the type of key to create)
    • -C (specifies a comment)
    • e.g. ssh-keygen -t rsa -C bigfont@outlook.com
    • -l (show the fingerprint of a specified public key file)
    • -f (specify a file name)
    • e.g. ssh-keygen -lf ~/.ssh/idrsa

Remaining Questions

  • Git Shell vs a Normal Windows PowerShell
  • githubrsa vs idrsa
    • The contents of my user’s .ssh folder is the following:
      • githubrsa
      • githubrsa.pub
      • idrsa
      • idrsa.pub
      • knownhosts
    • I think that GitHub for Windows added the first two. I know that I added the last three.
    • What is each for?

Copy Content in PowerShell

  • Get-Content somefile.txt | clip.exe
  • gc githubrsa.pub | clip.exe
  • This will copy the piped content to the clipboard

Useful Links