如何配置GitHub

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.

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

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

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

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.  Hi username! 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.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值