Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»General Articles»Adding a New SSH Key to Your GitHub Account

    Adding a New SSH Key to Your GitHub Account

    By RahulJanuary 5, 20234 Mins Read

    GitHub is a popular platform for hosting Git repositories, and it supports accessing repositories over SSH (Secure Shell). In order to access a GitHub repository over SSH, you will need to generate an SSH key pair and add the public key to your GitHub account.

    Advertisement

    Here are the steps for adding a new SSH key to your GitHub account:

    Prerequisites

    Before you can add an SSH key to your GitHub account, you will need to do the following:

    • Generate an SSH key pair. This consists of a private key and a public key. The private key is kept on your local machine, and the public key is uploaded to your GitHub account.
    • Install Git on your local machine. You will need Git installed in order to use the ssh-keygen command to generate the SSH key pair.

    The next step will help you to generate SSH key pair on your system.

    Generating an SSH Key Pair

    To generate an SSH key pair, follow these steps:

    1. Open a terminal window (Git Bash on Windows, or any terminal emulator on macOS or Linux).
    2. Run the following command to generate an SSH key pair:
      ssh-keygen -t rsa -b 4096 
      
      Output:
      [email protected]:~$ ssh-keygen -t rsa -b 4096 Generating public/private rsa key pair. Enter file in which to save the key (/home/rahul/.ssh/id_rsa): [PRESS ENTER] Enter passphrase (empty for no passphrase): [PRESS ENTER] Enter same passphrase again: [PRESS ENTER] Your identification has been saved in /home/rahul/.ssh/id_rsa Your public key has been saved in /home/rahul/.ssh/id_rsa.pub The key fingerprint is: SHA256:r/ohd9s7kHb2SygRRpdvAiO6x7cEdO9yDAZkpQnvQXs [email protected] The key's randomart image is: +---[RSA 4096]----+ | ..+.o .. | | =+=+.. | | o*+E+ . | | ...+o.o o | | oSo.= o | | . o.B.*. | | ..o++B... | | o +.+... | | .oo . oo.. | +----[SHA256]-----+

    This will generate a new SSH key pair using the RSA algorithm with a key length of 4096 bits.

    • When prompted, enter a file name for the private key. This is the file where the private key will be stored. You can use the default file name (id_rsa) or choose a different name.
    • When prompted, enter a passphrase for the private key. This is an optional security measure that adds an additional layer of protection to your private key. If you do not want to use a passphrase, just press Enter.
    • The ssh-keygen command will generate the SSH key pair and store the private key in the file that you specified. The public key will be stored in a file with the same name, but with a .pub extension.

    For example, if you specified the file name “id_rsa”, the private key will be stored in “id_rsa” and the public key will be stored in “id_rsa.pub”.

    Adding the Public Key to Your GitHub Account

    Now that you have generated an SSH key pair, you can add the public key to your GitHub account as follows:

    1. Go to your GitHub account settings.

      Adding a New SSH Key to Your GitHub Account
      Open Github Account Settings
    2. Select the “SSH and GPG keys” tab.

      Adding a New SSH Key to Your GitHub Account
      Go to “SSH and GPG keys” option
    3. Click the “New SSH key” button.

      Add new SSH Key in Github
      click “New SSH Key” button
    4. In the “Title” field, enter a name for the key. This can be any name that helps you identify the key.
    5. In the “Key” field, paste the contents of the public key file (e.g., id_rsa.pub).
      Adding SSH Key in Github Account
      Adding SSH Key

      You can use the cat command to view the contents of the file, or you can open it in a text editor.

      cat id_rsa.pub 
      
    6. Click the “Add SSH key” button to save the key.

    That’s it! You should now see the new SSH key listed in your GitHub account settings. You can use this key to access GitHub repositories over SSH.

    I hope this helps! Let me know if you have any questions or need further clarification on any of the steps.

    github SSH
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    20 Basic Linux Commands for the Beginners (Recommended)

    tail Command in Linux with Examples

    What is a Orphan Process in Unix/Linux

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • 20 Basic Linux Commands for the Beginners (Recommended)
    • tail Command in Linux with Examples
    • What is a Orphan Process in Unix/Linux
    • How To Display Warning Message to Unauthorized SSH Access
    • How to Set a Custom SSH Login Banner and MOTD
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.