How to set chmod, so that ONLY owner of the file can read, write and execute? (other users cannot read, write, and execute)
Asked
Active
Viewed 5.8k times
3 Answers
69
chmod 600 filename
will do it;
or
chmod 700
if it is an executable.
Another way that is less cryptic is:
chmod go-rwx filename
- The "g" is for group
- The "o" is for others
- The "-" is for removing permissions
- The "r" is for read-permission
- The "w" is for write-permission
- The "x" is for execute permission.
For the sake of completeness:
- "u" is for user / owner
- "+" is for adding permissions
-
Okay. I have read the man for chmod. I understand that by setting 744, I have full ownership and other people will be able to read it too. My webpage can be viewed by others. But I'm really worried that somebody in my school is able to access my folder in linux and copy my source code. – user21 Mar 05 '15 at 20:40
-
Whoops, I guess the 744 isn't what you wanted then. The number system has always confused me a bit, which is why I like the notation I showed above. If you use the "go-rwx" that will make sure nobody but you (and the computer admin, but there's no helping that) can read it. – Danny Mar 05 '15 at 21:02
-
6Here is a good website for figuring out the right number to use: http://www.onlineconversion.com/html_chmod_calculator.htm – Danny Mar 05 '15 at 21:06
-
2
You can do the following command on the file:
chmod 744 filename

Greg M
- 954
- 1
- 8
- 20
-
I have stored the webpage html file at remote linux school server, and I do not wish people to be able to access the file code. But I want people to be able to see the webpage. Please help! – user21 Mar 05 '15 at 20:27
-
1@Jeen It needs read permission for the others group or else it can't be served as a webpage. – randomusername Mar 05 '15 at 20:28
-
I am okay with people able to view the code using file inspector. But I do not wish people to be able to access the file stored in linux university server . – user21 Mar 05 '15 at 20:31
-
@Jeen I fixed it, change it to "chmod 744 filename" so others can view it. – Greg M Mar 05 '15 at 20:32
-
@Greg Can other people in my university able to access my source code store in the linux university server, if I use chmod 744? – user21 Mar 05 '15 at 20:35
-
@Jeen any webpage with HTML can be viewed, you can't hide that. The code will always be able to be viewed, because the HTML code is sent to the browser, and then processed. You can't deny people from viewing the HTML. – Greg M Mar 05 '15 at 20:44
-
back to the question at the top "...How to set chmod, so that ONLY owner of the file can read, write and execute? (other users cannot read, write, and execute) ..." `chmod 744` is not the answer! – guettli Apr 27 '23 at 11:20
0
This way all permissions are set to zero, and then the user gets permissions to read the file:
chmod a=,u=r file
Example:
touch file
chmod a=,u=r file
LANG=C stat file
File: file
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd01h/64769d Inode: 29812993 Links: 1
Access: (0400/-r--------) Uid: ( 1000/ guettli) Gid: ( 1000/ guettli)
Access: 2023-04-27 13:21:19.034135401 +0200
Modify: 2023-04-27 13:21:19.034135401 +0200
Change: 2023-04-27 13:21:27.458108021 +0200
Birth: 2023-04-27 13:21:19.034135401 +0200

guettli
- 25,042
- 81
- 346
- 663