如何运行cron作业作为一个用户,而不是root用户 [英] How to run the cron job as a user instead of root user
问题描述
我有一个要添加到与指定计时cron作业数的bash脚本,但它需要以root用户执行。我试图运行这些脚本即crob工作,但它需要root用户权限,因为我运行在Ubuntu EC2实例这个职位,其中root用户受到限制。什么是工作围绕以root用户运行这些脚本。
I have few bash scripts which are adding to cron jobs with specified timing, but it needs to be executed as root user. I am trying to run those scripts i.e., crob jobs but it needs root user permission, since I am running this jobs in ubuntu ec2 instance where root user is restricted. What would be the work around to run those scripts as root user.
感谢
推荐答案
有几种可能性:
1)添加脚本(县)根的crontab中。要做到这一点,你必须做的 sudo的苏 -
或苏 -
成为root,然后使用添加cron作业 crontab -e命令
1) add the script(s) to the crontab of root. To do this you have to do sudo su -
or su -
to become root, then add the cron jobs by using crontab -e
2)允许非root用户使用一个crontab和cron作业添加到用户的crontab,使用 crontab -e命令
和设置你的脚本集的uid标志并改变所有权的根,所以它会以root身份执行搭配chmod + S脚本名称; CHOWN根脚本名称
2) allow a non-root user to use a crontab, and add the cron job to that user's crontab , by using crontab -e
and set the set-uid flag of your script and change ownership to root, so it will execute as root chmod +s scriptname; chown root scriptname
这篇关于如何运行cron作业作为一个用户,而不是root用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!