How to run a command without sudo?

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

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

Is there a way to run a command without using sudo and without asking for a password?

Thanks!

+6
linux shell
source share
5 answers

Put it in crontab root

 sudo crontab -e 

There you can put

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

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

+3
source share

Just add the command to the list of sudoer files using cmd visudo (this cmd requires root priviledge) as shown below:

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

Take care of ABSOLUTE-PATH-TO-CMD, it can become a security hole.

+2
source share

It is very dangerous to place applications in the root root if the box is not protected from hackers. If by chance someone replaces binary files (including libraries), you are gone!

The best thing would be to sow all the files that binary calls to an unprivileged user, and run the task as an unprivileged user.

Any of the binaries that the application uses must not be written by anyone other than root.

+1
source share

run it as root? or sphinx? try to figure out which user you need to be run and add cron to this user

0
source share

You can configure sudo to not ask for a password. Read the person you know how to do. Find the line NOPASSWD.

0
source share

All Articles