A-A+

宝塔面板使用 www 用户执行命令方法分享

2026年04月26日 软件开发 暂无评论

在使用宝塔面板的时候,可能会遇到因权限问题而无法执行命令的现象,例如,执行定时任务的时候,默认会以 root 用户来执行,可能会出现无法读取 www 组文件的情况。本文简单分享一下在宝塔面板中使用 www 用户执行命令的方法。

两种写法

使用 www 用户执行命令,提供以下两种写法:

方法一:使用 EOF 语法

使用 EOF 语法:

su -s /bin/bash - www <方法二:在双引号内编写命令

在双引号内编写命令(推荐):

su -c "

编写你的命令,支持换行

" -s /bin/sh www

举例

假设 shell 脚本如下:

  1. git init  
  2. git add *  
  3. git commit -m "Initial commit"  
  4. git remote add origin https://github.com/pieruo_com/examples.git  
  5. git pull origin master --allow-unrelated-histories  
  6. git push -u origin master  

使用 www 用户执行命令:

  1. su -c " 
  2. git init 
  3. git add * 
  4. git commit -m "Initial commit" 
  5. git remote add origin https://github.com/pieruo_com/examples.git 
  6. git pull origin master --allow-unrelated-histories 
  7. git push -u origin master 
  8. " -s /bin/sh www  

结束语

在使用宝塔面板的时候,如果遇到无法执行命令的问题,可改用 www 用户来执行,例如在使用宝塔面板删除 Chevereto V4 过期外部存储图片的时候,就需要使用 www 用户来执行定时任务。如果有任何意见或建议,欢迎在下方评论处留言。

标签:

给我留言