LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-13-2010, 10:42 PM   #1
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Rep: Reputation: 59
Deny Users from Executing Certain Commands


Hi,


How can we deny a user or all the users, of course other than the root, from executing certain commands such as:

Code:
nice <some-priority-value> <some-command> 

ls -R /
?

Do we need to enter some lines in /etc/sudoers
by issuing the command visudo?

I didn't find any hint in that file.


Any ideas?


Foolish Assumptions:

You are not going to express any ethics here.

You have understood what the objective is and are going to show how to achieve it.

I don't have time for restricting users from listing a directory contents or issuing nice. They are examples only.

Thanks!

Last edited by devUnix; 10-15-2010 at 11:30 PM. Reason: For the Sake of Readers' Better Understanding of the Question
 
Old 10-14-2010, 12:25 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Quote:
Originally Posted by devUnix View Post
Hi,


How can we deny a user or all the users, of course other than the root, from executing certain commands such as:

Code:
nice <some-priority-value> <some-command> 

ls -R /
?

Do we need to enter some lines in /etc/sudoers
by issuing the command visudo?

I didn't find any hint in that file.


Any ideas?
Hello,

Yes you can use sudoers (edited by using visudo by preference) to prohibit use of certain commands by users if your sudoers is setup correctly. From the man page for sudoers:
Quote:
An exclamation point ('!') can be used as a logical not operator both in an alias and in front of a Cmnd. This allows one to exclude certain values. Note, however, that using a ! in conjunction with the built-in ALL alias to allow a user to run "all but a few" commands rarely works as intended (see SECURITY NOTES below).
Hope that helps.

Kind regards,

Eric
 
Old 10-14-2010, 09:07 AM   #3
zhaozhou
LQ Newbie
 
Registered: Oct 2009
Location: Sweden
Distribution: Gentoo
Posts: 23

Rep: Reputation: 1
Do note that adding the rules to sudoers will still allow the user to run the command without 'sudo'.

You can change allowed nice values in /etc/security, and I don't think it's a very good idea to disallow the user to list files in /.
 
Old 10-15-2010, 09:19 AM   #4
A.Thyssen
Member
 
Registered: May 2006
Location: Brisbane, Australia
Distribution: linux
Posts: 158

Rep: Reputation: 44
Why would you want to limit 'nice'?

Non-root users can only make processes 'nicer' They can't make a command any less-nice. The same goes for the renice command to modify the priority of an existing process.
Remeber under unix you can do most things in MANY different ways. Limiting one command many not limit all such methods.

As for ls -R / Why do you want to limit that. Anything they should not be able to list should have appropriate restrictions already (like appropriate directory read, or access).

The point of the unix system, is that it already has appropriate restrictions against users that are detremental to the system.

sudo on the other hand is not ment to limit users, but give specific users access to specific commands they normall do not have access to, especially as specific users (like root) they normally can't run commands as. For example a command to load a specific kernel driver, or say an cryptfs file system, which ordinary users can not do.


If you are wanting to restrict users from NORMAL commands, doing so one command at a time would be useless. You would want to limit ALL commands and only open up specific ones. That is the function of the restricted shell!

And is the right way to limit users, like guest accounts.

The other way is only let them use a special interface, for example for uploading web files to ther account. In which case the user does not even get a 'shell' at all.

So the question comes down to.... What do you REALLY want? Rather than your how to do question...

Last edited by A.Thyssen; 10-15-2010 at 09:23 AM.
 
Old 10-15-2010, 11:09 PM   #5
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
Quote:
Originally Posted by EricTRA View Post
Hello,

Yes you can use sudoers (edited by using visudo by preference) to prohibit use of certain commands by users if your sudoers is setup correctly. From the man page for sudoers:


Hope that helps.

Kind regards,

Eric


Hi Eric!


Thanks for the hint!
 
Old 10-15-2010, 11:12 PM   #6
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
Quote:
Originally Posted by zhaozhou View Post
Do note that adding the rules to sudoers will still allow the user to run the command without 'sudo'.

You can change allowed nice values in /etc/security
Thanks for the note!


Quote:
I don't think it's a very good idea to disallow the user to list files in /.
Neither do I. That was only an example.
 
Old 10-15-2010, 11:25 PM   #7
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
Quote:
Originally Posted by A.Thyssen View Post
Why would you want to limit 'nice'?


As for ls -R / Why do you want to limit that. A


So the question comes down to.... What do you REALLY want? Rather than your how to do question...
Thanks for your time and energy you wasted upon writing all those stuffs. Please do read my question again. To save your time this time, read this note:

Before flying a real aircraft, the students are given artificial aircrafts to simulate flying. We do not need to ask them why they are crashing or saving their artificial aircrafts.

Restricting ls -R / or nice -19 someCommand is not my objective. They are examples. I am not going to restrict a thousand users from listing a directory contents or displaying their system date or whatever normal operations they perform on their UNIX / Linux System.

When we say touch fileName we do not mean that a learner is going to name the file "fileName" instead of using his/her own common sense. That is just an example!

Similarly when we say:

rm -f /*

we just want to say that all the files in the named partition would be gone!

But do we need to care about the ethics behind executing the command? Possibly one would know what that command does and how to use it for one's own purpose. That's it.
 
Old 10-16-2010, 05:08 PM   #8
zhaozhou
LQ Newbie
 
Registered: Oct 2009
Location: Sweden
Distribution: Gentoo
Posts: 23

Rep: Reputation: 1
Alright, if I'm reading this correctly, you want some sort of shell (or desktop, whatever) that a user can play around in without ruining your computer.

This is a rather tough question to answer, since you can't just restrict commands.

However, if I'm reading this correctly, I think you want a chroot jail. You'd be able to lock a user to a directory which includes 'his own little OS', where you decide what he can/cannot do (restricting commands is one of them), but also, if he actually ruins hes OS (rm -rf /), you'll be able to quickly and easily restore it.

You can also script it even further so that when the user logs off, the chroot is automatically restored to default.
 
1 members found this post helpful.
Old 10-16-2010, 08:14 PM   #9
ndarkduck
LQ Newbie
 
Registered: Nov 2008
Location: Mex,Mex
Distribution: Fedora || Red Hat Linux
Posts: 28

Rep: Reputation: 7
Think a little simpler

Ehm... sorry but... Why not just... using UNIX standart permissions? You know like
Code:
chmod o-x /bin/echo
on the commands you like ?
 
Old 10-17-2010, 03:56 PM   #10
zhaozhou
LQ Newbie
 
Registered: Oct 2009
Location: Sweden
Distribution: Gentoo
Posts: 23

Rep: Reputation: 1
Quote:
Originally Posted by ndarkduck View Post
Ehm... sorry but... Why not just... using UNIX standart permissions? You know like
Code:
chmod o-x /bin/echo
on the commands you like ?
It's not that easy. First of all, disallowing the user to run the command "echo" - for example, can break scripts which are completly valid. Second of all, a user could create a simple script or program which does the exact same thing as "echo", and be able to run it. And thirdly, you'd have to deny the user read writes as well, not just execute.

Code:
cp /bin/echo ~/echo
chmod +x echo
./echo
 
Old 10-19-2010, 01:11 PM   #11
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
Quote:
Originally Posted by ndarkduck View Post
Ehm... sorry but... Why not just... using UNIX standart permissions? You know like
Code:
chmod o-x /bin/echo
on the commands you like ?
That way I will need to keep a record of commands whose default permissions I have changed.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
How commands are executing ? gsiva Linux - Server 1 07-21-2009 08:48 AM
deny commands execution pthug Linux - General 1 09-18-2005 02:12 PM
executing shell commands in c++ true_atlantis Programming 2 10-01-2004 04:53 PM
Executing commands in Konsole... meteotrade Linux - General 5 10-20-2003 06:34 PM
Executing commands on startup viciousfish Linux - General 5 06-28-2002 02:15 PM

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

All times are GMT -5. The time now is 11:13 PM.

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