使用ssh-agent的好處: 如果有多台遠程服務器與多個私鑰文件,ssh-gent將會嘗試使用不同的私鑰文件建立連接,直至成功 假如有 A、B、C 三台服務器,A是控制節點,A可以直接登錄B,但是無法直接登錄C,只能先登錄B,再從B登錄C,這樣的話就需要在B中也保存私鑰。所以使用ssh-agent,開啟agent forwarding,就不用在B中保存私鑰,只在A中保存私鑰,在B、C 中保存公鑰,就可以在A上直接登錄 B、C。 1、啟動ssh-agent [root@bogon ~]# ssh-agent SSH_AUTH_SOCK=/tmp/ssh-yaEU82MG1ExI/agent.1316; export SSH_AUTH_SOCK; SSH_AGENT_PID=1317; export SSH_AGENT_PID; echo Agent pid 1317; 2、ssh-agent啟動bash [root@bogon ~]# ssh-agent bash --login -i 3、將私鑰添加到ssh-agent中 [root@bogon ~]# ssh-add /root/.ssh/id_rsa Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)