在 Debian 下使用 nohup 时日志报错,通常不是 nohup 本身的问题,而是命令、环境或输出方式导致的。下面按常见原因 → 现象 → 解决办法给你梳理一下。
nohup: failed to run command ‘xxx’: Permission denied
或
nohup: appending output to ‘nohup.out’: Permission denied
✅ 原因:
nohup.out 已存在但属主不是你✅ 解决:
# 指定可写日志
nohup your_command > /tmp/app.log 2>&1 &
# 或改目录
cd /tmp
nohup your_command &
nohup: failed to run command ‘python3.11’: No such file or directory
✅ 原因:
✅ 解决:
which python3
nohup /usr/bin/python3 app.py > app.log 2>&1 &
✅ 建议:nohup 一定要用绝对路径
nohup: failed to run command ‘./start.sh’: Permission denied
✅ 解决:
chmod +x start.sh
日志突然中断,或:
Killed
✅ 原因:
✅ 检查:
dmesg | grep -i oom
journalctl -xe
nohup: nohup.out: No such file or directory
✅ 原因:
nohup.out 被 rm✅ 解决:
nohup cmd > app.log 2>&1 &
nohup /绝对路径/命令 \
> /var/log/app.log 2>&1 &
✅ 优点:
[Service]
ExecStart=/opt/app/start.sh
Restart=always
tmux new -s app
如果你愿意,把具体报错原文贴出来,我可以直接帮你定位是哪一类问题。