# Git SSH Key操作 ### 前言 為何GIT 需要 SSH Key呢? 為了要讓Github 認得這台電腦就是此帳號的User,因此我們會透過設定SSH 的Public Key 當認證的憑證。 --- ### 說明 HTTPS 跟 SSH 差異 HTTPS : 在操作時需要輸入帳密。 SSH : 已先在電腦內設定好金鑰,操作時不需要輸入帳密。 --- # Git 操作 ### 建立SSH Key Goole搜尋:github key-gen 網址:https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent #### 步驟1 ●至本機電腦>使用者>使用者名稱>建立.ssh資料夾(或是在C槽) #### 步驟2 ●在.ssh資料夾建立config檔 ※空格空4格,不要用Tab鍵。 ```config= Host GitHub.com HostName GitHub.com User git IdentityFile ~/.ssh/id_ed25519_{單位}_{User名稱} ``` #### 步驟3 對資料夾路徑輸入cmd開啟命令字元視窗 ※你的Git Email 輸入語法: ```git= ssh-keygen -t ed25519 -C "your_email@example.com" ``` #### 步驟4 cmd命字元視窗會顯示 產出的SSH金鑰您要存放的位置(請輸入本機電腦>使用者>使用者名稱>.ssh資料夾>User) #### 步驟5 cmd命字元視窗會顯示 請輸入密碼(請直接空白,按下Enter) #### 步驟6 cmd命字元視窗會顯示 請輸入確認密碼(請直接空白,按下Enter) #### 步驟7 最後會產生兩個檔 #### 步驟8 將檔案用Notepad++ 或 可閱覽程式碼的應用程式打開,複製附檔名為pub的金鑰,貼至GIT的SSH設定 路徑:Settings > SSH and GPG keys > New SSH key #### 總結 以上步驟完成後,即設定好了該台電腦跟Git Hub的SSH Key綁定認證。 --- # Sourcetree設定 ### 加入SSH Key #### 步驟1 路徑:Sourcetree IDE的工作列 > Tools > Create or Import SSH Keys  #### 步驟2 把原本.ssh資料夾的檔案 Load上來後按下Save private key,就會產另一個私鑰檔案在.ssh資料夾內。  #### 步驟3 路徑:Sourcetree IDE的工作列 > Tools > Options 「SSH Client Configuration」欄位區內選擇載入所儲存的 PuTTY 格式的私鑰檔案。  #### 總結 以上步驟完成後,即設定好了該台電腦的Sourcetree IDE跟Git Hub的SSH Key綁定認證。 ---- > 歡迎隨意引用或拷貝,若有涉及侵權概不負責。
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up