Skip to main content

Connecting Git and Github using SSH


        $ implies command line command

> implies the outcome in the command line


Connecting Git and Github using SSH


The Secure Shell Protocol is a cryptographic network protocol for operating network services securely over an unsecured network. Its most notable applications are remote login and command-line execution. SSH applications are based on a client–server architecture, connecting an SSH client instance with an SSH server.

Now we are about to see how to connect your PC with Github (so that we can access our Github through our Git Bash in our Windows computer)

(a list of files in your .ssh directory will be printed, if available)

  • Check the directory listing for one of the following,

id_rsa.pub

id_ecdsa.pub

id_ed25519.pub

If they are not found or if you have an error running step 3, you do not have an existing SSH key pair. To create a new one follow the steps below. 

  • Either generate a new SSH key or upload an existing one. 

If you don’t have or don’t wish to an existing key, generate a new one. 

Or if you already have a key you desire listed, you can add that to Github. 

  • In Git Bash, use the command as below substituting your email address,

$ ssh-keygen -t ed25519 -C “your_email@example.com”

If you are using a legacy system which doesn’t support the ed25519 algorithm, use

$ ssh-keygen -t rsa -b 4096 -C “your_email@example.com"

This creates a new SSH key, using the provided email as a label.

> Generating public/private algorithm key pair.


  • When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location.

> Enter a file in which to save the key (/c/Users/you/.ssh/id_algorithm):[Press enter]

  • At the prompt, type a secure passphrase.

> Enter passphrase (empty for no passphrase): [Type a passphrase]

> Enter same passphrase again: [Type passphrase again]

Now we have a new SSH key. 


Adding your SSH key to the ssh-agent


Before adding a new SSH key to the ssh-agent to manage your keys, you should have checked for existing SSH keys and generated a new SSH key.


  • Ensure the ssh-agent is running. To start it manually,

$ eval "$(ssh-agent -s)”

> Agent pid 59566

  • Add your SSH private key to the ssh-agent. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file.

$ ssh-add ~/.ssh/id_ed25519


Adding a new SSH key to your account


  • Copy the Ssh public key to your clipboard.

$ clip < ~/.ssh/id_ed25519.pub

This command copies the contents of your file to the clipboard.

(Note:  If your SSH public key file has a different name than the example code, modify the filename to match your current setup. When copying your key, don't add any newlines or whitespace.) 

  • In the upper-right corner of Github page, click your profile photo, then click Settings.
Image

  • In the “Access” section of the sidebar, click SSH and GPG keys. 
  • Click New SSH key or Add SSH key. 
Image

  • In the “Title” field, add a descriptive label for the new key.
  • Select the type of key, either authentication or signing. 
  • Paste your key into the “Key” field. 
Image

  • Click Add SSH key. 
  • If prompted, confirm access to your account on Github. 


Testing SSH connection

  • In Git Bash, enter this command,

$ ssh -T git@github.com 

A warning might appear like this,

> The authenticity of host 'github.com (IP ADDRESS)' can't be established.

> RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.

> Are you sure you want to continue connecting (yes/no)?

  • Verify the RSA fingerprint you see matches Github’s public key fingerprint. If it does, then type yes. A successful message would look like this,

> Hi username! You've successfully authenticated, but GitHub does not

> provide shell access.

As you have added your SSH key to your Github account, you can push, pull and do more Git commands through your CLI.  

Comments

Popular posts from this blog

Getting started with WSL

I recently started learning Linux operating system. I have a windows machine. I searched for what are the possible ways available to work with Linux. I ended up with more ways to install Linux and work with it. WSL is one of the simplest ways to get started with Linux on windows. So, I'll be sharing my learnings about WSL. It's obvious that to learn Linux one should have a Linux-based machine to work with and execute commands. There are four possible ways to get started with Linux. Possible ways to work with Linux Building a Linux-based computer which is quite expensive. I myself don't prefer to build a machine when I am a Student. Installing and using Linux in dual boot mode with your existing Windows using a virtual box. This is one of my preferred ways but it consumes more storage. So, this too fails. And the next way is to create instances in cloud platforms like AWS, GCP, and Azure and using remotely. Also, there is no cost associated with it. Because major cloud platf...

Elasticsearch- II

 ELASTICSEARCH                                          In this blog we are going to learn how to use elasticsearch and kibana using python. Before getting into this, make sure that you have elasticsearch and kibana installed. To know the detailed procedure about the installation of elasticsearch and kibana, click the link below to learn the installation process from scratch. https://crescenttechnocratsclub.blogspot.com/2022/09/blog-post.html For python, let’s use VS Code . Visual Studio (VS) Code is a streamlined code editor with support for development operations like debugging, task running, and version control. Python IDLE is also fine to use but we will work with vs code in this blog. Install VS code using the following link : https://code.visualstudio.com/download Click op...

Why you need Linux Right Now!

  Introduction Linux is an open-source operating system created in 1991 by Linus Torvalds. It's an alternative to the more popular Windows and Mac operating systems, and it comes with a wide range of features that make it a great choice for everyone, from beginners to seasoned professionals. In this blog, we'll discuss what Linux is, what it can offer you, and why you should start using it today. What Is Linux? Linux is used today by millions of people worldwide, including large corporations, small businesses, government organizations, and individuals. There are many reasons why you should use Linux. Here are a few: Linux is stable and secure. It is less likely to crash or become infected with a virus than Windows. Linux is customizable. You can change the look and feel of Linux to suit your needs, and you can add or remove software to create the perfect operating system for you. Linux is free. There are no licensing fees required to use Linux, and there are many free applicati...