SSH 和无人值守进程
我有一个 Ant 构建,有时会在我的服务器上的目录中执行“git Push”。我可以交互地完成此操作,因为它要求输入我的密钥的密码,但如果您设置一个 cron 作业来无人值守地运行构建,这就会出现问题。
除了不使用密码之外,我还有其他选择吗?我听说过使用 ssh-agent,但我也听说过对于无人值守的进程,该路由不起作用。有谁对此有任何建议,也许还有如何实施它的示例?
我看到有人建议在这里将 cron 作为守护进程运行: 通过 cron 运行的 bash 脚本访问 SSH 密钥工作 - 但我不确定如何做到这一点或输入我的密码而不通过将其以纯文本形式等方式妥协。
非常感谢任何帮助。
I have an Ant build that will sometimes execute a 'git push' within a directory on my server. I can do this fine interactively because it asks for the passphrase for my key, but this becomes problematic if you set up a cron job to run the build unattended.
Are there options for me beyond not using a passphrase? I've heard of using ssh-agent, but I've also heard for unattended processes that route won't work. Does anyone have any recommendations for this, and perhaps an example of how to implement it?
I saw that someone suggested to run the cron as a daemon here:
Accessing SSH key from bash script running via a cron job -- but I'm not sure how I could do that or put in my passphrase without compromising it by putting it in plain text, etc.
Any help greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,设置无密码登录。
使用 ssh-keygen 生成没有密码的公钥/私钥对。将公钥附加到服务器上的 ~/.ssh/authorized_keys 中。
然后运行 ssh -i /path/to/private_key server 以确认无密码登录正常工作。
最后,配置 git 使用
ssh -i ...< /代码>命令
。
正如 @mah 所建议的,您可能想在服务器上创建一个特定的 git 帐户。您将公钥添加到 ~git/.ssh/authorized_keys 以启用无密码登录。
authorized_keys 还具有限制传入连接可以运行哪些命令的选项。如果您对这些功能感兴趣,请阅读 SSH 文档。
当然,您希望保持私钥文件只有您自己可读。
First, set yourself up for password-less login.
Use
ssh-keygen
to generate a public/private key pair with no password. Append the public key to ~/.ssh/authorized_keys on the server.Then run
ssh -i /path/to/private_key server
to confirm that the password-less login is working.Finally, configure git to use that
ssh -i ...
command.As @mah suggests, you might want to create a specific
git
account on the server. You add the public key to ~git/.ssh/authorized_keys to enable the password-less login.authorized_keys also has options to restrict what commands the incoming connection can run. If you are interested in those features, read the SSH documentation.
And of course, you want to keep the private key file readable only by you.
我将通过在 git 服务器上创建一个受限帐户并让 ant 客户端对该受限帐户使用无密钥证书来解决此问题。
I would solve this by creating a restricted account on the git server and have the ant client use a keyless cert to that restricted account.