How to Set File and Directory Permissions with chmod's Numeric Notation in fedora linux

10:56 AM
Setting File and Directory Permissions with chmod's Numeric Notation


You need to control who can access what file. Either you need to keep prying eyes away from the recipe for the secret sauce, or you have some other secure information that needs protection. Or (more likely) you want to make something executable. In any case, you need to set permissions on files, and you need to understand how to calculate the correct numeric permission values.


Use the chmod (change mode) command. Only root user (superuser) and the file's owner can change permissions.


For example, this command gives the file owner read and write access to /archive/datafile, with verbose output. No other user, except root, can access this file at all:


$ chmod -v 600 /archive/datafile


mode of `/archive/datafile' changed to 0600 (rw-------)




Here the owner of /shared/list makes it world-readable, but only the file owner and root can make changes to it:




$ chmod -v 644 /shared/list


mode of `/shared/list' changed to 0644 (rw-r--r--)




Any script must have the executable bit set for it to work. This command makes a script editable only by the owner, and readable and executable by everyone:


$ chmod 755 /shared/somescript




Directories must always have the executable bit set, or they won't work:


$ chmod 755 /shared




Set permissions for a directory and its contents, including subdirectories, with the -R (recursive) flag. -v turns on verbosity, so you can see what it is doing:


$ chmod -R -v 755 /shared

0 Comments