user21
user21

Reputation: 1351

chmod - protect users' file being accessed so only owner can access?

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

Answers (3)

guettli
guettli

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

Danny
Danny

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

  • 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

Upvotes: 85

Greg M
Greg M

Reputation: 954

You can do the following command on the file:

chmod 744 filename

Upvotes: 2

Related Questions