Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When I want to grant access to another user to my file, I use chmod 777 file, but if I want to be sure I'm granting permission just for that user, how can I do it?

-- update

The file is owned by "root", so it's mine if I access it with sudo, I suppose (or maybe I'm confused.. please correct me).

I want to share a folder called /Data in the root. The other user I want to share it is the root of an embedded system, which I'm accessing with telnet and NFS.

The files inside /Data are generated by me, and every time I generate them, I have to use the command chmod 777 /Data so I can access them from the embedded system.

I'm using Ubuntu in my computer, and a compiled-here-linux in the embedded system.

share|improve this question
1  
@Tom: Please give more details. Is this a file owned by you? Where on the computer system is it located? Is the other user on the same system? Also, some more details about the use case would be helpful. If you just want to share a file with another person without anyone else being able to access it, there are variety of options, including pgp/gpg encryption. The traditional Unix permission model is a bit restricive, but you might want to consider acl if you are using Linux. What OS are you using? –  Faheem Mitha Mar 29 '11 at 14:44
    
Since you are root (mentioned in a comment below), can't you just use the user's name? For example chown bob file. Or if you want both the owner and the group chown bob.users file. –  faif Mar 29 '11 at 17:26
    
@Faheem Mitha please, see my update –  Tom Brito Mar 29 '11 at 17:27
1  
@Tom: Doing anything as root, unless absolutely necessary, is a really, really, bad idea. This is usually one of the first things one learns about unix, sometimes the hard way. Unless you really need to be root to access the files, don't do it as root (or sudo, which is equivalent). If you want to restrict permissions, there are better, safer ways to do it. –  Faheem Mitha Mar 29 '11 at 17:35
    
@Tom: I'm not sure if I understood the entire issue correctly, but if you want to share files between users, and want to be able to override the umask, acl is a reasonable way to go. This does assume the users you are sharing among are on the same system. acl is a linux extension of the basic unix permissions system. –  Faheem Mitha Mar 29 '11 at 17:41
show 6 more comments

2 Answers

up vote 9 down vote accepted

You need to find a group that only you and that user is part of, and give correct permission to the group, not the world.

Could be easier with access control lists, if available.

share|improve this answer
    
Can't I give the user name for the chmod? –  Tom Brito Mar 29 '11 at 15:02
1  
@Tom chmod changes the file mode bits; they don't have that kind of flexibility. You set read/write/execute for the owner, people in the owner's group, and everyone; that's it. If you need something more you should look into access control lists –  Michael Mrozek Mar 29 '11 at 15:11
2  
You can use this to figure out which groups you both belong to: wdiff -t <(groups $USER) <(groups other_user) –  l0b0 Mar 29 '11 at 15:26
    
So, if we both don't belong to a common group, how can I make us part of a same group? (I have access to both users here) –  Tom Brito Mar 29 '11 at 17:14
2  
@Tom: groupadd GROUPNAME to create the group, then usermod -a -G GROUPNAME USERNAME to add a user to the group. I also recommend reading the man pages of both commands. –  André Paramés Mar 30 '11 at 0:55
add comment

If you own the file, setfacl -m u:otheruser:rwx filename

If not, or if your filesystem doesn't support extended acls, I'm afraid you're out of luck.

share|improve this answer
    
I'm out of luck, there's no setfacl command. –  Tom Brito Mar 29 '11 at 17:05
    
@Tom: apt-get install acl or similar. –  Faheem Mitha Mar 29 '11 at 17:09
    
the user name in the other machine (an embedded system) is "root", so I tried with sudo setfacl -m u:root:rwx /Data but I got setfacl: /Data: Operation not supported –  Tom Brito Mar 29 '11 at 17:19
    
The file is mine, in my root user, of my computer. So it should work with sudo.. –  Tom Brito Mar 29 '11 at 17:20
    
@Tom: You need to mount your partition(s) with support for acl. See the docs. –  Faheem Mitha Mar 29 '11 at 17:37
show 6 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.