如何配置GitHub

来源:互联网 发布:个人交易怎么走淘宝 编辑:程序博客网 时间:2024/06/15 16:00

Generating an SSH key

·        MAC

·        WINDOWS

SSH keysare a way to identify trusted computers without involving passwords. You cangenerate an SSH key and add the public key to your GitHub account by followingthe procedures outlined in this section.

Werecommend that you regularly review your SSH keys list andrevoke any that haven't been used in a while.

Tip: Ifyou have GitHub for Windows installed,you can use it to clone repositories and not deal with SSH keys. It also comeswith the Git Bash tool, which is the preferred way of running git commands on Windows.

Checking for existing SSH keys

Beforeyou generate an SSH key, you can check to see if you have any existing SSHkeys.

Generating a new SSH key and adding it to thessh-agent

Afteryou've checked for existing SSH keys, you can generate a new SSH key to use forauthentication, then add it to the ssh-agent.

Adding a new SSH key to your GitHub account

Toconfigure your GitHub account to use your new (or existing) SSH key, you'llalso need to add it to your GitHub account.

Testing your SSH connection

Afteryou've set up your SSH key and added it to your GitHub account, you can testyour connection.

 

 

 

 

 

 

Checking for existing SSH keys

·        MAC

·        WINDOWS

·        LINUX

Beforeyou generate an SSH key, you can check to see if you have any existing SSHkeys.

1.     Open Git Bash.

2.     Enter ls -al ~/.ssh tosee if existing SSH keys are present:

3.  ls -al~/.ssh

4.  # Liststhe files in your .ssh directory, if they exist

5.     Check the directory listing tosee if you already have a public SSH key.

Bydefault, the filenames of the public keys are one of the following:

·        id_dsa.pub

·        id_ecdsa.pub

·        id_ed25519.pub

·        id_rsa.pub

·        If you don't have an existingpublic and private key pair, or don't wish to use any that are available toconnect to GitHub, then generate anew SSH key.

·        If you see an existing public andprivate key pair listed (for example id_rsa.pub and id_rsa) that you would like to use to connect toGitHub, you can add yourSSH key to the ssh-agent.

Tip: Ifyou receive an error that ~/.ssh doesn'texist, don't worry! We'll create it when we generate anew SSH key.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Generating a new SSH key and adding itto the ssh-agent

·        MAC

·        WINDOWS

·        LINUX

Afteryou've checked for existing SSH keys, you can generate a new SSH key to use forauthentication, then add it to the ssh-agent.

Generating a new SSH key

1.     Open Git Bash.

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

3.  ssh-keygen-t rsa -b 4096 -C "your_email@example.com"

4.  # Createsa new ssh key, using the provided email as a label

5.  Generatingpublic/private rsa key pair.

6.     When you're prompted to"Enter a file in which to save the key," press Enter. This acceptsthe default file location.

7.  Enter afile in which to save the key (/Users/you/.ssh/id_rsa):[Press enter]

8.     At the prompt, type a secure passphrase.For more information, see "Working with SSH key passphrases".

9.  Enterpassphrase (empty for no passphrase):[Type apassphrase]

10.Enter same passphraseagain:[Type passphrase again]

Adding your SSH key to thessh-agent

Beforeadding a new SSH key to the ssh-agent, you should have checked for existing SSH keys andgenerated a new SSH key.

If youhave GitHub for Windows installed,you can use it to clone repositories and not deal with SSH keys. It also comeswith the Git Bash tool, which is the preferred way of running git commands on Windows.

1.     Ensure ssh-agent is enabled:

o   If you are using Git Bash, turn onssh-agent:

o    # startthe ssh-agent in the background

o    eval"$(ssh-agent -s)"

o    Agent pid59566

o   If you are using another terminal prompt, suchas Git for Windows, turn onssh-agent:

o    # startthe ssh-agent in the background

o    eval$(ssh-agent -s)

o    Agent pid59566

2.     Add your SSH key to thessh-agent. If you used an existing SSH key rather than generating a new SSH key, you'llneed to replace id_rsa in the command with thename of your existing private key file.

3.  $ ssh-add ~/.ssh/id_rsa

4.     Add the SSH key to your GitHub account.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Adding a new SSH key to your GitHub account

·        MAC

·        WINDOWS

·        LINUX

Toconfigure your GitHub account to use your new (or existing) SSH key, you'llalso need to add it to your GitHub account.

Beforeadding a new SSH key to your GitHub account, you should have:

·        Checkedfor existing SSH keys

·        Generateda new SSH key and added it to the ssh-agent

1.     Copy the SSH key to yourclipboard.

If yourSSH key file has a different name than the example code, modify the filename tomatch your current setup. When copying your key, don't add any newlines orwhitespace.

$ clip < ~/.ssh/id_rsa.pub

# Copies the contents of the id_rsa.pubfile to your clipboard

Tip: If clip isn't working, you canlocate the hidden .ssh folder, open the file inyour favorite text editor, and copy it to your clipboard.

2.     In thetop right corner of any page, click your profile photo, then click Settings.

3.     In theuser settings sidebar, click SSH and GPG keys.

4.     Click New SSH key.

5.     In the "Title" field,add a descriptive label for the new key. For example, if you're using apersonal Mac, you might call this key "Personal MacBook Air".

6.     Pasteyour key into the "Key" field.

7.     Click Add SSH key.

8.     Confirm the action by enteringyour GitHub password.

·         Contact a human

 

 

 

 

Testing your SSH connection

·        MAC

·        WINDOWS

·        LINUX

Afteryou've set up your SSH key and added it to your GitHub account, you can testyour connection.

Beforetesting your SSH connection, you should have:

·        Checkedfor existing SSH keys

·        Generateda new SSH key

·        Added anew SSH key to your GitHub account

When youtest your connection, you'll need to authenticate this action using yourpassword, which is the SSH key passphrase you created earlier. For moreinformation on working with SSH key passphrases, see "Workingwith SSH key passphrases".

1.     Open Git Bash.

2.     Enter the following:

3.  ssh -Tgit@github.com

4.  # Attemptsto ssh to GitHub

You maysee one of these warnings:

Theauthenticity of host 'github.com (192.30.252.1)' can't be established.

RSA keyfingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.

Are yousure you want to continue connecting (yes/no)?

Theauthenticity of host 'github.com (192.30.252.1)' can't be established.

RSA keyfingerprint is nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.

Are yousure you want to continue connecting (yes/no)?

Note: Theexample above lists the GitHub IP address as 192.30.252.1. When pinging GitHub,you may see a range of IP addresses. For more information, see "WhatIP addresses does GitHub use that I should whitelist?"

5.     Verify that the fingerprint inthe message you see matches the following message, then typeyes:

6.  Hiusername! You'vesuccessfully authenticated, but GitHub does not

7.  provideshell access.

8.     Verify that the resulting messagecontains your username. If you see a message that contains "accessdenied," see "Error:Permission denied (publickey)".

If youreceive a message about "access denied," you can read theseinstructions for diagnosing the issue.

9.     If you're switching from HTTPS toSSH, you'll need to updateyour remote repository URLs.

 

0 0
原创粉丝点击