Using GitHub with SSH (Secure Shell) - GeeksforGeeks (2024)

Improve

Secure Shell (SSH) Protocol facilitates the communication among systems in an unsecured network by providing a secure channel over it. It safeguards the connection to remote servers enabling user authentication.

Using SSH, you can connect to your GitHub account eliminating the need of giving username and password each time you push changes to the remote repository. The integration process involves setting up SSH Keys within both the local and remote systems.

Connect to GitHub using SSH

Note: If you already have an existing SSH key, you can skip step 1 and go to step 2. You can verify the same by listing all the existing keys using the command:

 $ ls -al ~/.ssh 
Steps to connect GitHub to SSH :

Step 1: Generate SSH Key on Local System

  • Launch Terminal / Git Bash.
  • Paste the below command and substitute your GitHub email address:
     $ ssh-keygen -t rsa -b 4096 -C "your_email@example.com" 

    Using GitHub with SSH (Secure Shell) - GeeksforGeeks (1)

  • Press Enter when prompted “Enter a file in which to save the key”.
  • Type a passphrase of your choice.
  • Verify creation of SSH Key:
     $ ls -al ~/.ssh 

    Using GitHub with SSH (Secure Shell) - GeeksforGeeks (2)

Step 2: Add SSH Key to SSH Agent

  • Initiate ssh-agent:
     $ eval "$(ssh-agent -s)" 
  • If your key is generated with a different name, replace id_rsa in the command below:
     $ ssh-add ~/.ssh/id_rsa 

    Using GitHub with SSH (Secure Shell) - GeeksforGeeks (3)

Step 3: Add the SSH Key to your GitHub Account

  • Copy key to the clipboard:
    WINDOWS$ clip < ~/.ssh/id_rsa.pubLINUX$ sudo apt-get install xclip$ xclip -sel clip < ~/.ssh/id_rsa.pubMAC$ pbcopy < ~/.ssh/id_rsa.pub
  • Open the GitHub website and log in to your account. Go to the settings page from the menu in top right corner.
  • Select “SSH and GPG keys” from the sidebar and click on “New SSH key” option.
    Using GitHub with SSH (Secure Shell) - GeeksforGeeks (4)
  • Add relevant title in the “Title” field and paste the SSH key in the “Key field“.
  • Now, click on “Add SSH key“.

Step 4: Test the SSH Connection

  • Launch Terminal / Git Bash.
  • Type:
     $ ssh -T git@github.com 

    Using GitHub with SSH (Secure Shell) - GeeksforGeeks (5)

  • Connection is established if you are prompted with the following message:

    Hi {username}! You’ve successfully authenticated, but GitHub does not provide shell access.


Last Updated : 21 Apr, 2020

Like Article

Save Article

Share your thoughts in the comments

Please Login to comment...

Using GitHub with SSH (Secure Shell) - GeeksforGeeks (2024)
Top Articles
Latest Posts
Article information

Author: Errol Quitzon

Last Updated:

Views: 6349

Rating: 4.9 / 5 (59 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Errol Quitzon

Birthday: 1993-04-02

Address: 70604 Haley Lane, Port Weldonside, TN 99233-0942

Phone: +9665282866296

Job: Product Retail Agent

Hobby: Computer programming, Horseback riding, Hooping, Dance, Ice skating, Backpacking, Rafting

Introduction: My name is Errol Quitzon, I am a fair, cute, fancy, clean, attractive, sparkling, kind person who loves writing and wants to share my knowledge and understanding with you.