SSH-Agent 可以通过远程 bash 脚本工作吗?

SSH-Agent 可以通过远程 bash 脚本工作吗?

服务器 A 需要通过 svn+ssh 连接到服务器 B 以获取一些源文件以便在服务器 A 上部署。我的部署脚本通过以下方式从本地开发计算机运行:

ssh serverA 'bash -s' < deploy.sh 

我在服务器 A 和服务器 B 之间设置了无密码的公钥/私钥对。当我登录到服务器 A 的本地会话时,我进行了钥匙串设置,并且与服务器 B 的 svn+ssh 连接不是问题。部署.sh 脚本从本地会话在服务器 A 上成功运行。然而,当从我的开发盒通过 SSH 连接到它时,相同的脚本将无法远程运行。

当我在服务器 A 上远程运行命令时,如何从部署脚本中调用 ssh-agent 以使服务器 B 接受来自它的连接?

答案1

尝试使用-A选项来转发身份验证代理连接,如下所示:

ssh -A serverA 'bash -s' < deploy.sh

答案2

或者,更好的是,要么将其添加到您的系统中~/.ssh/config,以便影响用户发起的所有连接,要么在每个主机上使用它,要么将其添加到系统范围的 ssh 客户端配置中。这样,所有使用 ssh 的应用程序都将受益,并且您只需在一处维护配置。

另请参阅 ssh 手册页的摘录:

 -A      Enables forwarding of the authentication agent connection.  This can also be specified on a per-host basis in a configuration file.

         Agent forwarding should be enabled with caution.  Users with the ability to bypass file permissions on the remote host (for the agent's
         UNIX-domain socket) can access the local agent through the forwarded connection.  An attacker cannot obtain key material from the agent,
         however they can perform operations on the keys that enable them to authenticate using the identities loaded into the agent.

相关内容