allow user to use sudo cp on a specific directory and only a specific file


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users allow user to use sudo cp on a specific directory and only a specific file
# 1  
Old 09-09-2011
allow user to use sudo cp on a specific directory and only a specific file

Is there a way to allow a user to use sudo cp on a specific directory and only a specific file?
# 2  
Old 09-09-2011
Kind of, but may not offer all the flexibility you want. For instance, to allow user nh2 to copy foo to /home/bar, put in your /etc/sudoers file
Code:
nh2  ALL=(ALL) NOPASSWD: /bin/cp foo /home/bar

Drawbacks are (among others):
  1. cp is not as flexible; for instance I have to use exactly the syntax set in the sudoers file. Eventually this means using absolute path for the file to copy.
  2. access right might need fixing. Depending on your requirement, plain cp or using the '-p' option for cp might be enough.

HTH,
/Lew
# 3  
Old 09-09-2011
I would reccomend you check setuid.

You can make a shell script and a small c program to call it with root privileges.

So an example :
You make shell script with USER named test.sh which does cp file1 /etc/
Then you make a C program called execshell (or whatever) which runs that script with system call ( please find examples online for C setuid and system call )

Compile that program.

As root you make chown root:root and chmod 4755 to that C program.
User can now invoke that c program which will execute that shell script with root permisions and copy the file1 to /etc/ as root invoked by USER.

Be carefull tho, setuid needs to be handled with care.
passwd would be a lovely example of setuid in C and exceptions it uses.

Hope that helps.
Regards
Peasant.
# 4  
Old 09-09-2011
Instead of trying to restrict a program that gives him permissions to copy any file, why not use ordinary file permissions to control his access?
# 5  
Old 09-11-2011
Quote:
Originally Posted by Corona688
Instead of trying to restrict a program that gives him permissions to copy any file, why not use ordinary file permissions to control his access?
The only way that would be possible is if I give write permission on the /etc directory. I don't think thats a good idea. The /etc/resolv.conf keeps getting messed up. I want ordinary users to able to use internet and thats not possible right now with the dns not being set properly. The only way I can think of is by allowing a user to use sudo cp on a specific directory and only a specific file.
This User Gave Thanks to cokedude For This Post:
# 6  
Old 09-12-2011
Quote:
The only way that would be possible is if I give write permission on the /etc directory. I don't think thats a good idea. The /etc/resolv.conf keeps getting messed up. I want ordinary users to able to use internet and thats not possible right now with the dns not being set properly. The only way I can think of is by allowing a user to use sudo cp on a specific directory and only a specific file.
Is that a real problem? You could create a group for the users that need to edit /etc/resolv.conf, gives write permission to /etc/ and /etc/resolv.conf for that group. As long as the other files in /etc doesn't belong to this group, these users won't be able to mess-up those files (files in /etc belong normally to root:root).

Corona is right: If doable, this way should be prefered over sudo/cp.

Brgds,
/Lew
# 7  
Old 09-13-2011
Quote:
Originally Posted by COKEDUDE
The only way that would be possible is if I give write permission on the /etc directory.
Not true, directory permissions don't control that. If you chown :group /etc/resolv.conf ; chmod g+rw /etc/resolv.conf then anyone in group will be able to modify it.
Quote:
The /etc/resolv.conf keeps getting messed up.
Fixing /etc/resolv.conf every time it gets messed up isn't really a solution... It's like stocking extra fire extinguishers instead of fixing a smoking electrical short. If you don't want whatever autoconfig keeps messing up the file to do so, disable it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Is there a way to restrict a user (owner) to execute scripts from a specific directory

Hello, I have a user Bob on a RHEL 7 server1. Where his script area is "/home/Bob/scripts/" and he is the owner for this directory. On the server1, there is a NFS mount from another server2, with path as "/global/work/" and Bob is the owner for this directory too in server2. (Same UID and GID... (5 Replies)
Discussion started by: karumudi7
5 Replies

2. UNIX for Advanced & Expert Users

Change sFTP home directory for particular user and from specific server

Hello Folks, Of course i came here for your favour :) How to set a defalult home directory for sFTP login ( at present users land in to their home directrory) when they connect from specific server. When server(A) sFTP's to Linux server(B) they land to thier home directory. I want... (5 Replies)
Discussion started by: Thala
5 Replies

3. Solaris

Limit bash/sh user's access to a specific directory

Hello Team, I have Solaris 10 u6 I have a user test1 using bash that belong to the group staff. I would like to restrict this user to navigate only in his home directory and his subfolders but not not move out to other directories. How can I do it ? Thanks in advance (1 Reply)
Discussion started by: csierra
1 Replies

4. Solaris

Limit FTP user's access to a specific directory

Hi, I have searched "Limit FTP user's access to a specific directory" subject for 3 days. I found proftp and vsftp but i couldn't compile and install. Is there any idea. Please suggest. (6 Replies)
Discussion started by: hamurd
6 Replies

5. Solaris

How to restrict user to a specific directory in solaris 10

Hi all, I want to create a new user and grant him ONLY transfer files access to a specific directory where he can only upload and read the files. He should be restricted to this activity only. Regards (6 Replies)
Discussion started by: gilldn
6 Replies

6. Solaris

User permission to a specific directory only

is is possible to grant user access to only one subdirectory? example a. create ftp user with read/write/delete access (ftp user doesnt belong to uguys group) $ cd /etc/mydir $ls file1 file2 $ls -al -rw-rw-r-x 2 unixguy uguys 96 Dec 8 12:53 file1 -rw-rw-r-x 2 unixguy uguys 96 Dec 8... (1 Reply)
Discussion started by: lhareigh890
1 Replies

7. Solaris

create user with RWX access to a specific directory in Solaris 10

I need to create a user account for a developer that will allow him rwx access to all resources in a directory. How can I do that? Thanks (5 Replies)
Discussion started by: gsander
5 Replies

8. UNIX for Dummies Questions & Answers

granting permission to file/directory to a specific user

hello, I would like to grant full access to a directory which is owned by root and the web application that created it. I have though of adding the permission to the whole world, but for security reason I would like to grant it to one more user. I have tried this 'chmod -U newUser+wrx... (2 Replies)
Discussion started by: run123
2 Replies

9. Solaris

when FTP user will go to specific directory

Hi experts, I have a user "bingo" in my sunsolaris 9. # /etc/passwd bingo:x:513:1::/export/home/bingo:/bin/bash when anyone Telnet to this user it goes to his home directory /export/home/bingo But now i want- when someone FTP to this user "bingo" it will NOT go to his home dir. Rather it... (5 Replies)
Discussion started by: thepurple
5 Replies

10. Solaris

give user permission on specific directory in solaris

dear all does any one give any user write permission using access control list or another way to solve this problem (1 Reply)
Discussion started by: murad.jaber
1 Replies
Login or Register to Ask a Question