For beginners to understand, you might need to connect your PC to GitHub to store your project and its versions secured on cloud. You can upload files/folder directly to GitHub using its user interface but their is far easier and quicker and professional way to do the same.
Using SSH ( Secure Socket Shell ) you can directly upload your entire code from your computers command prompt but to do so GitHub must know and acknowledge your computer as a authorized device or else anyone would upload code that might break or corrupt your code on cloud.
Here I will only explain how you will make GitHub acknowledge your system in few Simple Steps:
Generating a New SSH Key
This is a secret key or password that will let you connect your computer to GitHub
a) Open Git Bash ( If not installed you can simply download and install it from here )
b) Paste the text below in your terminal or gitbash, substituting in your GitHub email address.
$ ssh-keygen -t ed25519 -C "firstname.lastname@example.org"
This creates a new ssh key, using the provided email as a label.
c) When you’re prompted to “Enter a file in which to save the key,” press Enter. This accepts the default file location.
d) When prompted Enter Paraphrase it is like a password you create and must remember. Although if you are not confident enough to remember the password you could just press enter twice that means whenever you will connect you need not enter any password which means less security.
Adding Your SSH key to the SSH Agent
The ssh-agent is a helper program that keeps track of user’s identity keys and their passphrases.
a) Starting the ssh-agent in the background
# start the ssh-agent in the background $ eval "$(ssh-agent -s)"
b) Adding the ssh private key to the ssh agent
# add the ssh private key to the ssh agent $ ssh-add ~/.ssh/id_ed25519
Adding the new SSH-Key to you GitHub Account
Very good, We are half the way now. If you faced any difficulty until now or you had existing ssh keys you can click here for detailed reference and guidance from GitHub official docs.
- Copy the SSH public key to your clipboard.
$ clip < ~/.ssh/id_ed25519.pub # Copies the contents of the id_ed25519.pub file to your clipboard
clip isn’t working, you can locate the hidden
.ssh folder, open the file in your favorite text editor, and copy it to your clipboard.
2. Open and login to your GitHub account
3. In the user settings sidebar, click SSH and GPG keys.
4. Click New SSH key or Add SSH key.
5. In the “Title” field, add a descriptive label for the new key. For example, if you’re using a personal Laptop, you might call this key “Personal Home Laptop”.
6. Paste your key into the “Key” field.
Testing you Connection
This is important because sometimes things might no go as planned
- Open GitBash
- Enter the following:
$ ssh -T email@example.com # Attempts to ssh to GitHub
3. Now here I faced an issue:
4. Noticed the RSA key fingerprint was different than to what I added to the GitHub.
5. Solution : When this line prompts : Are you sure you want to continue connecting (yes/no/[fingerprint])?
Rather than writing yes / no , paste the code that you GitHub is displaying like down below
Now your computer is connected to GitHub via SSH