ssh-agent 和 crontab —— 有没有什么好办法让它们相遇? [英] ssh-agent and crontab -- is there a good way to get these to meet?

查看:24
本文介绍了ssh-agent 和 crontab —— 有没有什么好办法让它们相遇?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个简单的脚本,它每晚将 svn 活动日志邮寄给我们的开发人员.到现在为止,我都是在和svn仓库在同一台机器上运行的,所以不用担心认证问题,直接用svn的file:///地址样式即可.

I wrote a simple script which mails out svn activity logs nightly to our developers. Until now, I've run it on the same machine as the svn repository, so I didn't have to worry about authentication, I could just use svn's file:/// address style.

现在我在家用计算机上运行脚本,访问远程存储库,所以我不得不更改为 svn+ssh://路径.ssh-key 设置得很好,在正常情况下,我不需要输入密码来访问 svn 存储库.

Now I'm running the script on a home computer, accessing a remote repository, so I had to change to svn+ssh:// paths. With ssh-key nicely set up, I don't ever have to enter passwords for accessing the svn repository under normal circumstances.

但是,crontab 无法访问我的 ssh-keys/ssh-agent.我已经在网上的几个地方读到了这个问题,这里也提到了这个问题,但没有解决:

However, crontab did not have access to my ssh-keys / ssh-agent. I've read about this problem a few places on the web, and it's also alluded to here, without resolution:

为什么 ssh 失败来自 crontab 但从命令行执行时成功?

我的解决方案是将其添加到脚本的顶部:

My solution was to add this to the top of the script:

### TOTAL HACK TO MAKE SSH-KEYS WORK  ###
eval `ssh-agent -s`

这似乎在 MacOSX 10.6 下工作.

This seems to work under MacOSX 10.6.

我的问题是,这有多可怕,有没有更好的方法?

My question is, how terrible is this, and is there a better way?

推荐答案

当您运行 ssh-agent -s 时,它会启动一个后台进程,您稍后需要将其杀死.因此,最低限度是将您的 hack 更改为:

When you run ssh-agent -s, it launches a background process that you'll need to kill later. So, the minimum is to change your hack to something like:

eval `ssh-agent -s` 
svn stuff
kill $SSH_AGENT_PID

但是,我不明白这个 hack 是如何工作的.简单地运行代理而不运行 ssh-add 不会加载任何密钥.也许 MacOS 的 ssh-agent 的行为与其 手册页 说确实如此.

However, I don't understand how this hack is working. Simply running an agent without also running ssh-add will not load any keys. Perhaps MacOS' ssh-agent is behaving differently than its manual page says it does.

这篇关于ssh-agent 和 crontab —— 有没有什么好办法让它们相遇?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆