Generating SSH Keys
SSH Keys is a-identify trusted computers, without involving passwords. The steps below would walk you through generating a SSH key and adding the public key to your GitHub account.
We recommend that you regularly review your SSH keys list and revoke all that haven ' t been used in a WHI Le.
Tip: If You have a GitHub for Windows installed, you can use it to clone repositories and not deal WI Th SSH keys. It also comes with the Git Bash tool, which is the preferred-of- the----The running git
commands on Windows.
Step 1:check for SSH keys
First, we need to check for existing SSH keys on your computer. Open Git Bash and enter:
Ls-al ~/.ssh# Lists the files in your. SSH directory, if they exist
Check the directory listing to see if you already has a public SSH key. By default, the filenames of the public keys is one of the following:
Id_dsa.pub
Id_ecdsa.pub
Id_ed25519.pub
Id_rsa.pub
if You see a existing public and private key pair listed (for example Id_rsa . pub and Id_rsa ) That's would like-to-use-connect to GitHub, you CA n Skip Step 2 and go straight to Step 3 .
Tip: If You receive a error that ~/.ssh doesn ' t exist, don ' t worry! We ' ll create it in Step 2.
Step 2:generate a new SSH key
-
with git Bash still open, copy and paste the text below. Make sure your substitute in your GitHub email address.
ssh-keygen -t rsa -b 4096 -c "[email protected]" # creates a new ssh key, using the provided email as a label# generating public/private rsa key pair.
-
we strongly suggest keeping the default settings as they is, so if you ' re prompted to" Enter a F Ile in which to save the key ", just press Enter to continue.
# enter file in which to save the key ( /USERS/YOU/.SSH/ID_RSA): [press enter]
-
you ' ll be asked to enter a passphrase.
# enter passphrase (empty for no passphrase): [ Type a passphrase]# enter same passphrase again: [type passphrase again]
Tip: We strongly recommend a very good, secure passphrase. For more information, see "Working with SSH key passphrases".
After you enter a passphrase, you'll be given the fingerprint, or ID, of your SSH key. It'll look something like this:
# Your identification have been saved in/users/you/.ssh/id_rsa.# Your public key have been saved In/users/you/.ssh/id_rsa. pub.# the key fingerprint is:# 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db [email protected]
Step 3:add your key to the Ssh-agent
To configure the ssh-agent program to use your SSH key:
If you have a GitHub for Windows installed, you can use the it to clone repositories and is deal with SSH key S. It also comes with the Git Bash tool, which is the preferred-by- the--the running git
commands on Windows .
Ensure Ssh-agent is enabled:
If You is using Git Bash, turn on ssh-agent:
# Start the ssh-agent in the backgroundssh-agent-s# agent PID 59566
If You is using another terminal prompt, such as msysgit, turn on ssh-agent:
# Start the ssh-agent in the Backgroundeval $ (ssh-agent-s) # Agent PID 59566
Add your SSH key to the ssh-agent:
Ssh-add ~/.ssh/id_rsa
Tip: If you didn ' t generate a new SSH key in Step 2, and used an existing SSH key instead, you'll Need to replace Id_rsain the above command with the name of the your existing private key file.
Step 4:add your SSH key to your account
To configure your GitHub account to use your SSH key:
Copy the SSH key to your clipboard. If your key is named id_dsa.pub
, id_ecdsa.pub
or, then change the id_ed25519.pub
filename of the below from id_ Rsa.pub to the one, matches your key:
Clip < ~/.ssh/id_rsa.pub# Copies the contents of the Id_rsa.pub file to your clipboard
Warning: It ' s important to copy the key exactly without adding newlines or whitespace.
Add the copied key to GitHub:
In the top right corner of any page, click your profiles photo, then click Settings.
In the user settings sidebar, click SSH keys.
Click Add SSH key.
The Title field, add a descriptive label for the new key. For example, if you ' re using a-personal Mac, you might call this key "personal MacBook Air".
Paste your key into the "key" field.
Click Add key.
Confirm the action by entering your GitHub password.
Step 5:test the connection
to Make sure everything are working, you'll now try to SSH into GitHub. When you do this, you'll be asked to authenticate this action using your password, which are the SSH key passphrase you c Reated earlier.
-
open git Bash and enter:
ssh -t [email protected]# attempts to ssh to github
Warning:
# The authenticity of host ' github.com (207.97.227.239) ' can ' t be established.# RSA key fingerprint is 16:27:ac:a5:76:28:2 d:36:63:1b:56:4d:eb:df:a6:48.# is sure you want to continue connecting (yes/no)?
Verify the fingerprint in the message to see matches the following message and then type yes
:
# Hi username! You ' ve successfully authenticated, but GitHub does not# provide shell access.
If the username in the message was yours, you ' ve successfully set up your SSH key!
If you receive a message on "Access Denied," You can read these instructions for diagnosing the issue.
If you ' re switching from HTTPS to SSH, you'll now have need to update your remote repository URLs. For more information, see changing a remote ' s URL.
Generating SSH Keys