自動 SSH 手動運行但不在背景運行

自動 SSH 手動運行但不在背景運行

@reboot我正在cron上運行以下腳本root

autossh -f -i /home/pi/.ssh/myRemote.pem -R 2210:localhost:22 [email protected]

當我手動運行時,它工作正常,但從cron我看到它在日誌中顯示不斷失敗:

Nov 25 01:15:56 kirkins autossh[1936]: starting ssh (count 1)
Nov 25 01:15:56 kirkins autossh[1936]: ssh child pid is 1947
Nov 25 01:16:01 kirkins autossh[1936]: ssh exited prematurely with status 130; autossh exiting
Nov 25 01:16:40 kirkins autossh[605]: starting ssh (count 13)
Nov 25 01:16:40 kirkins autossh[605]: ssh child pid is 1949
Nov 25 01:16:40 kirkins autossh[605]: ssh exited with error status 255; restarting ssh
Nov 25 01:18:48 kirkins autossh[605]: starting ssh (count 14)
Nov 25 01:18:48 kirkins autossh[605]: ssh child pid is 1970
Nov 25 01:18:49 kirkins autossh[605]: ssh exited with error status 255; restarting ssh

有人知道出了什麼問題嗎?我在其他 StackExchange 網站上看到了一些相關帖子,但沒有一個解決方案適合我。

答案1

原因可能是ssh不喜歡它在沒有控制終端的情況下啟動這一事實(cron孩子們沒有控制終端)。

你可以試試ssh -tt。或在screen/內運行它tmux

相關內容