原文链接
lucky定时获取证书,并自动替换fnos证书 - 攻略分享 飞牛私有云论坛 fnOS
想必大家安装应用商店中的lucky都遇到了lucky执行
自动替换证书的错误

我也同样遇到了,经过多次实验无法执行

这段指令,否则提示log
sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper sudo: a password is required
询问Copilot后得知
当脚本被 Lucky(或 crontab、systemd 等)以非交互方式触发时,没有关联的终端(TTY),sudo
无法弹出密码输入提示,就会报出:
sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper sudo: a password is required
核心原因在于:
- 系统默认要求在交互式终端下才能输入 sudo 密码(requiretty)。
- 非交互脚本又没有提供密码来源,导致 sudo 执行失败。
解决方案如下:
首先ssh进入终端后输入
sudo -i
提权至ROOT用户需要保留

这一步的代码,保存后输入 ‘crontab -e' 打开root用户下的定时任务列表
#删除括号内(包括括号)的所有内容替换成自己的脚本路径和log保存路径
#每月15日12时0分自动以ROOT权限执行lucky无法执行自动更新证书的脚本
0 12 15 * * (/opt/scripts/monthly_backup.sh >> /var/log/backup.log 2>&1)
实测过后可以正常执行更新脚本每月自动执行一次,如需要测试请自行修改Cron表达式到就近的时间
如需其他时间自动更新证书也请自行修改Cron表达式