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但密鑰不同
- 取消全局用戶名/郵箱設置,為每個倉庫獨立設置用戶名/郵箱
設置郵箱和用戶名
# 設置全局的 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
總結
- 上一篇: Codeforces 补题记录
- 下一篇: 软件架构设计——解释器模式