Linux - General This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
10-08-2005, 11:48 AM
|
#1
|
Member
Registered: Nov 2004
Location: France & Germany
Distribution: (Pure) Debian Etch & Sid
Posts: 116
Rep:
|
[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
++
Last edited by kloss; 10-09-2005 at 03:16 PM.
|
|
|
10-08-2005, 12:27 PM
|
#2
|
Member
Registered: Nov 2004
Location: BIOS
Distribution: RHEL3.0, FreeBSD 5.x, Debian 3.x, Soaris x86 v10
Posts: 379
Rep:
|
Try as follows:
Code:
boss localhost= NOPASSWD:/home/boss/it/connect_vpn.sh
Hope this helps.
|
|
|
10-08-2005, 12:38 PM
|
#3
|
Member
Registered: Nov 2004
Location: France & Germany
Distribution: (Pure) Debian Etch & Sid
Posts: 116
Original Poster
Rep:
|
Unfortunately, it doesn't.
Thanks
|
|
|
10-08-2005, 02:57 PM
|
#4
|
Senior Member
Registered: Aug 2005
Posts: 1,755
Rep:
|
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.
|
|
|
10-08-2005, 03:33 PM
|
#5
|
Member
Registered: Nov 2004
Location: France & Germany
Distribution: (Pure) Debian Etch & Sid
Posts: 116
Original Poster
Rep:
|
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.
++
|
|
|
10-09-2005, 12:37 PM
|
#6
|
Member
Registered: Jul 2005
Location: France
Distribution: Arch Linux
Posts: 540
Rep: 
|
In the /etc/sudoers file enter the individual commands of the script instead of the name of the script :
Code:
boss ALL=NOPASSWD: /etc/init.d/vpnclient_init start, vpnclient connect inside user foo pwd bar
because it is these individual commands that are sudoed not the entire script
Hope this will resolve the problem.
Regards.
Last edited by berbae; 10-09-2005 at 12:38 PM.
|
|
|
10-09-2005, 03:15 PM
|
#7
|
Member
Registered: Nov 2004
Location: France & Germany
Distribution: (Pure) Debian Etch & Sid
Posts: 116
Original Poster
Rep:
|
Yes it works ! Thanks, you rock.
(To be exact, I had to add the full path of the file "vpnclient".)
Btw, visudo is really unconvenient - gedit did the job.
++
|
|
|
10-10-2005, 07:24 AM
|
#8
|
LQ Veteran
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
|
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.
|
|
|
10-10-2005, 11:39 AM
|
#9
|
Member
Registered: Nov 2004
Location: France & Germany
Distribution: (Pure) Debian Etch & Sid
Posts: 116
Original Poster
Rep:
|
OK, Thanks for the tip.
++
|
|
|
All times are GMT -5. The time now is 03:18 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|