《ssh-agent管理ssh密鑰》要點:
本文介紹了ssh-agent管理ssh密鑰,希望對您有用。如果有疑問,可以聯系我們。
ssh-agent是ssh其中一個組件,可以用來管理密鑰和傳送證書.
ssh-agent的man原文
DESCRIPTION
ssh-agent is a program to hold private keys used for public key authenti-
cation (RSA, DSA, ECDSA). The idea is that ssh-agent is started in the
beginning of an X-session or a login session, and all other windows or
programs are started as clients to the ssh-agent program. Through use of
environment variables the agent can be located and automatically used for
authentication when logging in to other machines using ssh(1).
ssh-agent代理允許使用ssh登陸已經配置ssh信任關系的機器,并在這些已經配置同樣信任關系的機器間跳轉,而不需要再次鑒權.
例如: 在不設置ssh-agent的情況下 機器bbb,ccc和ddd上都已經配置了aaa機的公鑰
從aaa機器登陸bbb后,如果需要登陸ccc或者ddd機器 就必須是先退出bbb再重新登陸ccc或者ddd
root@aaa$ ssh bbb
root@bbb$ ssh ccc 如果從bbb上登陸ccc, 會因為沒有信任關系提示要求輸入密碼
root@ccc’s password:
這就是ssh-agent要解決的問題,通過所有服務器上存放私鑰副本,可以不需要暴露私鑰.
你所需要做的是在aaa上啟動ssh-agent代理,然后ssh-add添加默認的ssh密鑰.
root@aaa$ ssh-agent
SSH_AUTH_SOCK=/XXXXXXX/XXX/agent.401; export SSH_AUTH_SOCK;
SSH_AGENT_PID=402; export SSH_AGENT_PID;
root@aaa$ ssh-add
不過你還需要在bbb,ccc和ddd機器上配置ssh客戶端轉發代理請求,配置/etc/ssh/ssh_config(不同操作系統位置不大一樣)
ForwardAgent Yes
這樣當aaa登陸bbb,然后跳轉ccc的時候,bbb會要求ssh-agent提供有效證書,甚至再繼續跳轉倒ddd上,ccc會先和bbb協商轉發請求給aaa的ssh-agent.