开发者

How to run a command without sudo?

I want to add a line in the crontab (on my local machine) which will run every five minutes. My problem is the command I am going to use requires sudo :

sudo indexer --config /usr/local/etc/sphinx.conf --all --rotate

Is there a way I ca开发者_Go百科n run the command without using sudo and without prompting for password ?

Thanks!


Put it in the crontab of root

sudo crontab -e

There you can put

indexer --config /usr/local/etc/sphinx.conf --all --rotate

All commands in this crontab will be executed as root. If you just du crontab -e as your current user, they will be executed under your users permissions.


Just append your command to the sudoer file list by using cmd visudo(this cmd requires root priviledge) as below:

<YOUR_USER_NAME> ALL = NOPASSWD:<ABSOLUTE-PATH-TO-CMD>

Take care of the ABSOLUTE-PATH-TO-CMD,It may become a security hole.


Its extremely dangerous to put applications in root's crontab unless the box is secured well from hackers. If by chance someone replaces the binaries (including libraries), you're gone!

A better way would be to chown all the files the binary accesses to an unprivileged user and run the job as the unprivileged user.

Any of the binary files the application uses should not be writeable by anyone except root.


run it as a root ? or sphinx user ? try to find out which user you need it to be run as and add it to that users cron


You can configure sudo not to ask password. Read man sudoers for how to do that. Search for NOPASSWD string.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜