LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 02-02-2009, 02:36 AM   #1
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
Imposing quotes/escapes on command allowed by sudo


Hi,

I want to allow a user to be able to execute one of the following commands:

Code:
sudo grep -i connect\ time /var/log/messages
sudo grep -i "connect time" /var/log/messages
but not the command

Code:
sudo grep -i connect time /var/log/messages
I have tried the following lines in /etc/sudoers:

Code:
somebody        ALL=NOPASSWD: /bin/grep -i connect\ time /var/log/messages
somebody        ALL=NOPASSWD: /bin/grep -i connect\\\ time /var/log/messages
somebody        ALL=NOPASSWD: /bin/grep -i "connect time" /var/log/messages
somebody        ALL=NOPASSWD: /bin/grep -i \"connect time\" /var/log/messages
somebody        ALL=NOPASSWD: /bin/grep -i \\\"connect time\\\" /var/log/messages
Each of those either permits the command I don't want to permit or is rejected by visudo as invalid.

Any suggestions?

Thanks in advance.
 
Old 02-02-2009, 07:08 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
Offhand I can't think of a way to do that. But you could create a script that only root can run containing the command you want to allow (without sudo) and add that script to /etc/sudoers.
 
Old 02-04-2009, 03:29 AM   #3
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Original Poster
Rep: Reputation: 61
OK. Thanks for the response.
 
Old 02-04-2009, 05:56 AM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 680Reputation: 680Reputation: 680Reputation: 680Reputation: 680Reputation: 680
Sorry, retesting my answer it didn't work. One thing you could try is replacing the space with a dot which would match. The user would have to enter the dot in the command as well however.

Last edited by jschiwal; 02-04-2009 at 06:21 AM.
 
Old 02-05-2009, 01:29 AM   #5
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Original Poster
Rep: Reputation: 61
Quote:
Originally Posted by jschiwal View Post
One thing you could try is replacing the space with a dot which would match. The user would have to enter the dot in the command as well however.
Yeah. That works. Thanks.
 
Old 06-29-2016, 09:52 AM   #6
ymicromed
LQ Newbie
 
Registered: Nov 2012
Location: Vienna
Distribution: Debian, OpenSUSE, RedHat, Fedora, Ubuntu, Solaris
Posts: 2

Rep: Reputation: Disabled
Smile

Hello,

You can create script1 with commands and arguments with quotes like:

/usr/sbin/asterisk -rx "sip show peers"

Allow the user to run this script by adding him to sudoers "visudo"

user ALL= NOPASSWD: /path/script1

Create script2 and put inside it

#!/bin/bash
sudo /path/script1

Run the script2 normally without sudo.
./script2
use script2 to be called by other services.

I have tested this solution.

I hope this will help.

Last edited by ymicromed; 06-29-2016 at 09:53 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script: how to insert a command into quotes alekone Linux - General 4 01-12-2009 08:56 AM
Can a sudo user be allowed use relative path yksudha Linux - Security 1 06-11-2008 01:02 AM
sudo: "user not allowed to execute" jjonas Linux - Security 6 07-05-2007 05:46 AM
Using single quotes vs double quotes in PHP strings vharishankar Programming 6 07-11-2005 11:41 AM
Quotes in command line expression afshin Programming 4 02-24-2003 07:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 06:47 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