在 Debian 上用 nohup 跑程序时,日志文件的权限主要由创建日志的用户、umask、以及文件是否已存在决定。下面按常见场景说明怎么设。
典型用法:
nohup your_command > app.log 2>&1 &
app.log 由运行命令的用户创建umask 影响在启动前设置 umask:
umask 022
nohup your_command > app.log 2>&1 &
结果:
644(rw-r–r–)如果想让同组可写:
umask 002
→ 664
chmod 644 app.log
chown user:group app.log
touch app.log
chmod 640 app.log
chown appuser:appgroup app.log
nohup your_command >> app.log 2>&1 &
sudo -u appuser bash -c 'nohup your_command > /var/log/app.log 2>&1 &'
日志属主就是 appuser
写 systemd service:
[Service]
User=appuser
ExecStart=/path/to/your_command
StandardOutput=append:/var/log/app.log
StandardError=append:/var/log/app.log
然后:
sudo systemctl start yourapp
日志权限由 systemd 和目录权限决定
检查:
ls -l app.log
namei -l /path/to/app.log
✅ 生产环境:
/var/log/app/)✅ 临时测试:
umask + nohup如果你能说下:
我可以直接给你一条最合适的命令。