github免输用户名/密码SSH登录的配置
2016-09-22 10:53 oijen 阅读(5178) 评论(0) 编辑 收藏 举报从github上获取的,自己整理了下,以备后用。
Generating an SSH key
SSH keys are a way to identify trusted computers without involving passwords. You can generate an SSH key and add the public key to your GitHub account by following the procedures outlined in this section.
We recommend that you regularly review your SSH keys list and revoke any that haven't been used in a while.
Tip: If you have GitHub for Windows installed, you can use it to clone repositories and not deal with SSH keys. It also comes with the Git Bash tool, which is the preferred way of running git
commands on Windows.
Checking for existing SSH keys
Before you generate an SSH key, you can check to see if you have any existing SSH keys.
Generating a new SSH key and adding it to the ssh-agent
After you've checked for existing SSH keys, you can generate a new SSH key to use for authentication, then add it to the ssh-agent.
Adding a new SSH key to your GitHub account
To configure your GitHub account to use your new (or existing) SSH key, you'll also need to add it to your GitHub account.
Testing your SSH connection
After you've set up your SSH key and added it to your GitHub account, you can test your connection.
Checking for existing SSH keys
Before you generate an SSH key, you can check to see if you have any existing SSH keys.
-
Open Git Bash.
-
Enter
ls -al ~/.ssh
to see if existing SSH keys are present:ls -al ~/.ssh # Lists the files in your .ssh directory, if they exist
-
Check the directory listing to see if you already have a public SSH key.
By default, 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 existing public and private key pair, or don't wish to use any that are available to connect to GitHub, then generate a new SSH key.
- If you see an existing public and private key pair listed (for example id_rsa.pub and id_rsa) that you would like to use to connect to GitHub, you can add your SSH key to the ssh-agent.
Tip: If you receive an error that ~/.ssh doesn't exist, don't worry! We'll create it when we generate a new SSH key.
Generating a new SSH key and adding it to the ssh-agent
After you've checked for existing SSH keys, you can generate a new SSH key to use for authentication, then add it to the ssh-agent.
Generating a new SSH key
-
Open Git Bash.
-
Paste the text below, substituting in your GitHub email address.
ssh-keygen -t rsa -b 4096 -C "your_email@example.com" # Creates a new ssh key, using the provided email as a label Generating public/private rsa key pair.
-
When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location.
Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
-
At the prompt, type a secure passphrase. For more information, see "Working with SSH key passphrases".
Enter passphrase (empty for no passphrase): [Type a passphrase] Enter same passphrase again: [Type passphrase again]
Adding your SSH key to the ssh-agent
Before adding a new SSH key to the ssh-agent, you should have checked for existing SSH keys and generated a new SSH key.
If you have GitHub for Windows installed, you can use it to clone repositories and not deal with SSH keys. It also comes with the Git Bash tool, which is the preferred way of running git
commands on Windows.
-
Ensure ssh-agent is enabled:
-
If you are using Git Bash, turn on ssh-agent:
# start the ssh-agent in the background eval "$(ssh-agent -s)" Agent pid 59566
-
If you are using another terminal prompt, such as Git for Windows, turn on ssh-agent:
# start the ssh-agent in the background eval $(ssh-agent -s) Agent pid 59566
-
-
Add your SSH key to the ssh-agent. If you used an existing SSH key rather than generating a new SSH key, you'll need to replace id_rsa in the command with the name of your existing private key file.
$ ssh-add ~/.ssh/id_rsa