【发布时间】:2010-10-26 13:21:52
【问题描述】:
我有一个 bash 脚本,它对远程机器执行 ssh 并在那里执行命令,例如:
ssh -nxv user@remotehost echo "hello world"
当我从命令行执行命令时,它工作正常,但在作为 crontab 的一部分执行时失败(错误代码=255 - 无法建立 SSH 连接)。详情:
...
Waiting for server public key.
Received server public key and host key.
Host 'remotehost' is known and matches the XXX host key.
...
Remote: Your host key cannot be verified: unknown or invalid host key.
Server refused our host key.
Trying XXX authentication with key '...'
Server refused our key.
...
在本地执行时,我以 root 身份运行,crontab 也以 root 身份运行。 从 crontab 和命令行执行 'id' 得到完全相同的结果:
$ id
> uid=0(root) gid=0(root) groups=0(root),...
我从一些本地机器 ssh 到运行 crond 的机器。我有 ssh 密钥和凭据,可以 ssh 到 crond 机器和脚本连接到的任何其他机器。
PS。请不要问/抱怨/评论以 root 身份执行任何操作是错误的/错误的/等等 - 这不是这个问题的目的。
【问题讨论】:
-
尝试使用 -v 而不是 -q --- 它仍然不起作用,但它会为您提供可能帮助您解决问题的诊断。
-
谢谢戴夫! - 使用 -v 执行时,我在输出中包含了有趣的部分
-
由于事实/问题的改变,我删除了我的答案。