Adding your SSH public key to GitLab. Create and add your SSH key pair. It is best practice to use Git over SSH instead of Git over HTTP. In order to use SSH, you will need to: Create an SSH key pair; Add your SSH public key to GitLab. Creating your SSH key pair. Go to your command line. Follow the instructions to generate your SSH key pair. Adding your SSH public key to GitLab. You can launch projects from a GitHub repository to your server by using a deploy key, which is an SSH key that grants access to a single repository. GitHub attaches the public part of the key directly to your repository instead of a personal user account, and the private part of the key remains on your server.
- Generate Ssh Key Github Git
- Generating New Ssh Key Github
- Generating An Ssh Key For Github Mac
- Generate Ssh Public Key For Github
Objectives
- Explain what an SSH key is
- Generate your own SSH key pair
- Add your SSH key to your GitHub account
- Learn how to use your SSH key in your GitHub workflow
Why Use an SSH Key?
When working with a GitHub repository, you'll often need to identify yourself to GitHub using your username and password. An SSH key is an alternate way to identify yourself that doesn't require you to enter you username and password every time.
SSH keys come in pairs, a public key that gets shared with services like GitHub, and a private key that is stored only on your computer. If the keys match, you're granted access.
The cryptography behind SSH keys ensures that no one can reverse engineer your private key from the public one.
Generating an SSH key pair
The first step in using SSH authorization with GitHub is to generate your own key pair.
You might already have an SSH key pair on your machine. You can check to see if one exists by moving to your
.ssh
directory and listing the contents.
Generate Ssh Key Github Git
If you see
id_rsa.pub
, you already have a key pair and don't need to create a new one.
If you don't see
id_rsa.pub
, use the following command to generate a new key pair. Make sure to replace [email protected]
with your own email address.
(The
-o
option was added in 2014; if this command fails for you, just remove the -o
and try again)
![Ssh Ssh](/uploads/1/2/6/6/126611024/854759029.png)
When asked where to save the new key, hit enter to accept the default location.
Generating New Ssh Key Github
You will then be asked to provide an optional passphrase. This can be used to make your key even more secure, but for this lesson you can skip it by hitting enter twice.
When the key generation is complete, you should see the following confirmation:
The random art image is an alternate way to match keys but we won't be needing this.
Add your public key to GitHub
We now need to tell GitHub about your public key. Display the contents of your new public key file with
cat
:
Generating An Ssh Key For Github Mac
![Generating An Ssh Key For Github Generating An Ssh Key For Github](/uploads/1/2/6/6/126611024/117509910.png)
The output should look something like this:
Copy the contents of the output to your clipboard.
Login to github.com and bring up your account settings by clicking the tools icon.
Select SSH Keys from the side menu, then click the Add SSH key button.
Name your key something whatever you like, and paste the contents of your clipboard into the Key text box.
Finally, hit Add key to save. Enter your github password if prompted.
####Using Your SSH Key
Going forward, you can use the SSH clone URL when copying a repo to your local machine.
This will allow you to bypass entering your username and password for future GitHub commands.
Key Points
- SSH is a secure alternative to username/password authorization
- SSH keys are generated in public / private pairs. Your public key can be shared with others. The private keys stays on your machine only.
- You can authorize with GitHub through SSH by sharing your public key with GitHub.
macos_sierra_chorke_ssh.sh
Generate Ssh Public Key For Github
# generating a new ssh key and adding it to the ssh agent |
# https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/ |
# ssh key generation for chorke |
ssh-keygen -t rsa -b 4096 -C '[email protected]' |
# Generating public/private rsa key pair. |
# Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter] |
# Enter passphrase (empty for no passphrase): [Type a passphrase] |
# Enter same passphrase again: [Type passphrase again] |
# start or check ssh-agent |
eval'$(ssh-agent -s)' |
# Agent pid 2911 |
# bit_chorke_rsa add to ~/.ssh/config |
# Host bit.chorke.com |
# HostName bitbucket.org |
# PreferredAuthentications publickey |
# IdentityFile ~/.ssh/bit_chorke_rsa |
# User git |
# git_chorke_rsa add to ~/.ssh/config |
# Host git.chorke.com |
# HostName github.com |
# PreferredAuthentications publickey |
# IdentityFile ~/.ssh/git_chorke_rsa |
# User git |
# add key to ssh-agent |
ssh-add -K ~/.ssh/id_rsa |
ssh-add -K ~/.ssh/bit_chorke_rsa |
ssh-add -K ~/.ssh/git_chorke_rsa |
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment