這兩天在使用Source Tree Terminalpush code時都會依值跳出要驗證SSH Key的錯誤,若沒有安裝ssh key就必須先設定好SSH Key才可以進行下一步,於是我到GitHub 教學上看怎麼設定ssh key,發現用source treeterminal來建ssh key然後轉成.ppk再設定到GitHub 上還挺容易的。

  Step 1. 打開Source Tree任一repositoryterminal,只要按下Source Tree 視窗上方的Terminal按鈕即可打開Unix Like終端介面。

 

  Step 2. 按照GitHub教學下指令建立ssh key: https://help.github.com/enterprise/2.11/user/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/ 參考指令。

$ ssh-keygen -t rsa -b 4096 -C your_email@example.com

Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):[Press enter]
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]

 

Passphrasesave key的部分我都直接按Enter採預設值。

 

接下來可以到C:\Users\terry_liu\.ssh 查看剛剛建的key: test_rsa | test_rsa.pub

 

  Step 3. Adding your SSH key to the ssh-agent via Source Tree Terminal.

# start the ssh-agent in the background
$ eval $(ssh-agent -s)
Agent pid 59566
 
$ ssh-add ~/.ssh/test_rsa
 

 

  Step 4. GitHub上自己的Account -> Settings -> SSH and GPG Keys 下新增SSH key

 

按下 New SSH Key :

 

 

輸入 Title(這把key用在與哪台機器溝通,故輸入電腦名稱,如:tw-terryX)

輸入 Key( test_rsa的內容),以下是新增key的結果:

 

 

基本上到這邊就可以透過SSH keySource TreeTerminal介面溝通了,以下是測試指令:

Step 5. Test Connection for your client with SSH key,

$ ssh -T git@hostname
# Attempts to ssh to GitHub Enterprise

 

這樣以後push code就可以直接透過SSH key驗證了。

201839日星期五

arrow
arrow

    jackterrylau 發表在 痞客邦 留言(0) 人氣()