Deny to edit a specific file in sudoers


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Deny to edit a specific file in sudoers
# 1  
Old 01-30-2013
Deny to edit a specific file in sudoers

How do I deny a user to edit a specific file in directory but the user will have a capability to use sudo and execute any command? I will just deny him/her to edit sayy 5files in different directories in linux?

example. He cannot edit /etc/modprobe.d/blacklist.conf and /etc/sshd.config? Then the rest he can use sudo command.

thanks
# 2  
Old 01-30-2013
You shouldn't allow to edit any file at all via sudo. This is what group ownerships are meant for: instead of doing it via sudo you make the file owned by a certain group, grant the group the write-privilege and make any user allowed to edit the file a member of this group.

Code:
# ls -l /file/in/question
-rw-rw---- 1 root mayedit 11872 2013-01-29 18:34 /file/in/question

# groups willedit
willedit : users mayedit

# groups willnotedit
willnotedit : users

Now you add any user who should be able to edit the file to the "willedit" group and all others are left out.

The reason why you shouldn't do that via sudo is because most editors allow shell escapes and this is one of the classical ways to circumvent restrictions via sudo: to allow sudo vi /some/file for instance means that the user is allowed to set up the process vi /some/file as root. Issuing ":!sh" in this vi session now escapes to a normal shell in which the user is now fully root. You don't need any sudo restrictions in place in this case any more.

I hope this helps.

bakunin
# 3  
Old 01-30-2013
If you do need to give sudo vi access, you can use rvim, which will not allow shell commands to be called via ! within vi.
# 4  
Old 01-30-2013
thanks. however if the 'mayedit' user will execute sudo vi /file/in/question, he will be able to edit it right? the user will have like sudo access to all (ie. shutdown, cp, mv, any commands) but not to a specific files i will mention. is this possible?
# 5  
Old 01-30-2013
Quote:
Originally Posted by lhareigh890
thanks. however if the 'mayedit' user will execute sudo vi /file/in/question, he will be able to edit it right? the user will have like sudo access to all (ie. shutdown, cp, mv, any commands) but not to a specific files i will mention. is this possible?
Ahem,

"mayedit" is not a user, but a user group. Users are "willedit" and "willnotedit".

By giving a user the right to "sudo vi" this user will effectively be able to become root and use any command - shutdown, mv, cp and anything else included - without even having to use "sudo".

And, no, this is not possible. root may do everything and if you allow a user to become root, you have allowed him to do everything effectively. There is no restricting after you have given full rights. This is why you shouldn't use sudo for this, as explained above.

I hope this helps.

bakunin
# 6  
Old 01-31-2013
thanks..is there an application or a way on how to do this? because i want our sysads to say apt-get install, shutdown, mv, cp etc but will restrict their access to the ff for example
a. /etc/modprobe.d/blacklist.conf--- its bec i will disable usb/video module

in this way they will not be able to edit this file but they can edit all files, cp, mv, rm etc since they are sysad and they will be sudoers.
# 7  
Old 02-01-2013
The short answer is no. This is because of your proposed security model, i.e. allow the editing of all files except for a small number of files. This is sometimes known as a "mostly open" security model. A better approach in this case is to use a "mostly closed" model, i.e. deny permission to edit all files except for a small number of files.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Sudoers file

In the sudoers file in Solaris... I am trying to limit the DEVELOPER user privileges to where those users can only use the “rm” command in certain directories. This is to prevent them from deleting directories or files and destroying a server. I want them to be able to use the "rm" command but... (1 Reply)
Discussion started by: nzonefx
1 Replies

2. UNIX for Dummies Questions & Answers

Help with Sudoers file

Hi using Solaris 10. trying to update /etc/sudoers file I need to add all the fist level operation team. This is what I have but it doesn't seem to work. Please help.Error message sudo su - >>> sudoers file: parse error, line 9 <<< >>> sudoers file: parse error, line 9 <<< ... (2 Replies)
Discussion started by: samnyc
2 Replies

3. HP-UX

Unable to edit the sudoers file using script

Hi All, I've made a script in order to delete the users. The script is deleting the users and removing its entry from the /etc/sudoers however it is changing the permissions of the /etc/sudoers file to the user from which it is executing the script. #!/bin/ksh #set -x print "The script... (2 Replies)
Discussion started by: Kits
2 Replies

4. Shell Programming and Scripting

Edit file content at the specific line.

How to edit file content at the specific line? For example at below The things to edit --> This is line 2. And it is below line 1. This is line 1. This is line 2. # i want to append some words at this row line. How? This is line 3. (8 Replies)
Discussion started by: alvin0618
8 Replies

5. Shell Programming and Scripting

How to edit specific variable in file?

HI guys i have a question. Question 1: how do i modify a particular string? e.g echo "Please enter Book Title: " read a echo "Please enter Author: " read b if ] then echo " Record found!" which will then pop out a menu with the follow output 1. Update Name 2.... (1 Reply)
Discussion started by: ichar
1 Replies

6. UNIX for Advanced & Expert Users

sudoers file

i have defined a rule in the sudoers file so a specific user is able to run some commands as sudo with no password. my question is: is it possible to restrict a user to run commands as sudo only in a certain directory? for example: chown only the files that are located in /var/tmp. Thank you. ... (2 Replies)
Discussion started by: noam128
2 Replies

7. AIX

Does ACL can only grant/deny access for specific command?

Dear AIX/UNIX experts: I have a demand to restricted a file to be copy by others, but this file must can be read by others/Applications. As I tried, the chmod command cannot fulfill this requirement. But not sure if the ACL can achieve this function or not ? Could anybody give me your... (8 Replies)
Discussion started by: devyfong
8 Replies

8. UNIX for Dummies Questions & Answers

sudoers file questions

What is the difference between ALL and localhost in the bellow? # %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom # %users localhost=/sbin/shutdown -h now Thank you. (2 Replies)
Discussion started by: hemangjani
2 Replies

9. UNIX for Advanced & Expert Users

deny deletion of a file without omiting w permission

how to forbid deleting a file even though the file is owned by the user? I thought of setfacl command on solaris. Any hints please? thx (2 Replies)
Discussion started by: melanie_pfefer
2 Replies

10. Linux

sudoers file

Hi, I have edited 'sudoers' file to allow 'cads' user shutdown the system without providing a password. Can someone tell me what's wrong with my file? It's not working when I 'sudo SHUTDOWN' command: sudo: SHUTDOWN: command not found Thanks a lot! # Host alias specification... (4 Replies)
Discussion started by: whatisthis
4 Replies
Login or Register to Ask a Question