git使用指定的ssh-key名
阿新 • • 發佈:2021-08-17
git ssh
-
以管理員身份執行powershell
-
使用你的github賬號郵箱生成一個ssh key
ssh-keygen -t ed25519 -C "[email protected]" -f "你想讓github ssh key存放的路徑"
-
檢視是否設定ssh-agent,如下圖情況則為ssh-agent未執行
ssh-add -l
-
執行ssh-agent
Set-Service ssh-agent -StartupType Automatic Start-Service ssh-agent Get-Service ssh-agent
-
將你的github ssh key新增到ssh agent
ssh-add "C:\Users\mayu3\.ssh\id_rsa-remote-ssh-github"
-
複製你的github ssh key的私鑰到剪貼簿
Get-Content C:\Users\mayu3\.ssh\id_rsa-remote-ssh-github.pub | Set-Clipboard
-
登入你的GitHub賬戶,新增ssh key的公鑰
-
點選New SSH key
-
填寫Title和Key
-
新增後的效果
-
編輯
~/.ssh/config
檔案新增以下內容Host github.com Hostname github.com IdentityFile ~/.ssh/id_rsa_custom IdentitiesOnly yes
-
新增remote
# notessh 是你為remote起的別名,隨便起 # [email protected]:sober-orange/mynote.git 是你的倉庫ssh連結 git remote add notessh [email protected]:sober-orange/mynote.git
-
提交程式碼
# 以下兩行命令等價 git push --set-upstream notessh main git push -u notessh main