生成新 SSH 密鑰並添加到 ssh-agent


轉載自 Github 幫助文檔。

檢查現有 SSH 密鑰后,您可以生成新 SSH 密鑰以用於身份驗證,然后將其添加到 ssh-agent。

如果您還沒有 SSH 密鑰,則必須生成新 SSH 密鑰。 如果您不確定是否已有 SSH 密鑰,請檢查現有密鑰

如果不想在每次使用 SSH 密鑰時重新輸入密碼,您可以將密鑰添加到 SSH 代理,讓它管理您的 SSH 密鑰並記住您的密碼。

生成新 SSH 密鑰

  1. 打開終端。

  2. 粘貼下面的文本(替換為您的 GitHub 電子郵件地址)。

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

這將創建以所提供的電子郵件地址為標簽的新 SSH 密鑰。

> Generating public/private rsa key pair.
  1. 提示您“Enter a file in which to save the key(輸入要保存密鑰的文件)”時,按 Enter 鍵。 這將接受默認文件位置。

    > Enter a file in which to save the key (/home/you/.ssh/id_rsa): [Press enter]
    
  2. 在提示時輸入安全密碼。 更多信息請參閱“使用 SSH 密鑰密碼”

    > Enter passphrase (empty for no passphrase): [Type a passphrase]
    > Enter same passphrase again: [Type passphrase again]
    

將 SSH 密鑰添加到 ssh-agent

將新 SSH 密鑰添加到 ssh-agent 以管理密鑰之前,應檢查現有 SSH 密鑰生成新 SSH 密鑰

  1. 將 SSH 密鑰添加到 GitHub 帳戶

  2. 在后台啟動 ssh-agent。

    $ eval "$(ssh-agent -s)"
    > Agent pid 59566
    
  3. 將 SSH 私鑰添加到 ssh-agent。 如果您創建了不同名稱的密鑰,或者您要添加不同名稱的現有密鑰,請將命令中的 id_rsa 替換為您的私鑰文件的名稱。

    $ ssh-add ~/.ssh/id_rsa
    
  4. 將 SSH 密鑰添加到 GitHub 帳戶


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM