Please enable Javascript to view the contents

github ssh設定

 ·   ·  ☕ 1 分鐘  ·  ✍️ JK

介紹

github使用SSH連線可以上傳Private(私人)儲存庫,暫時還不想開放給人觀看code或是公司專案非常適合使用SSH連線來上傳檔案,依照github官方文檔介紹設定。

推薦教學觀看頻道

github官方文檔

安裝需求

必須安裝:git git-scm.com

設定方法

開啟 Git Bash 程式

輸入 將email 改成 你的github的email

ssh-keygen -t rsa -b 4096 -C "[email protected]"

會看到此訊息

使用提供的電子郵件作為標籤,將建立一個新的ssh key。

> Generating public/private rsa key pair.

按下鍵盤的Enter

Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):[Press enter]

輸入y

/c/Users/you/.ssh/id_rsa already exists.
Overwrite (y/n)? y

輸入短密碼 方便記憶可與github密碼相同

Enter passphrase (empty for no passphrase):
Enter same passphrase again:

產生的key檔案路徑,依你的路徑為主,稍後需要id_rsa.pub檔案內的key複製到github

設定SSH KEY

選擇SSH and GPG keys.

選擇 New SSH key

使用記事本打開id_rsa.pub 將裡面的key複製到裡面,Title可隨便取

點選

確認,登入密碼

SSH key 加入到ssh-agent

eval $(ssh-agent -s)

SSH 私鑰添加到 ssh-agent

ssh-add ~/.ssh/id_rsa

確認是否連線成功

開啟 Git Bash 程式

ssh -T [email protected]

顯示 代表成功

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

push code 到 github

如果是建立全新的儲存庫,需要輸入 git init。

git init

// "." 代表上傳當前路徑的全部資料
git add .

git commit -m "first commit"

git remote add origin [email protected]:you/you.git

git push -u origin master

// 會要求輸入短密碼
Warning: Permanently added the RSA host key for IP address 'xx.xx.xx.x' to the list of known hosts.
Enter passphrase for key '/c/Users/you/.ssh/id_rsa':]

如果遇到問題或是想看更多詳細教學請到github官方文檔

https://help.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh

分享

JK
作者
JK
學習筆記