日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

SSH管理多密钥

發布時間:2025/5/22 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SSH管理多密钥 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

生成密鑰對

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"# 默認情況下在~/.ssh目錄下生成id_rsa和id_rsa.pub兩個文件 # id_rsa是密鑰,id_rsa.pub是公鑰# 生成a密鑰對和b密鑰對,-f參數設置密鑰文件的文件名 ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -f ~/.ssh/a_id_rsa ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -f ~/.ssh/b_id_rsa

連接a機器用密鑰a,連接b機器用密鑰b

# 在~/.ssh目錄下編輯config文件 Host aHostName 192.158.5.201User rootPort 1234IdentityFile ~/.ssh/a_id_rsa Host bHostName 192.158.5.202User rootPort 1234IdentityFile ~/.ssh/b_id_rsa# 下面兩條命令就可以連上a,b兩臺機器 ssh a ssh b

訪問github用密鑰a,訪問gitee用密鑰b

# 在~/.ssh/config配置文件中添加如下配置 Host github.comIdentityFile ~/.ssh/a_id_rsa Host gitee.comIdentityFile ~/.ssh/b_id_rsa# 驗證, 如果失敗可用-vT參數查看失敗原因 git -T git@github.com git -T git@gitee.com

訪問多個github賬號

  • 設置不同Host對應同一個HostName但密鑰不同
  • 取消全局用戶名/郵箱設置,為每個倉庫獨立設置用戶名/郵箱
# 在~/.ssh/config配置文件中添加如下配置 Host account1.github.comHostName github.comIdentityFile ~/.ssh/a_id_rsa Host account2.github.comHostName github.comIdentityFile ~/.ssh/b_id_rsa

設置郵箱和用戶名

# 設置全局的 git config --global user.email "your_email@example.com" git config --global user.name "your_name"# 取消全局的 git config --global --unset user.email git config --global --unset user.name# 為每個庫設置單獨的 git config user.email "your_email@example.com" git config user.name "your_name"

scp的簡化

# 未配置ssh-config之前 scp -P 1234 root@xxx.xxx.xxx.xxx:/abc/def .# 配置ssh-config之后 scp a:/abc/def .

ssh-agent

ssh-agent bash命令解釋: ssh-agent是專為既令人愉快又安全的處理RSA和DSA密鑰而設計的特殊程序,不同于ssh,ssh-agent是個長時間持續運行的守護進程(daemon),設計它的唯一目的就是對解密的專用密鑰進行高速緩存。ssh包含的內建支持允許它同ssh-agent通信,允許ssh不必每次新連接時都提示您要密碼才能獲取解密的專用密鑰。對于ssh-agent,您只要使用ssh-add把專用密鑰添加到ssh-agent的高速緩存中。這是個一次性過程;用過ssh-add之后,ssh將從ssh-agent獲取您的專用密鑰,而不會提示要密碼短語來煩您了。 如果出現如下提示信息說明沒有SSH Key在代理中

補:遇到的一個錯誤,提示信息如下

/root/.ssh/config: line 5: Bad configuration option: identifyfile /root/.ssh/config: terminating, 1 bad configuration options# 原因是拼寫錯誤 # IdentifyFile --> IdentityFile

參考

  • Simplify Your Life With an SSH Config File
  • Linux下如何管理多個ssh密鑰

轉載于:https://www.cnblogs.com/okokabcd/p/9065534.html

總結

以上是生活随笔為你收集整理的SSH管理多密钥的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。