SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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?
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.
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.
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.
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).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.