請提早到官網註冊GitHub帳號,提早在terminal或者cmd安裝git,而後你要檢測本身電腦是否存在 SSH key,而後須要把SSH key複製下來,粘貼到你的GitHub。
- 第一步:安裝git,通常都尚未安裝git就去找SSH key,怎麼可能找獲得
- 請必須先有本身的GitHub帳號,而後纔是找本身的SSH key
- Mac如何找到本身的SSH key,步驟很詳細,跟着走不會有問題javascript
- https://www.jianshu.com/p/5b34b7b34cae php
前言:最近有很多剛剛使用github管理代碼的開發者或者新手碼農在網上 問我如何關聯本身的github,今天就寫篇文章僅供參考。
1、首先你要檢測本身電腦是否存在 SSH keycss
在終端輸出: ls -al ~/.ssh
若是你本地沒有生成的話java
終端上面會顯示:No such file or directory
若是已經存在的話,git
則會顯示 id_rsa 和 id_rsa.pub
2、若是本地沒有的話,咱們要本身手動生成了如今咱們來Show一把github
在終端輸入:ssh-keygen -t rsa -C "your_email@example.com"
"your_email@example.com" 爲事例郵箱,此處應填寫爲你在github上面註冊的郵箱。shell
成功後終端上面會顯示結果以下:vim
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/xxx/.ssh/id_rsa):
提示你保存.ssh/id_rsa的路徑,這裏直接Enter就好windows
Greated directory '/Users/xxx/.ssh'. Enter passphrase(empty for no passphrase):
這時提示輸入passphrase,每次與Github通訊都會要求輸入passphrase,以免某些「失誤」,建議輸入ruby
成功後,終端顯示
Your identitification has been saved in /Users/xxx/.ssh/id_rsa. Your public key has been saved in /user/xxx/id_rsa.pub. the key fingerprint is xxxxxxxxxx.......xxxxxxxx your_email@example.com The key's randomart image is:(這裏圖就省略顯示了)
3、天劍key到SSH
終端輸入命令:
ssh-add ~/.ssh/id_rsa
此時會要求輸入passphrase(輸入步驟 二 中的 passphrase就好 )
成功後,中選顯示:
identity added:/User/xxx/.ssh/id_rsa(/Users/xxx/.ssh/id_rsa)
最後會在 /Users/xxx/.ssh/ 生成兩個文件,id_rsa和id_rsa.pub,這樣 SSH key 就已經生成成功了
4、添加SSH key 到Github 上
這裏有兩種方法:一種找到內容id_rsa.pub、一種用命令行
一、直接 終端輸入:vim ~/.ssh/id_rsa.pub
終端顯示
手動複製從ssh-rsa 開始,以your_email@example.com結束,而後粘貼到你登陸的github帳號上面Settings -->SSH keys -->Add SSH key 保存便可 Title 能夠隨便寫,Key粘貼剛複製內容,這樣SSH key 就添加到你的Github上了。
二、或者 在終端輸入命令
pbcopy < ~.ssh/id_rsa.pub
而後粘貼到你登陸的github帳號上面Settings -->SSH keys -->Add SSH key 保存便可 Title 能夠隨便寫,Key粘貼剛複製內容,這樣SSH key 就添加到你的Github上了。
5、如何檢測SSH key
輸入命令:ssh git@github.com
此時會驗證SSH key是否有權限訪問 你的 github
成的顯示爲
Hi your_name!You've successfully authenticated,but Github does not provide shell access. connection to github.com closed.
- win如何找到SSH key連接以下
- https://blog.csdn.net/lsyz0021/article/details/52064829
當咱們使用github或者bitbucket等倉庫時咱們有可能須要ssh認證,因此須要生成他的ssh key。
一、首先你要安裝git工具
下載地址:https://git-scm.com/downloads
二、右鍵鼠標,選中 「Git Bash here」,固然你也能夠在windows的 「開始」--->「因此程序」,或者安裝目錄打開它
三、輸入指令,進入.ssh文件夾
cd ~/.ssh/
若是提示 「 No such file or directory」,你能夠手動的建立一個 .ssh文件夾便可
命令爲:
mkdir ~/.ssh
四、配置全局的name和email,這裏是的你github或者bitbucket的name和email
git config --global user.name "ganziwen"
git config --global user.email "2422156774@qq.com"
五、生成key
ssh-keygen -t rsa -C "2422156774@qq.com"
連續按三次回車,這裏設置的密碼就爲空了,而且建立了key。
Your identification has been saved in /User/Admin/.ssh/id_rsa. Your public key has been saved in /User/Admin/.ssh/id_rsa.pub. The key fingerprint is: ………………
最後獲得了兩個文件:id_rsa和id_rsa.pub
六、打開Admin目錄進入.ssh文件夾,用記事本打開id_rsa.pub,複製裏面的內容添加到你github或者bitbucket ssh設置裏便可
這是bitbucket的添加key,點擊右上方的頭像,選擇設置,而後
這是github添加key
七、測試是否添加成功
bitbucket輸入命令:
ssh -T git@bitbucket.org
提示:「You can use git or hg to connect to Bitbucket. Shell access is disabled.」 說明添加成功了
github輸入命令:
ssh git@github.com
提示:「Hi lsyz0021! You've successfully authenticated, but GitHub does not provide shel l access.」說明添加成功。
- 找到本身的SSH key以後保存下來
- 以上步驟完成後請看下面。
- 請打開你的pycharm—-> (Mac版本)Preferences|||(Win版本)settings—->Version Control —> Github
- 輸入你的GitHub帳號還有密碼,而後點擊Test,其餘的別管,最後記得點擊Apply,OK退出。