Reputation: 1351
How to set chmod, so that ONLY owner of the file can read, write and execute? (other users cannot read, write, and execute)
Upvotes: 39
Views: 81840
Reputation: 27969
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
Upvotes: 3
Reputation: 3336
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
For the sake of completeness:
Upvotes: 85