LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   file permissions (https://www.linuxquestions.org/questions/slackware-14/file-permissions-658010/)

marciobarbalho 07-24-2008 12:36 PM

file permissions
 
Please, dear friends...

How do I set permissions to a file that users are allowed to read but not delete, move or modify ?

Thank you very much

wernerz 07-24-2008 12:41 PM

chmod 444 "file"

Taken from man page:
Examples

chmod 400 file - Read by owner
chmod 040 file - Read by group
chmod 004 file - Read by world
chmod 200 file - Write by owner
chmod 020 file - Write by group
chmod 002 file - Write by world
chmod 100 file - execute by owner
chmod 010 file - execute by group
chmod 001 file - execute by world

To combine these just add the numbers together:
chmod 444 file - Allow read permission to owner and group and world
chmod 777 file - Allow everyone to read, write, and execute file

marciobarbalho 07-24-2008 01:27 PM

then, whether I did this to a file, it works no matter what machine the file will be read on, right? I mean, I set this permissions on my machine and then send the file to a friend who will only read the file whether he is not logged as root, right?

Thanks

wernerz 07-24-2008 01:48 PM

No! File permissions are only good on your machine or on the same linux network. If you send a file to a Windows user he/she will be able to read it/change it/delete it because it is on their computer...assuming it is a text/html or other common file format.

KasMage 07-24-2008 02:37 PM

Permissions are not too hard once you get them down.

4 = read
2 = write
1 = execute

Add them together for combined powers. In other words, 4 (read) + 2 (write) = 6, so 6 means you have the ability to read and write. 7 would be read, write, and execute, and 5 would be read and execute.

Each file will have three numbers for permissions (and an optional fourth, but that's slightly more complicated). The first number determines the permissions for the owner. The second number determines the permissions for the group owner. The third number determines permissions for everyone else.

So, if a file is set to 740, then the owner has full access, people in the group the file belongs to have read access, and others have no access. For your particular case, you're probably wanting something like 744. The owner would retain all control, and everyone else would have read access. The 444 recommendation would work as well, but then the owner has no execute or write permissions, which I would assume you'd want.

As for files retaining their permissions when transferred, you're almost always out of luck. If you e-mail him the file or something along those lines, he gets complete control of his copy of the file. If it's on a local network, then he won't be able to do anything to the file that he doesn't have permission to do, but once he copies the file to his computer, he gets control over that copy. You can't just retain control over a file on somebody else's computer just because they copied it from you.

T3slider 07-24-2008 07:04 PM

If you package the file in a tar archive you can retain permissions (use the -p switch), so when the recipient untars the file the permissions will be preserved. However, as the new owner (or at least as the root user), they can always chmod the file to give themselves write permissions.

Mr. C. 07-24-2008 07:10 PM

Quote:

Originally Posted by marciobarbalho (Post 3225162)
How do I set permissions to a file that users are allowed to read but not delete, move or modify ?

To prevent file deletion, it is necessary to remove write permission from the DIRECTORY where the file resides. When a file is deleted, it is the directory that is modified, not the file.

An alternative is to use chattr on the file (ACLs, but these are non-portable).


All times are GMT -5. The time now is 03:29 AM.