相关疑难解决方法(0)

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

我有一个bash脚本,它对远程机器执行ssh并在那里执行命令,如:

ssh -nxv user@remotehost echo "hello world"
Run Code Online (Sandbox Code Playgroud)

当我从命令行执行命令时它工作正常,但是当作为crontab的一部分执行时它失败(errorcode = 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.
...
Run Code Online (Sandbox Code Playgroud)

在本地执行时,我充当root用户,crontab也以root身份运行.从crontab和命令行执行'id'会得到完全相同的结果:

$ id
> uid=0(root) gid=0(root) groups=0(root),...
Run Code Online (Sandbox Code Playgroud)

我从一些本地机器ssh到运行crond的机器.我有ssh密钥和凭据ssh到crond机器和脚本连接到的任何其他机器.

PS.请不要问/抱怨/评论以root身份执行任何错误/错误/等等 - 这不是这个问题的目的.

unix ssh bash crontab

23
推荐指数
2
解决办法
3万
查看次数

标签 统计

bash ×1

crontab ×1

ssh ×1

unix ×1