Ownership and Permission
In computer operations, there is a device to ensure that personal files (like documents, folders, and hard disks) are kept private from others and prevent them from accessing, modifying, or deleting any data.
To do this, the concept of ‘owners’ and ‘permissions’ are being employed. So, every file or directory has an "owner" (usually the user who created it) and a "group".
For example, when I right click on a folder (Guitar), and choose ‘Properties’ and then select the ‘Permissions’ tab, the following will result:
There are 3 fields for ‘Access Permissions’ and 2 fields for ‘Ownership’. It suggests that the owner is ‘kai’, who can vew & modify content of the folder. ‘Others’ and ‘Group’ (a member of it) can only view the content but cannot modify it.
We may also have situations as the one below:
where the ownship is ‘root’ (the administrator), and no one is permitted to view or modify the content.
There are times that one may want or need to change the Ownership or Permissions.
In the linux environment, you can use the command chown to change the Ownership (as aresult, the new owner will have all the Permissions).
For example, to change the owner of ‘myfile.txt’ to 'john' AND the group to 'john', the syntax is like this:
sudo chown john:john myfile.txt
or
sudo chown john:users myfile.txt
To change ownership recursively for an entire directory and all its contents:
sudo chown -R john:john /path/to/directory/
If you to change the ‘Permissions’ only use the command chmod.
This command keeps the ‘Ownership’ unchanged but change only the 3 main Permissions:
- Read
- Write
- Execute
The chmod command is used with a symbolic or numeric (octal) mode.
The following symbols are used for different catagories of users and Permissions:
· u = user/owner
· g = group
· o = others (any other user on the system)
· a = all (equivalent to u+g+o)
· r = read
· w = write
· x = execute
You add (+) or remove (-) permissions.
Examples:
Give read and write permission to "others" (any user):
sudo chmod o+rw myfile.txt
Give read, write, and execute permission to "others":
sudo chmod o+rwx myscript.sh
Give read and execute permission to "others" for a directory/drive (so they can list its contents):
sudo chmod o+rx /path/to/directory/
Set the permissions for "others" to be exactly read and write (and remove execute):
sudo chmod o=rw myfile.txt
Make a file readable and writable by EVERYONE (owner, group, and others):
sudo chmod a+rw myfile.txt
沒有留言:
張貼留言