LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-23-2012, 10:23 AM   #1
abhinav4
Member
 
Registered: Jun 2010
Location: India
Distribution: Fedora/Cent OS
Posts: 123

Rep: Reputation: 0
Exclamation Open file using sudo


I have a file "abc" which has 700 permission.
I want to set something in sudoers file so that a user "somename" have full privilege to it.

*What are the best practices to perform the above task.
 
Old 08-23-2012, 10:26 AM   #2
byannoni
Member
 
Registered: Aug 2012
Location: /home/byannoni
Distribution: Arch
Posts: 128

Rep: Reputation: 36
I don't think you can do that in sudoers, but you can do this:
Code:
chown somename abc
 
Old 08-23-2012, 10:36 AM   #3
abhinav4
Member
 
Registered: Jun 2010
Location: India
Distribution: Fedora/Cent OS
Posts: 123

Original Poster
Rep: Reputation: 0
Wee it seems that sudoers file is used only to gain access to some commands. but it cannot be used to give permission to a user to modify the contents of a file
 
Old 08-23-2012, 11:45 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,944

Rep: Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693
Quote:
Originally Posted by abhinav4 View Post
Wee it seems that sudoers file is used only to gain access to some commands. but it cannot be used to give permission to a user to modify the contents of a file
Right...so why can't you do what you want, since you just (essentially) said that sudo can do it?

Give ONE user permission to use ONE command. That command can be "vi <some file name>". Change the ownership of the file to only allow root to access it, so then either root or that one user (via "sudo vi <some file name>") can edit it.
 
Old 08-23-2012, 04:09 PM   #5
jefro
Moderator
 
Registered: Mar 2008
Posts: 15,388

Rep: Reputation: 2199Reputation: 2199Reputation: 2199Reputation: 2199Reputation: 2199Reputation: 2199Reputation: 2199Reputation: 2199Reputation: 2199Reputation: 2199Reputation: 2199
I think I'd have changed the group or owner to this user so that they could do some task before I gave them sudo.
 
1 members found this post helpful.
Old 08-23-2012, 04:18 PM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,944

Rep: Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693
Quote:
Originally Posted by jefro View Post
I think I'd have changed the group or owner to this user so that they could do some task before I gave them sudo.
That's another way to do it, which will work just fine, too. However, I tend to lean towards sudo for things just like this, mainly because of the auditing purposes. A user can modify/delete their shell history, but (if you only give them sudo rights for ONE COMMAND), can't edit the sudo logs, and you can see what they did, and when.

The same thing can be accomplished either way, though, but the OP did ask about sudo specifically.
 
Old 08-23-2012, 06:58 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Unfortunately, tools like vi enable you to escape to the shell, then all bets are off ...
I'd go with user or group ownership & set the perms as needed or (more fine-grained) use an ACL.
 
Old 08-23-2012, 07:04 PM   #8
byannoni
Member
 
Registered: Aug 2012
Location: /home/byannoni
Distribution: Arch
Posts: 128

Rep: Reputation: 36
Quote:
Originally Posted by chrism01 View Post
Unfortunately, tools like vi enable you to escape to the shell, then all bets are off ...
I'd go with user or group ownership & set the perms as needed or (more fine-grained) use an ACL.
That is a good point, but:
Quote:
Originally Posted by TB0ne View Post
if you only give them sudo rights for ONE COMMAND
Don't give them a command that will let them escape to the shell. Be careful, but if you know what you're doing, you won't have that problem.
 
Old 08-23-2012, 07:16 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Quote:
I want to set something in sudoers file so that a user "somename" have full privilege to it.
Need the OP to define 'full privilege'.

In any case my point stand; sudo is designed to control what cmds/tools you can run.
It cannot protect files and many cmds have a way to break out into the shell, even if its just ctrl-C or similar.
See the Security Notes here http://linux.die.net/man/8/sudo
 
Old 08-24-2012, 07:02 AM   #10
abhinav4
Member
 
Registered: Jun 2010
Location: India
Distribution: Fedora/Cent OS
Posts: 123

Original Poster
Rep: Reputation: 0
Quote:
somename ALL=/root/abc
Putting above line in sudoers file made me achieve what i was trying, and I do not think it is a security hole.

Last edited by abhinav4; 08-24-2012 at 07:04 AM.
 
Old 08-24-2012, 08:39 AM   #11
iamwilliam
Member
 
Registered: Apr 2006
Location: Nairobi
Distribution: CentOS
Posts: 78

Rep: Reputation: 21
I think you need to use FACL (File Access Lists) to achieve what you want.

You need to make sure that the filesystem has been mounted with the acl option.

Code:
[root@docserver ~]# cat /etc/fstab
/dev/VolGroup00/LogVol00 /                       ext3    defaults,acl        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
Remount the filesystem
Code:
mount -o remount /
Verify the options have been applied
Code:
[root@server ~]# mount -l
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw,acl)
Now user2 has "full control" over secretfile
Code:
 setfacl -m u:user2:x /home/user1/
 setfacl -m u:user2:rwx /home/user1/secretfile
 
Old 08-24-2012, 09:43 AM   #12
abhinav4
Member
 
Registered: Jun 2010
Location: India
Distribution: Fedora/Cent OS
Posts: 123

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by iamwilliam View Post
I think you need to use FACL (File Access Lists) to achieve what you want.

You need to make sure that the filesystem has been mounted with the acl option.

Code:
[root@docserver ~]# cat /etc/fstab
/dev/VolGroup00/LogVol00 /                       ext3    defaults,acl        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
Remount the filesystem
Code:
mount -o remount /
Verify the options have been applied
Code:
[root@server ~]# mount -l
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw,acl)
Now user2 has "full control" over secretfile
Code:
 setfacl -m u:user2:x /home/user1/
 setfacl -m u:user2:rwx /home/user1/secretfile
Thanks but the whole question was to do it from sudoers file
 
  


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
LXer: The Ultimate Sudo FAQ To Sudo Or Not To Sudo? LXer Syndicated Linux News 13 04-13-2013 02:36 AM
[SOLVED] "sudo: Can't mkdir /var/run/sudo/%user%: File exists" CNBarnes Linux - Server 7 01-10-2011 05:11 PM
open sudo terminal program in aix in c sachin.s.puri AIX 1 12-21-2009 09:22 AM
[SOLVED] How can I double click and open application with sudo permission blurboy Linux - Newbie 15 10-09-2009 11:03 PM
Geting error loop QFike:getch: File not open QFile:atEnd: this file is not open badgerbox76 Linux - Newbie 6 01-07-2006 06:30 PM


All times are GMT -5. The time now is 12:51 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration