Running a script as root with sudo without entering the user password
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
[solved] Running a script as root with sudo without entering the user password
Hi
I have a script to start a VPN client. I want a normal user ("boss") to be able to run the script without entering any password. I try to play with NOPASSWD in /etc/sudoers, but it doesn't work. When "boss" runs the scripts, he always has to enter his password.
Here is the script (home/boss/it/connect_vpn.sh) :
Code:
sudo /etc/init.d/vpnclient_init start
sudo vpnclient connect inside user foo pwd bar
Here is /etc/sudoers :
Code:
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
boss ALL=NOPASSWD:/home/boss/it/connect_vpn.sh
Here is the output of "uname -a" and "id" for "boss":
Code:
Linux ubuntu 2.6.10-5-386 #1 Fri Sep 23 14:13:55 UTC 2005 i686 GNU/Linux
uid=1000(boss) gid=1000(boss) groups=4(adm),20(dialout),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),107(lpadmin),108(scanner),109(admin),1000(boss)
Thanks a lot for your help, i'm looking for a solution for a while without success
How about a different approach: make the file owned by root, and then turn on the setuid bit on the permissions, and give everyone executable permission.
Well, I can be wrong, but I think this approach works well with binaries but not with shell scripts. What annoys me is that I'm sure there is a simple trick to do that.
++
While you can edit sudoers without using visudo, it really isn't that good an idea. The main reason is that visudo checks the syntax of the sudoers file when you quit and alerts you to any borked entries.
That said, I completely agree that vi is quite possibly the worst text editor ever. However, there is a way to use a different text editor within visudo, provided visudo was compiled with the right options.
Before starting visudo, enter the following line:
export EDITOR=pico (or nano or joe or whatever your favorite console text editor is).
If visudo was compiled right, it checks the $EDITOR environment variable and uses that editor and will default to vi if $EDITOR is not set.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.