Thứ Sáu, 11 tháng 4, 2014

Permissions on ubuntu

Permissions
Nhiều người có thể sử dụng một máy tính trong cùng một khoảng thời gian như nhau.

Vậy làm thế nào để bảo vệ quyền lợi của những user đó?
Đó là mục đích của bài học này

Bài học này bao gồm các lệnh:
+ chmod  thay đổi quyền truy cập  file
+ Su, sudo : tạm thời trở thành supperuser
+ chown: thay đổi quyền sở hữu tệp tin
+ chgrp: Thay đổi quyền sở hữu nhóm của tệp tin

File Permissions:

Trên hệ điều hành linux, mỗi tệp tin và thư mục đều được đăng kí quyền truy cập cho chủ sở hữu riêng của chúng, các thành viên của groupuser liên quan, và những người khác. Permissions có thể được chỉ định để đọc , viết, hay execute một file

Để hiểu về quyền setting một file, chúng ta có thể sử dụng lệnh ls
ví dụ:

[me@linuxbox me]$ ls -l /bin/bash
-rwxr-xr-x 1 root root  316848 Feb 27  2000 /bin/bash

+ file 'bin/bash' được sở hữu bởi user root
+ root user có quyền read, write , execute file này
+ file được sở hữu bởi nhóm root
+ members của nhóm root có thể r, x file này
+ mọi người khác có thể r, x file này

permissions diagram


Chmod:

Chmod command được sử dụng để thay đổi permission của một file hoặc directory. Để sử dụng nó, bạn  xác định các thiết lập mong muốn và tên file, các file mà bạn muốn thay đổi. Có hai cách để thực hiện điều này. Chúng ta chỉ bàn về cách có tên "octal notation method"

Đại diện cho ba thiết lập permissions ( owner, group, and other) là những con số, đây là cách khá thuận tiện cho việc nén lại các thiết lập permissions. Ví dụ , nếu bạn muốn thiếp lập "some_file" có quyền đọc và viết cho owner, nhưng lại muốn giữ file riêng đối với những người khác:

[me@linuxbox me]$ chmod 600 some_file

Bảng các con số đại diện :
http://linuxcommand.org/lc3_lts0090.php


Value Meaning
777 (rwxrwxrwx) No restrictions on permissions. Anybody may do anything. Generally not a desirable setting.
755 (rwxr-xr-x) The file's owner may read, write, and execute the file. All others may read and execute the file. This setting is common for programs that are used by all users.
700 (rwx------) The file's owner may read, write, and execute the file. Nobody else has any rights. This setting is useful for programs that only the owner may use and must be kept private from others.
666 (rw-rw-rw-) All users may read and write the file.
644 (rw-r--r--) The owner may read and write a file, while all others may only read the file. A common setting for data files that everybody may read, but only the owner may change.
600 (rw-------) The owner may read and write a file. All others have no rights. A common setting for data files that the owner wants to keep private.


Directory Permissions

chmod command có thể được sử dụng để điều khiển quyền truy cập cho các directories.
+ r: cho phép list nội dung thư mục
+ w: cho phép tạo, sửa delete file trong thư mục
+ x: Cho phép truy cập vào thư mục. Ví dụ như:
 cd dir


bảng các thiết lập cho directories:

Value Meaning
777 (rwxrwxrwx) No restrictions on permissions. Anybody may list files, create new files in the directory and delete files in the directory. Generally not a good setting.
755 (rwxr-xr-x) The directory owner has full access. All others may list the directory, but cannot create files nor delete them. This setting is common for directories that you wish to share with other users.
700 (rwx------) The directory owner has full access. Nobody else has any rights. This setting is useful for directories that only the owner may use and must be kept private from others.



Trở thành supperuser tạm thời:
Có những lúc bạn cần trở thành supperuser để thục hiện một sô tasks quản trị hệ thống quan trọng. Bạn sẽ cần phải được logged in như là một supper user.
Thực hiện điều này với câu lệnh:
$ su
$ sudo command...

và bạn cần nhập password

Thay đổi tệp tin sở hữu
bạn có thể thay đổi chủ sở hữu của một tệp tin bằng lệnh  chown.
Ví dụ bạn thay đổi chủ sở hữu của tệp tin some_file từ 'me' sang 'you':( bạn cần trở thảnh supperuser trước)

[me@linuxbox me]$ su
Password:
[root@linuxbox me]# chown you some_file
[root@linuxbox me]# exit
[me@linuxbox me]$


Thay đổi nhóm sở hữu:
dùng lệnh "chgrp"
ví dụ:

[me@linuxbox me]$ chgrp new_group some_file

để chuyển quyền nhóm sở hữu của some_file thành new_group

Không có nhận xét nào:

Đăng nhận xét