Using SSH in Git for Windows with PowerShell
This is a brain dump after having configured SSH in PowerShell with Git and GitHub.
Use the github rsa 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\github rsa
- Change the remote origin URL to the git protocol
- git remote set-url origin [email protected]:user/projectName.git
- 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 [email protected]
- -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
- Why can a Git Shell use SSH even with remote.origin.url= https://github.com/bigfont/WindowsPowerShell.git ,
- whereas a normal PowerShell window requires remote.origin.url= [email protected]:bigfont/WindowsPowerShell.git ?
- Note: use git config –l to inspect this.
-
The contents of my user’s .ssh folder is the following:
-
github
rsa
- github
rsa.pub -
id
rsa
- id
rsa.pub - known hosts
-
github
rsa
Copy Content in PowerShell
- Get-Content somefile.txt | clip.exe
- gc githubrsa.pub | clip.exe
- This will copy the piped content to the clipboard