How to setup SSH key for Git from scratch

less than 1 minute read

Published:

Writing this blog, as I always have to look up for various links on the internet to set up Git and SSH keys on a fresh install of an operating system. The following setup is for Linux

  1. Install git. Run
    sudo apt install git-all
  2. Check the version to see if installed correctly
    git --version
  3. Setup the configuration file by adding your name and email address
    git config --global user.name "John Doe"
    git config --global user.email johndoe@example.com
  4. Create a new SSH key
    ssh-keygen -t ed25519 -C "johndoe@example.com"
    Press enter to select the default location
  5. Start the SSH agent in background
    eval "$(ssh-agent -s)"
  6. Now, add the SSH private key to the SSH agent
    ssh-add ~/.ssh/id_ed25519
  7. Copy the SSH public key
    cat ~/.ssh/id_ed25519.pub
  8. Add this key to your GitHub account by navigating to the SSH key section in settings

References:

  1. Install Git
  2. Setup Git for the first time
  3. Generating a new SSH key
  4. Adding the SSH key to your GitHub account