1. 程式人生 > 其它 >git使用指定的ssh-key名

git使用指定的ssh-key名

git ssh

  1. 以管理員身份執行powershell

  2. 使用你的github賬號郵箱生成一個ssh key

    ssh-keygen -t ed25519 -C "[email protected]" -f "你想讓github ssh key存放的路徑"
    
  3. 檢視是否設定ssh-agent,如下圖情況則為ssh-agent未執行

    ssh-add -l
    
  4. 執行ssh-agent

     Set-Service ssh-agent -StartupType Automatic
     Start-Service ssh-agent
     Get-Service ssh-agent
    
  5. 將你的github ssh key新增到ssh agent

    ssh-add "C:\Users\mayu3\.ssh\id_rsa-remote-ssh-github"
    
  6. 複製你的github ssh key的私鑰到剪貼簿

    Get-Content C:\Users\mayu3\.ssh\id_rsa-remote-ssh-github.pub | Set-Clipboard
    
  7. 登入你的GitHub賬戶,新增ssh key的公鑰

  8. 點選New SSH key

  9. 填寫Title和Key

  10. 新增後的效果

  11. 編輯~/.ssh/config檔案新增以下內容

    Host github.com
        Hostname        github.com
        IdentityFile    ~/.ssh/id_rsa_custom
        IdentitiesOnly yes
    
  12. 新增remote

    # notessh 是你為remote起的別名,隨便起
    # [email protected]:sober-orange/mynote.git 是你的倉庫ssh連結
    git remote add notessh [email protected]:sober-orange/mynote.git
    
  13. 提交程式碼

    # 以下兩行命令等價
    git push --set-upstream notessh main
    git push -u notessh main
    

參考文獻

https://www.163.com/dy/article/GHCG1C5B0511DSSR.html