github 笔记

如果你已经安装了GitHub的windows客户端,就可以忽略此文。

1. 下载git 命令行工具 http://git-scm.com/

2.生成sshkey

2.1 cd 到保存key的文件夹

2.2 生成sshkey

出现第一个提示,

Enter file in which to save the key ,请输入将要生成的文件名

Enter passphrase (empty for no passphrase): 这个文件的密码
# Enter same passphrase again:这个文件的密码

2.3 添加到ssh-agent

这里要输入刚才的密码

如果出现 Could not open a connection to your authentication agent. 错误

在shell下执行  $ ssh-agent bash --login -i  然后执行  $ ssh-add 就好了哈。

(http://www.tangrucheng.com/implementation-of-ssh-add-could-not-open-a-connection-to-your-authentication-agent-errors.html)、

 

2.4 把刚生成的文件,内容拷贝出来

 

类似这种的

拷贝到 sshkeys里面

https://help.github.com/articles/generating-ssh-keys/

Now that you have the key copied, it's time to add it to GitHub:

  1. Settings icon in the user barIn the top right corner of any page, click .

  2. SSH keysIn the user settings sidebar, click SSH keys.

  3. SSH Key buttonClick Add SSH key.

  4. In 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".
  5. The key fieldPaste your key into the "Key" field.
  6. The Add key buttonClick Add key.
  7. Confirm the action by entering your GitHub password.

Test everything out

To make sure everything is working, you'll now try SSHing to GitHub. When you do this, you will be asked to authenticate this action using your password, which was the passphrase you created earlier.

Open up your Git Bash and type:

ssh -T git@github.com
# Attempts to ssh to GitHub

You may see this 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:2d:36:63:1b:56:4d:eb:df:a6:48.
# Are you sure you want to continue connecting (yes/no)?

Don't worry! This is supposed to happen. Verify that the fingerprint in your terminal matches the one we've provided up above, and then type "yes."

# Hi username! You've successfully authenticated, but GitHub does not
# provide shell access.

在Git 命令行里面使用的时候,如果启用了二次验证,需要用person token代替密码使用。
否则会报错

git push “Authentication Failed”

问题解答在这里

http://stackoverflow.com/questions/17659206/git-push-authentication-failed

If you enabled two-factor authentication in your Github account you won't be able to push via HTTPS using your accounts password. Instead you need to generate a personal access token. This can be done in the application settings of your Github account. Using this token as your password should allow you to push to your remote repository via HTTPS. Use your username as usual.

Source: https://help.github.com/articles/https-cloning-errors#provide-access-token-if-2fa-enabled

Creating a token

  1. Settings icon in the user barIn the top right corner of any page, click .

  2. Applications settingsIn the user settings sidebar, click Applications.

  3. Generate new token buttonClick Generate new token.

  4. Token description fieldGive your token a descriptive name.
  5. Selecting token scopesSelect the scopes you wish to grant to this token. The default scopes allow you to interact with public and private repositories, user data, and gists.
  6. Generate token buttonClick Generate token.
  7. Newly created tokenCopy the token to your clipboard. For security reasons, after you navigate off this page, no one will be able to see the token again.

Remember to keep your tokens secret; treat them just like passwords! They act on your behalf when interacting with the API. Don't hardcode them into your programs. Instead, opt to use them as environment variables.

When you're done using your token, feel free to click Delete to get rid of it permanently.



原文地址:https://www.cnblogs.com/xiaokang088/p/4204203.html