Setting up SSH for Git (Windows)
You just created a GitHub account, downloaded git and are ready to set get going! If you haven’t installed git on your computer I’ve written an article on the proccess.
Let’s set you up with an SSH connection for uploading(pushing) your git repo to GitHub. There is a few steps to this, but once you’re done — you’re good!
SSH is short for Secure Shell and is a cryptographic network protocol for operating network services securely over an unsecured network.
Being connected through SSH allows git to interact with GitHub without having to providing the actual login information, securely.
Open up PowerShell — (Open your start menu and start typing it - out it should then show up as a result)
Once it’s open you want to head to your user directory (should default there) and then a directory called “.ssh”. Don’t worry, if it’s not there we’ll create it.
Below will follow a few sections with commands, enter the parts not directly surrounded by **.
cd ~/.ssh** if it throws a message about it not existing do the following **
Now we need to generate the ssh information that will be used.
ssh-keygen -t rsa -b 4096 -C "githubEmail@email.com"**include "" surrounding the email**
Press enter through the next few prompts. We’ll keep the default name for the ssh-key (id_rsa) and no passphrase. I ran into some difficulties with a customized name.
We now have two new files in our .ssh directory: ‘id_rsa’ and ‘id_rsa.pub’
Now open the .pub file in a text editor.
Copy the entire content of the file - ‘ctrl+a’ to select all then ‘ctrl+c’ to copy to clipboard. You can now close the PowerShell window.
Now head over to your GitHub account settings by clicking the top right icon (or profile picture if you’ve added one), select the SSH and GPG keys option and click “New SSH key”.
Here you’ll see a form for you to fill out a Title for your SSH key and the key itself. The title is for you to be able to differentiate keys if you end up setting up on different computers etc. Paste in the content you copied from the id_rsa.pub file in the Key section. Click “Add SSH key” when ready.
Once added it should show up under the SSH key section. It will show white when not previously used and turn green when used.
Alright, we’re halfway there! Now it’s time to set things up to allow your computer to communicate with via the SSH.
We’ll need to open up PowerShell again, however we’re going to need Administrator rights for this next part. You can right-click it in the search result and select Run as Administrator. Now let’s enter some commands:
Get-Service -Name ssh-agent | Set-Service -StartupType Manual
ssh-add id_rsa **or your custom file name - Not the .pub file**
This adds the ssh key to the ssh-agent. Now we’ll verify that it communicates with GitHub, and then we’ll configure git to “recognize” you.
ssh -T firstname.lastname@example.org
** If successful should return:
Hi GitHubUserName! You've successfully authenticated, but GitHub does not provide shell access.**git config --global user.email "yourGitHubEmail@example.com"
git config --global user.name "Your Name"**I have the default init name as 'main'**
git config --global init.defaultbranch "main"
SSH should now be set up for use 😄.
Let’s create a test repository on your desktop.
cd test-sshgit init
notepad readme.md **notepad will open and ask if you want to create the file since it doesn't exist - click yes**
git add .
git commit -m "initial commit. Checking if ssh is working"
Your local repository is now ready, now we’ll just have to make a repository on GitHub. Click the “+” button next to your profile-icon and select “New repository”. We’ll create an empty repository for this test, all you need is to give it a name, keep it as public and click “Create repository”.
The following page gives some information on how to use the new repository. We don’t need all the extra info here, click the “SSH” button and then click the small clipboard icon (or copy the text-content next to it manually) to copy it to your clipboard, we will use this next.
Now back to PowerShell, you kept it open, right? 😉
git remote add origin githubSSHText
it should look something like this:
git remote -v
should return something like:
origin githuburl/repo-name.git (fetch)
origin githuburl/repo-name.git (pull)
**git push -u origin main
It should now push the local repository (just one file in this case) online, isn’t that exciting?!
If you made it this far I want to thank you for your time and attention. I have more stuff coming.