Connecting to GitHub with SSH


Install Git

On Windows, download git for windows.

On Linux, running the command sudo apt-get install git to install git.

Verify that the installation was successful:

git --version

Git Settings

Setting your user name and email for git

git config --global "taogen"
git config --global ""

Check your git settings

git config
git config

Checking for existing SSH keys

Before you generate an SSH key, you can check to see if you have any existing SSH keys.

  1. Open Terminal or Git Bash

  2. Enter ls -al ~/.ssh to see if existing SSH keys are present.

  3. Check the directory listing to see if you already have a public SSH key. By default, the filenames of supported public keys for GitHub are one of the following.




  4. Either generate a new SSH key or upload an existing key.

Generating a new SSH key and adding it to the ssh-agent

Generating a new SSH key

  1. Open Terminal or Git Bash

  2. Paste the text below, substituting in your GitHub email address.

    $ ssh-keygen -t ed25519 -C ""

    Note: If you are using a legacy system that doesn’t support the Ed25519 algorithm, use:

    $ ssh-keygen -t rsa -b 4096 -C ""

    After running the above command, you need to enter a file path or use the default file path and enter a passphrase or no passphrase.

    Generating public/private ALGORITHM key pair.
    Enter file in which to save the key (C:/Users/YOU/.ssh/id_ALGORITHM):
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in C:/Users/YOU/.ssh/id_ALGORITHM.
    Your public key has been saved in C:/Users/YOU/.ssh/
    The key fingerprint is:
    The key's randomart image is:
    +--[ED25519 256]--+
    | .. o|
    | . .++|
    | o++.|
    | o = .ooB.|
    | . S = =o* +|
    | * =.+ =o|
    | . o .+=*|
    | +=O|
    | .oBE|

Adding your SSH key to the ssh-agent

You can secure your SSH keys and configure an authentication agent so that you won’t have to reenter your passphrase every time you use your SSH keys.

  1. Ensure the ssh-agent is running.

Start it manually:

# start the ssh-agent in the background
$ eval "$(ssh-agent -s)"
> Agent pid 59566

Auto-launching the ssh-agent Configuration

You can run ssh-agent automatically when you open bash or Git shell. Copy the following lines and paste them into your ~/.profile or ~/.bashrc file in Git shell:


agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }

agent_start () {
(umask 077; ssh-agent >| "$env")
. "$env" >| /dev/null ; }


# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2=agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)

if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then

unset env
  1. Add your SSH private key to the ssh-agent.

If your private key is not stored in one of the default locations (like ~/.ssh/id_rsa), you’ll need to tell your SSH authentication agent where to find it. To add your key to ssh-agent, type ssh-add ~/path/to/my_key.

$ ssh-add ~/.ssh/id_ed25519

Adding a new SSH key to your GitHub account

  1. Open Terminal or Git Bash. Copy the SSH public key to your clipboard.

    $ pbcopy < ~/.ssh/
    # Copies the contents of the file to your clipboard


    $ clip < ~/.ssh/
    # Copies the contents of the file to your clipboard


    $ cat ~/.ssh/
    # Then select and copy the contents of the file
    # displayed in the terminal to your clipboard
  2. -> Settings -> Access - SSH and GPG keys -> New SSH key

Testing your SSH connection

After you’ve set up your SSH key and added it to your account on, you can test your connection.

  1. Open Terminal or Git Bash

  2. Enter the following command

    $ ssh -T
    # Attempts to ssh to GitHub

    If you see the following message, you have successfully connected GitHub with SSH.

    > Hi USERNAME! You've successfully authenticated, but GitHub does not
    > provide shell access.


[1] Connecting to GitHub with SSH