How to connect to Github using SSH ?
This tutorial guides you on how to connect to Github using SSH. While setting up development environment or checking out code from git for the first time, you may need to setup Github with SSH. So that it simplifies your authentication and connection process each time you visit Github repository.
How to connect to Github using SSH ?
You can use SSH protocol for authentication and connecting to remote servers. And using SSH keys you can connect to Github servers without using your username and access token each time.
Let’s see step by step procedure on how to setup Github with SSH or how to connect to Github using SSH.
SSH Keys – Existing/ Generate new one
First, you need to check whether you can use existing SSH key before you generate a new key.
To check existing SSH keys, try the following.
- Git bash
- Run the following command ls -al ~/.ssh which will list public keys if you already have some.
ubuntu@my-ubuntu-virtual-machine:~$ ls -al ~/.ssh total 20 drwx------ 2 ubuntu ubuntu 4096 Jun 7 12:43 . drwxr-xr-x 19 ubuntu ubuntu 4096 Jun 11 15:49 .. -rw------- 1 ubuntu ubuntu 464 Jun 7 12:35 id_ed25519 -rw-r--r-- 1 ubuntu ubuntu 109 Jun 7 12:35 id_ed25519.pub -rw-r--r-- 1 ubuntu ubuntu 1110 Jun 7 13:45 known_hosts
To generate a new SSH key:
- And if you don’t have any keys listed or if you don’t wish to use any of them, then you can generate a new SSH key.
- All you need to do is just open Git bash terminal and run the following command.
$ ssh-keygen -t ed25519 -C "[email protected]"
The above command will create a new SSH key using the email provided by you as label and you would see the following message.
> Generating public/private ed25519 key pair.
You will be prompted for typing secure passphrase. Hence type the passphrase and type again the same passphrase as prompted.
> Enter passphrase for key '/home/ubuntu/.ssh/id_ed25519': <Type passphrase> > Enter same passphrase again: <Type passphrase again>
Once the SSH keys are generated successfully then you need to add SSH key to your Github account.
Add SSH Key to Github account
You need to perform the below steps to add SSH key to your Github account (i.e., the email address that you have used while generating SSH keys)
- First, you need to run the following commands and copy your public key.
$ cd /home/ubuntu/.ssh/ ~.ssh/ $ ls id_ed25519 id_ed25519.pub known_hosts $ cat id_ed25519.pub ssh-ed25519 DDDGGHHHAGAGAHADASHGAH2dghdasjhgjaghakdhgkashdgdkjahkghkahgkhag [email protected]
- After that, login to your GitHub account.
- Then click your profile avatar and choose Settings.
- And select SSH and GPG keys.
- Click New SSH key.
- Enter a title in the field.
- Paste your public key into the Key field.
- Click Add SSH key.
That’s all. You had successfully added the new SSH key to your Github account.
Add your new SSH key to ssh-agent
First, make sure that ssh-agent is running on your machine. To check that you can run the following command. This command will start the ssh-agent in the background.
$ eval "$(ssh-agent -s)" > Agent pid 59568
Then you need to add your SSH private key ( id_ed25519) to the ssh-agent as shown below
$ ssh-add ~/.ssh/id_ed25519
That’s all. You are Done!
Testing Github with SSH
Finally you can try the small test to check if Github SSH setup works.
$ ssh -T [email protected] Enter passphrase for key 'home/ubuntu/.ssh/id_ed25519': Hi <username> You've successfully aunthenticated, but GitHub does not provide shell access.
Note, if you have Github Dektop installed, then you can clone git repositories without using or dealing with SSH Keys. This is just for your information.
Hope this article is helpful to you 🙂
- Set or change root password in Ubuntu Linux
- Linux: sudo: apt-get: command not found
- How to Start Stop Restart MariaDB on Linux OS ?
- Putty Fatal Error No supported authentication methods available
- How to find which users belongs to a specific group in linux
- Give write permissions for specific user or group for specific folder in linux
- How to unzip a zip file from Terminal (Google Cloud Shell)
- Build a Docker Image with a Dockerfile and Cloud Build in GCP?
- How to create GCP project on Google Cloud Platform
- MariaDB – How to set max_connections permanently ?
- How to create GCP project on Google Cloud Platform
- Is it possible to change Google Cloud Platform Project ID ?
- Create non-root SSH user account and provide access to specific folders
- MySQL : How to grant all privileges to the user on database ?
- How to install OpenJDK 11 in Ubuntu Machine ?
- Amazon Linux AMI : apt-get command not found
- How to get the first and last element of a list in Python ?
- Find the PID of the process that is using specific port ?
- Check sshd logs and status in linux ?
- How to throw away the local commits from your branch in Git ?