我有一个bash脚本,用于执行ssh到远程机器,并在那里执行一个命令,如:
- ssh -nxv user@remotehost echo "hello world"
当我从命令行执行命令它工作正常,但是作为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.
- ...
在本地执行时,我作为一个根,crontab也以root身份工作.
从crontab和命令行执行’id’提供完全相同的结果:
- $id
- > uid=0(root) gid=0(root) groups=0(root),...
我从一些本地机器到运行crond的机器上执行ssh.我有ssh密钥和凭据到ssh,以克隆机器和脚本连接到的任何其他机器.