- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: allow sudo for www user to run root shell scri...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2005 10:02 PM
07-22-2005 10:02 PM
howto allow sudo for www user to run root shell script:
I put in /usr/local/etc/sudores:
---------------------------------------------------
%www ALL=(ALL) NOPASSWD: ALL
www ALL=(root) ALL,!/bin/sh
---------------------------------------------------
but still get:
# sudo -u www sh /usr/local/www/cgi-bin/ntop/ntop.sh start
touch: /var/log/ntop.access.log: Permission denied
ntopbsd#
I know all security aspects, but I really need it.
kind regards
chris
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2005 10:58 PM
07-22-2005 10:58 PM
SolutionYour sudoers say:
Any user in the 'www' group can run any command without any password.
The user 'www' can run any command (except /bin/sh) as 'root' only.
So that's not going to work.
As the 'www' user, you just want to issue 'sudo /usr/local/www/cgi-bin/ntop/ntop.sh start'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2005 11:31 PM
07-22-2005 11:31 PM
Re: allow sudo for www user to run root shell script
but I cannot do:
# su www
This account is currently not available.
to try it.
I'd like to execute this root shell script via browser, using a perl script:
----------------------------------------------------------------------------------
#!/usr/bin/perl -w
use CGI::Carp qw(fatalsToBrowser);
use CGI;
my $query = new CGI;
# write the log
BEGIN
{
use CGI::Carp qw(carpout);
my $errorlog = "/var/tmp/errorlog.txt";
open(LOG, ">$errorlog") or die("Unable to open $errorlog: $!\n");
print LOG "Errors:\n";
carpout(*LOG);
}
print $query->header;
print "\n";
print "\n";
print "
print "\n";
print "\n";
print "\n";
print "
print "
print "
'sudo sh /usr/local/www/cgi-bin/ntop/ntop.sh stop' or die "cannot stop ntop: $!";
sleep(8);
$cc = 'sudo sh /usr/local/www/cgi-bin/ntop/ntop.sh start' or die "cannot start ntop: $!";
print "Status: ",$cc,"\n";
print "";
print "";
exit($cc);
----------------------------------------------------------------------------------
but it doesn't work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2005 11:36 PM
07-22-2005 11:36 PM
Re: allow sudo for www user to run root shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2005 11:41 PM
07-22-2005 11:41 PM
Re: allow sudo for www user to run root shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2005 11:43 PM
07-22-2005 11:43 PM
Re: allow sudo for www user to run root shell script
user: www
group: www
how can I check them to be sure ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2005 11:54 PM
07-22-2005 11:54 PM
Re: allow sudo for www user to run root shell script
%www ALL=(ALL) NOPASSWD: ALL
but still doesn't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2005 12:11 AM
07-23-2005 12:11 AM
Re: allow sudo for www user to run root shell script
What is your apache 'error_log' saying?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2005 01:15 AM
07-23-2005 01:15 AM
Re: allow sudo for www user to run root shell script
[Sat Jul 23 13:51:33 2005] [error] [client 192.168.0.105] Premature end of script headers: ntop4.cgi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2005 01:30 AM
07-23-2005 01:30 AM
Re: allow sudo for www user to run root shell script
I don't have any errors or entries in apache error log now, but still doesn't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2005 01:33 AM
07-23-2005 01:33 AM
Re: allow sudo for www user to run root shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2005 01:40 AM
07-23-2005 01:40 AM
Re: allow sudo for www user to run root shell script
--------------------------------------------------------------------
# perl ntop4.cgi
Content-Type: text/html; charset=ISO-8859-1
bsd#
--------------------------------------------------------------------
but ntop doesn't start
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2005 01:44 AM
07-23-2005 01:44 AM
Re: allow sudo for www user to run root shell script
If you look at your output, you can see the exact problem.
Around your sudo lines, you've got forward-single-quotes ('). You need back-tick's (`). Wrong character..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2005 02:00 AM
07-23-2005 02:00 AM
Re: allow sudo for www user to run root shell script
# sudoers file.
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.
#
# Host alias specification
# User alias specification
# Cmnd alias specification
# Defaults specification
# Runas alias specification
# User privilege specification
root ALL=(ALL) ALL
# Uncomment to allow people in group wheel to run all commands
# %wheel ALL=(ALL) ALL
# Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
# Samples
# %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
# %users localhost=/sbin/shutdown -h now
%www ALL=(ALL) NOPASSWD: ALL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2005 02:04 AM
07-23-2005 02:04 AM
Re: allow sudo for www user to run root shell script
'sudo sh /usr/local/www/cgi-bin/ntop/ntop.sh stop' or die "cannot stop ntop: $!";
sleep(8);
$cc = 'sudo sh /usr/local/www/cgi-bin/ntop/ntop.sh start' or die "cannot start ntop: $!";
These lines use the forward single quote ('). As you aren't using the system() call, it appears as if you want to subshell out, which means you should be using the back tick (`), not quote (').
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2005 02:13 AM
07-23-2005 02:13 AM
Re: allow sudo for www user to run root shell script
can you post pls the correct syntax ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2005 02:24 AM
07-23-2005 02:24 AM
Re: allow sudo for www user to run root shell script
'sudo sh /usr/local/www/cgi-bin/ntop/ntop.sh stop' or die "cannot stop ntop: $!";
sleep(8);
$cc = 'sudo sh /usr/local/www/cgi-bin/ntop/ntop.sh start' or die "cannot start ntop: $!";
You need to change them to either:
`sudo sh /usr/local/www/cgi-bin/ntop/ntop.sh stop` or die "cannot stop ntop: $!";
sleep(8);
$cc = `sudo sh /usr/local/www/cgi-bin/ntop/ntop.sh start` or die "cannot start ntop: $!";
or use some form of system() and less control over it's output...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2005 02:38 AM
07-23-2005 02:38 AM
Re: allow sudo for www user to run root shell script
I changed but now I get this error from the command line:
# perl ntop4.cgi
Content-Type: text/html; charset=ISO-8859-1
Software error:
cannot stop ntop: No such file or directory at ntop4.cgi line 32.
For help, please send mail to this site's webmaster, giving this error message
and the time and date of the error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2005 03:07 AM
07-23-2005 03:07 AM
Re: allow sudo for www user to run root shell script
/usr/local/www/cgi-bin/ntop/ntop.sh
If it is, then change it from:
sudo sh /usr/local/www/cgi-bin/ntop/ntop.sh
to just:
sudo /usr/local/www/cgi-bin/ntop/ntop.sh
ensuring that /usr/local/www/cgi-bin/ntop/ntop.sh is executable (chmod +x /usr/local/www/cgi-bin/ntop/ntop.sh).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2005 03:21 AM
07-23-2005 03:21 AM
Re: allow sudo for www user to run root shell script
# perl ntop4.cgi
Content-Type: text/html; charset=ISO-8859-1
Software error:
cannot stop ntop: No such file or directory at ntop4.cgi line 32.
For help, please send mail to this site's webmaster, giving this error message
and the time and date of the error.
I don't really understand the path is correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2005 03:26 AM
07-23-2005 03:26 AM
Re: allow sudo for www user to run root shell script
Ok, try fully-pathing 'sudo' too. During CGI execution, it's not uncommon to run in a reduced path environment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2005 04:43 AM
07-23-2005 04:43 AM
Re: allow sudo for www user to run root shell script
/usr/local/www/cgi-bin/ntop/
I never tried fully-pathing 'sudo'.
how it should work ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2005 12:07 PM
07-23-2005 12:07 PM
Re: allow sudo for www user to run root shell script
`sudo /usr/local/www/cgi-bin/ntop/ntop.sh start` .....
use:
`/usr/bin/sudo /usr/local/www/cgi-bin/ntop/ntop.sh start` ....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2005 12:15 PM
07-23-2005 12:15 PM
Re: allow sudo for www user to run root shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2005 12:25 PM
07-23-2005 12:25 PM
Re: allow sudo for www user to run root shell script
it needs following entry in sudoers
www bsd = NOPASSWD: /usr/local/www/cgi-bin/ntop/ntop.sh
and
this perl code does his job very well:
--------------------------------------------------------------------------------------------------------
system `/usr/local/www/cgi-bin/ntop/ntop.sh stop` or die "cannot stop ntop: $!";
sleep(8);
$cc = `sudo /usr/local/www/cgi-bin/ntop/ntop.sh start` or die "cannot start ntop: $!";
print "status: ",$cc,"\n";
--------------------------------------------------------------------------------------------------------
I can stop & start ntop via browser !
Now I'm going to take a cold beer.
greetings
chris