# Using Github with SSH keys

## Generate a public/private RSA key pair <a href="#generate_a_publicprivate_rsa_key_pair" id="generate_a_publicprivate_rsa_key_pair"></a>

Skip to next step if you have an existing SSH key pair.

{% hint style="info" %}
Windows users can use either PowerShell, Windows Terminal, or WSL (Windows Subsystem for Linux).  Mac and Linux users should use their preferred terminal.
{% endhint %}

Run the `ssh-keygen` command with default arguments to generate and replace your private keypair.

```
ssh-keygen -t rsa
```

You will be prompted to provide a filename and an additional password if required.

{% hint style="info" %}
It is common to NOT use a password with the private key because the operating system already controls user access.
{% endhint %}

The output will look like this:

<figure><img src="https://1008771031-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fo84Tuz16JeqaVoFstgKj%2Fuploads%2FvT6jRVFS31qZxxfw46CD%2Fssh-keygen.png?alt=media&#x26;token=e90d72d2-88a1-4937-aac9-c1b3e5dd65ac" alt="" width="563"><figcaption></figcaption></figure>

## Copy the public key

Use the terminal to display the public key, highlight, and copy to clipboard.

{% hint style="danger" %}
The public key will have a .pub file extension.  You should never share your private key!
{% endhint %}

```
$ cd $HOME/.ssh
$ cat id_rsa.pub
```

The output will look similar to the following:

<figure><img src="https://1008771031-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fo84Tuz16JeqaVoFstgKj%2Fuploads%2Fb5IAri7lRn4kS01Igm3A%2Fssh%20output.png?alt=media&#x26;token=4955b740-3dcf-4f5a-b4ec-14877a712165" alt=""><figcaption></figcaption></figure>

## Save the public key to GitHub

Navigate to 'Settings' under your GitHub profile.  In the Left navigation select 'SSH and GPG keys':

<figure><img src="https://1008771031-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fo84Tuz16JeqaVoFstgKj%2Fuploads%2FYH0Jn2cWQN0s56vBrPCw%2Fimage1.png?alt=media&#x26;token=423bd6d2-bb02-4045-9c20-d13591c6a669" alt="" width="172"><figcaption></figcaption></figure>

Select 'New SSH key', add a title with any descriptive name, and paste the public key into the Key textarea:

<figure><img src="https://1008771031-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fo84Tuz16JeqaVoFstgKj%2Fuploads%2Fy5DhFhjjSwOx9UUXmTX2%2Fimage.png?alt=media&#x26;token=dfa7c536-9c76-447a-897b-eed5f45cb5c7" alt="" width="375"><figcaption></figcaption></figure>

Your repos will now show clone commands using SSH:

<figure><img src="https://1008771031-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fo84Tuz16JeqaVoFstgKj%2Fuploads%2FdXhpWifTJJRKJOtlYQQg%2Fimage.png?alt=media&#x26;token=9c876b0d-611d-45d5-baba-cecd18f864e2" alt="" width="238"><figcaption></figcaption></figure>
