miercuri, 17 august 2011

Changing files and directories permission in Ubuntu and Debian


In addition of learning the Ubuntu Linux shell commands, this post will show you how to change files and directories permission in Ubuntu and Debian Linux. The chmod command lets you change the access permissions of files and directories. The list below shows several chmod command lines and how access to the directory or file changes. This commands are applied to all Linux distros, not limited to Ubuntu or Debian system.

  • chmod 0700

The directory’s owner can read or write files in that directory as well as change to it. All other users (except root) have no access.

  • chmod 0771

Same as for the owner. All other users can change to the directory, but not view or change files in the directory. This can be useful for server hardening, where you prevent someone from listing directory contents, but allow access to a file in the directory if someone already knows it’s there.

  • chmod 0777

All permissions are wide open.

  • chmod 0000

All permissions are closed. Good to protect a directory from errant changes. However, backup programs that run as non-root may fail to back up the directory’s contents.

  • chmod 666

Open read/write permissions completely on a file.

  • chmod 644

Only the owner can change or delete the file, but all can view it.

The first 0 in the mode line can usually be dropped (so you can use 777 instead of 0777).

The -R option is a handy feature of the chmod command. With -R, you can recursively change permissions of all files and directories starting from a point in the file system. Here are some examples:

$ sudo chmod -R 700 /tmp/test Open permission only to owner below /tmp/test
$ sudo chmod -R 000 /tmp/test Close all permissions below /tmp/test
$ sudo chmod -R a+rwx /tmp/test Open all permissions to all below /tmp/test

Note that the -R option is inclusive of the directory you indicate. So the permissions above, for example, would change for the /tmp/test directory itself, and not just for
the files and directories below that directory.

Reference: Ubuntu Linux Toolbox

Niciun comentariu:

Trimiteți un comentariu