Why ssh fails from crontab but succedes when executed from a command line?

前端 未结 5 771
隐瞒了意图╮
隐瞒了意图╮ 2021-01-01 09:41

I have a bash script that does ssh to a remote machine and executes a command there, like:

ssh -nxv user@remotehost echo \"hello world\"

Wh

5条回答
  •  难免孤独
    2021-01-01 10:11

    I am guessing that normally when you ssh from your local machine to the machine running crond, your private key is loaded in ssh-agent and forwarded over the connection. So when you execute the command from the command line, it finds your private key in ssh-agent and uses it to log in to the remote machine.

    When crond executes the command, it does not have access to ssh-agent, so cannot use your private key.

    You will have to create a new private key for root on the machine running crond, and copy the public part of it to the appropriate authorized_keys file on the remote machine that you want crond to log in to.

提交回复
热议问题