github 筆記

weixin_34377065發表於2015-01-05

如果你已經安裝了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.

 

 



 

相關文章