r2b2
r2b2

Reputation: 1275

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 can run the command without using sudo and without prompting for password ?

Thanks!

Upvotes: 6

Views: 8310

Answers (5)

schemacs
schemacs

Reputation: 2891

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.

Upvotes: 3

Marko Kevac
Marko Kevac

Reputation: 2982

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

Upvotes: 0

Nilesh
Nilesh

Reputation: 624

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.

Upvotes: 1

theHaunted
theHaunted

Reputation: 1

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

Upvotes: 0

JochenJung
JochenJung

Reputation: 7213

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.

Upvotes: 3

Related Questions