Skip to content

Using SSH Keys with Git Providers

Copy Your Public Key to the Clipboard

Run the following command in PowerShell to copy your public key to the clipboard:

Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub | Set-Clipboard

If you are using a different key type, replace id_ed25519.pub with the appropriate filename. If your key is not located in the default ~/.ssh/ directory, replace ~/.ssh/id_ed25519.pub with the path to your public key file. Only ever copy the public key to the clipboard, never the private key. The public key is typically the file with the .pub extension.

Run the following command in Terminal to copy your public key to the clipboard:

pbcopy < ~/.ssh/id_ed25519.pub

If you are using a different key type, replace id_ed25519.pub with the appropriate filename. If your key is not located in the default ~/.ssh/ directory, replace ~/.ssh/id_ed25519.pub with the path to your public key file. Only ever copy the public key to the clipboard, never the private key. The public key is typically the file with the .pub extension.

Run the following command in Terminal to copy your public key to the clipboard:

xclip -selection clipboard < ~/.ssh/id_ed25519.pub

If you are using a different key type, replace id_ed25519.pub with the appropriate filename. If your key is not located in the default ~/.ssh/ directory, replace ~/.ssh/id_ed25519.pub with the path to your public key file. Only ever copy the public key to the clipboard, never the private key. The public key is typically the file with the .pub extension.

Add Your Public Key to Your Git Provider

Follow the steps in the GitHub documentation to copy your key to the website. Make sure you have already copied your public key to the clipboard, have a GitHub account, and are logged in.

Follow the steps in the GitLab documentation to copy your key to the website. Make sure you have already copied your public key to the clipboard, have a GitLab Lehigh account, and are logged in.

Follow the steps in the Bitbucket documentation to copy your key to the website. You only have to read the section stating "Provide Bitbucket Cloud with your public key". Make sure you have already copied your public key to the clipboard, have a Bitbucket account, and are logged in.

Test Your SSH Connection

Run the following command to test your SSH connection to GitHub:

ssh -T git@github.com
# Attempts to ssh to GitHub

If you see a warning like this, just enter yes to continue:

> The authenticity of host 'github.com (IP ADDRESS)' can't be established.
> ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
> Are you sure you want to continue connecting (yes/no)?

The final output of the command should look like this:

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

Run the following command to test your SSH connection to GitLab Lehigh:

ssh -T git@gitlab.cse.lehigh.edu
# Attempts to ssh to GitLab Lehigh

If you see a warning like this, just enter yes to continue:

> The authenticity of host 'gitlab.cse.lehigh.edu (IP ADDRESS)' can't be established.
> ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
> Are you sure you want to continue connecting (yes/no)?

The final output of the command should look like this:

> Welcome to GitLab, <username>!

Run the following command to test your SSH connection to Bitbucket:

ssh -T git@bitbucket.org 
# Attempts to ssh to Bitbucket

If you see a warning like this, just enter yes to continue:

> The authenticity of host 'bitbucket.org (IP ADDRESS)' can't be established.
> ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
> Are you sure you want to continue connecting (yes/no)?

The command should tell you whether you successfully connected to Bitbucket and authenticated.

Configuring Your Git Repository to Use Your SSH Key

If you have an existing repository that you want to use your SSH key with, you will need to update the remote URL to use your SSH key. You can do this by running the following command in the root directory of your repository.

Please note that this is an example URL, and you will need to retrieve your SSH URL for this specific Git repository from your Git provider's website. Most Git providers support this functionality. In GitHub, you can find the SSH URL by clicking on the "Code" button, and then clicking on the "SSH" tab.

git remote set-url origin git@github.com:USERNAME/REPOSITORY.git

If you want to clone (download) a repository by using your SSH key, you can do so by running the following command.

Please note that this is an example URL, and you will need to retrieve your SSH URL for this specific Git repository from your Git provider's website. Most Git providers support this functionality. In GitHub, you can find the SSH URL by clicking on the "Code" button, and then clicking on the "SSH" tab.

git clone git@github.com:USERNAME/REPOSITORY.git

If you want to upload your local code to a new repository in your Git provider that uses your SSH key, you can do so by following the steps in the documentation for your Git provider. Most Git providers support this functionality. In GitHub, you can find the steps to create a new repository by clicking on the "New" button, and then clicking on the "Create repository" button.

Then, you can copy the SSH URL and use it to connect to your new repository by running the following command:

git remote add origin git@github.com:USERNAME/REPOSITORY.git

Please note that this is an example URL, and you will need to retrieve your SSH URL for this specific Git repository from your Git provider's website. You will also need to have already created the repository on the Git provider's website beforehand to retrieve the required SSH URL.

After running the command, your local repository will be connected to the new remote repository on your Git provider. You can now proceed to push, branch, pull, and merge as you would with any other repository.