Git With SSH

Using Git with SSH is now the go-to way of committing and pushing changes to a remote repository using version control. With many version control services like GitHub pulling support for HTTPS token-based authentication, it is imperative to switch to a more secure and convenient way of managing your repositories.

In this tutorial, we will have a look at creating a new SSH key and adding it to your GitHub account to manage your repositories remotely from your Linux system.

Creating an SSH Key

  1. Open up a terminal window.

  2. At the terminal prompt, type

    ssh-keygen -t ed25519 -C "<YOUR-EMAIL>"
    

    and press enter all the way through. An SSH private-public key pair will be generated by default at $(HOME)/.ssh/id_ed2519[.pub].

    Note: If ssh-keygen is not found on your system, please install the openssh or equivalent package.

Adding Your SSH Key to GitHub

  1. Open up a browser window and go to GitHub.

  2. Login with your GitHub credentials and go to Settings, then under the Access field, click on SSH and GPG keys.

  3. Click on New SSH key at the top right of your screen.

  4. Give a title to your new SSH key, and ensure that the type is Authentication key.

  5. In a terminal window, issue the following command.

    cat ~/.ssh/id_ed25519.pub
    

    This will print out the public key that you just generated.

    Note: Please do not expose your private key online.

  6. Now, copy and paste the entire public key without extraneous characters to the Key field.

  7. Click on Add SSH Key and follow the on-screen prompts to enable Sudo mode.

  8. Your SSH key should be added and visible in SSH and GPG keys.

Next Steps

Note: Skip this section if you have already set up git to recognize who you are.

  1. Now that you have added your SSH key to your GitHub account, you have to set up git to recognize that you are committing.

  2. At a terminal window, type the following commands.

    git config --global user.name "<YOUR-NAME>"
    git config --global user.email "<YOUR-EMAIL>"
    
  3. You can now commit and push changes to your remote repositories on GitHub!

Resources

  1. Adding a new SSH key to your GitHub account.

GoatsWeb

My personal website where I post stuff!