How to SSH into GitHub on Windows example
OpenSSH, the open source version of the Secure Socket Shell (SSH) tools, is a standard part of the Windows 10 and Windows Server 2019 operating systems. This greatly simplifies how to connect to GitHub with SSH on Windows.
Step-by-step Windows GitHub SSH example
To connect to GitHub with SSH from Windows, follow these steps:
- Open PowerShell
- Run the ssh-keygen command to create SSH keys
- Copy the value of the SSH public key
- Save the public key in your GitHub account settings
- Perform a Git clone operation using your repo’s SSH URL
Create SSH Keys for GitHub
To start, store a public SSH key on GitHub. This is validated against a locally stored private key that Git uses to validate and establish a connection. GitHub SSH keys are created with the ssh-keygen tool that comes prepackaged with updated versions of Windows.
In Windows PowerShell, issue the following ssh-keygen command to create GitHub SSH keys:
PS C:\github\ssh\example> ssh-keygen -o -t rsa -C "[email protected]"
You will be asked for an optional passphrase. It’s permissible to click enter and leave this blank.
ssh-keygen flags | Purpose | Suggested |
---|---|---|
-C | Comments or metadata to add to the public key | Email address |
-t | The type of GitHub SSH key to create | RSA |
-o | Use the newest OpenSSH format | Leave blank |
You will also be asked for a location to save the GitHub SSH keys on Windows. Again, just click enter to accept the default location, which is the .ssh folder under the user’s home directory.
Git and SSH tutorials |
---|
Need to setup SSH for GitHub, GitLab, or CodeDeploy? These SSH Key tutorials will help:
These quick tutorials will get you working with Git and the secure shell in no time. |
The Windows GitHub SSH keys live in the .ssh folder under the current user’s home directory. The following directory listing under the .ssh folder of a user named Cameron shows the two files created by the ssh-keygen tool:
PS C:\Users\Cameron\.ssh> dir LastWriteTime Name ------------- ---- 1/1/2022 id_rsa 1/1/2022 id_rsa.pub
GitHub SSH config
Open the SSH public key in a text editor such as Notepad++, perform a Select All, and copy the key.
With the SSH key copied, log into GitHub, navigate to your account settings, and paste the public key as a new SSH key.
SSH to GitHub on Windows
With the SSH keys generated, and the public key registered in your GitHub account, you can now use Git to connect to GitHub over SSH on Windows.
Simply copy the SSH URL from the GitHub page of the repository you wish to clone, and then provide that SSH link to the Git clone command:
PS C:\github\ssh\example> git clone [email protected]:cameronmcnz/java-jakarta-ee.git Cloning GitHub SSH Windows into ‘java-jakarta-ee’… Host authenticity cannot be established. Do you still want to connect(yes or no)? yes Receiving objects: 100% (55/55),5.78 MiB | 1.32 MiB/s, Windows GitHub SSH done. Resolving deltas: 100% (66/66), Windows GitHub SSH done.
Notice the initial git clone with GitHub SSH on Windows complains about being unable to establish the host authenticity. That warning message is expected. Just type yes and allow the GitHub SSH clone operation to continue.
Once the remote repository is cloned, you can continue to use Git as you normally would, issue commits, add submodules, rebase branches and push back and forth with GitHub. All operations that use the network will automatically use an SSH connection.
And that’s how easy it is to connect to GitHub over SSH on Windows based machines.