您现在的位置是:网站首页> 编程资料编程资料
在linux shell脚本中root切换到普通用户执行脚本或命令的方法_linux shell_
2023-05-26
301人已围观
简介 在linux shell脚本中root切换到普通用户执行脚本或命令的方法_linux shell_
需求:
安装deb包,设置程序安装后启动,不需要root权限启动程序 | 不能用root权限启动
其他开机启动选项
方法:root临时降低权限
secUser=`who am i | awk '{print $1}'` #echo $secUser su $secUser -c <指令> > /dev/null 2>&1 & #这一条命令的执行权限是临时的,只在本条语句起作用 id -u # 结果为0,还是root用户权限 附: su --help
-c, --command COMMAND pass COMMAND to the invoked shell -h, --help display this help message and exit -, -l, --login make the shell a login shell -m, -p, --preserve-environment do not reset environment variables, and keep the same shell -s, --shell SHELL use SHELL instead of the default in passwd
以上这篇在linux shell脚本中root切换到普通用户执行脚本或命令的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
您可能感兴趣的文章:
相关内容
- 在任意目录下使用某个shell脚本的方法_linux shell_
- Linux shell 实现用for循环100次的方法_linux shell_
- Linux中shell脚本获取当前工作目录的方法_linux shell_
- 基于shell脚本中cd命令无效的解决方法_linux shell_
- 通过shell脚本循环进入目录执行命令的方法_linux shell_
- shell递归输出文件名和目录名的方法_linux shell_
- 利用shell脚本遍历文件夹内所有的文件并作整理统计的方法_linux shell_
- 十三个写好shell脚本的技巧分享_linux shell_
- shell获取目录下所有文件夹的名称并输出的实例_linux shell_
- Linux Shell获取文件夹下的文件名方法_linux shell_
