LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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


Reply
  Search this Thread
Old 10-22-2012, 10:22 PM   #1
limgrace
LQ Newbie
 
Registered: Jan 2006
Posts: 7

Rep: Reputation: 0
sudo ask for password if run using script


hi,
i need certain user (example:jerry) to be able to execute chmod as root.
edit/etc/sudoers by adding the line at end of the file

jerry ALL= NOPASSWD: /bin/chmod a+w /dev/st0

login as jerry , execute sudo /bin/chmod a+w /dev/st0 from command line
successfully executed

created a script tesh.sh in jerry acct
#!/bin/bash
sudo /bin/chmod a+w /dev/st0

run the script ./tesh.sh at command line, it prompted for password
after entering passowrd, error prompted
sorry, user jerry is not allowed to execute '/bin/chmod a+w /dev/st0' as root on server1.

problem:
1.it ask for password
2. when password was entered , it prompted that user cannot execute command as root on server1

pls help.
 
Old 10-22-2012, 10:42 PM   #2
mark_alfred
Senior Member
 
Registered: Jul 2003
Location: Toronto, Ontario, Canada
Distribution: Ubuntu Linux 16.04, Debian 10, LineageOS 14.1
Posts: 1,572

Rep: Reputation: 210Reputation: 210Reputation: 210
You may need to use visudo to edit the sudoers file. Beyond that suggestion, I really don't know how you can solve this issue.
 
Old 10-22-2012, 10:45 PM   #3
mdlinuxwolf
Member
 
Registered: Dec 2006
Distribution: Mepis and Fedora, also Mandrake and SuSE PC-BSD Mint Solaris 11 express
Posts: 385

Rep: Reputation: 42
I don't think users without passwords on their accounts can use sudo.

Try just doing:

su
Myrootpassword

If root is disabled like in Mint or Ubuntu try:

sudo su
Myuserpassword

In both cases, you'll have a genuine root prompt.

Give that user a strong password!!
 
Old 10-22-2012, 11:01 PM   #4
limgrace
LQ Newbie
 
Registered: Jan 2006
Posts: 7

Original Poster
Rep: Reputation: 0
tried using visudo. delete the old line and reenter it again.

jerry ALL= NOPASSWD: /bin/chmod a+w /dev/st0

problem still them same.

but if i changed it to jerry ALL=(ALL) NOPASSWD: ALL
it works.


what do i missed out? is there a problem w/ the stmt jerry ALL= NOPASSWD: /bin/chmod a+w /dev/st0 ?
im using redhat6 es
 
Old 10-23-2012, 12:09 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
It would be interesting to know exactly which distro+version this is.
The basic syntax is
Code:
use machine=(runas) NOPASSWD: cmds
http://linux.die.net/man/5/sudoers

It possible your distro has decided to tighten up security by requiring a runas value...
I would definitely have a close read of the man pages on your system.
 
Old 10-23-2012, 08:49 AM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by limgrace View Post
tried using visudo. delete the old line and reenter it again.

Code:
jerry ALL= NOPASSWD: /bin/chmod a+w /dev/st0
I believe jerry will have to be a member of whaterver group
Code:
ls -ld /dev/st0
is designated AND this should be
Code:
jerry ALL= NOPASSWD: /bin/chmod
AFAICT...

any else see that?

Have a Great Day!
 
Old 10-23-2012, 08:55 PM   #7
limgrace
LQ Newbie
 
Registered: Jan 2006
Posts: 7

Original Poster
Rep: Reputation: 0
its redhat linux ent server 6.2 santiago
 
Old 10-23-2012, 09:26 PM   #8
limgrace
LQ Newbie
 
Registered: Jan 2006
Posts: 7

Original Poster
Rep: Reputation: 0
if i used the code
jerry ALL= NOPASSWD: /bin/chmod

it works.
 
Old 10-23-2012, 09:49 PM   #9
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by limgrace View Post
if i used the code
jerry ALL= NOPASSWD: /bin/chmod

it works.
That does give user "jerry" the ability to run /bin/chmod with any arguments whatsoever and change the permissions on any file or directory in the system, which is probably way more capability than you intended.
 
Old 10-24-2012, 12:07 AM   #10
limgrace
LQ Newbie
 
Registered: Jan 2006
Posts: 7

Original Poster
Rep: Reputation: 0
this the result of ls -ld /dev/st0
crw-rw-r- 1 root tape 9, 0 Oct 15 12:33 /dev/st0

but if i add a+w /dev/st0 , it doesnt work. how do i go abt it?
 
Old 10-24-2012, 07:26 AM   #11
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
I really don't know why that isn't working for you, as that same syntax works fine for me:
Code:
rnichols ALL = NOPASSWD: /bin/chmod a+w /tmp/tfile
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Sudo problem - Run all commands with password except these uncle-c Linux - Newbie 1 02-16-2010 11:02 AM
How do I use sudo in a script without asking for password? Usalabs Linux - General 1 08-28-2008 01:59 PM
Shell script sudo without password prompt under Darwin? lhouk Other *NIX 3 02-08-2008 11:16 AM
sudo problem. Want permission to run a sbin program without a password inverted.gravity Linux - Software 11 03-21-2007 03:34 PM
Running a script as root with sudo without entering the user password kloss Linux - General 8 10-10-2005 11:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration