Linux 進階指令

檔案權限設定

改變檔案群組
chgrp [群組名稱] [檔案或目錄]
  • 群組名稱記錄在/etc/group設定檔中,改變群組時,若群組名稱不存在設定檔中會發生錯誤。

範例:設定db.sqlite3的群組用戶為www-data

chgrp www-data db.sqlite3
改變檔案擁有者
chown [-R] [帳號名稱或群組名稱] [檔案或目錄]
  • 帳號名稱記錄在/etc/passwd設定檔中,改變擁有者時,若帳號名稱不存在設定檔中會發生錯誤。
  • -R設定後,會連同目錄底下的所有目錄和檔案一同改變擁有者。

範例:

chown deploy mysite.conf
改變檔案存取權限

方式一:

chmod [-R] [xyz] [檔案或目錄]
  • xyz分別代表usergroupother的權限。
  • xyz為三個rwx加總的數字組合。
    • r : read : 4
    • w : write : 2
    • x : excute : 1

範例一:設定test.txt的權限為:擁有者可讀/寫/執行、群組用戶可讀、其他用戶可讀。

chmod 744 test.txt

範例二:設定test目錄下的所有檔案與目錄擁有相同的權限。

chmod -R 755 test

方式二:

chmod [-R] [ugoa] [+-=] [rwx] [檔案或目錄]
  • 用戶
    • u : user
    • g : group
    • o : other
    • a : all
  • 操作
    • + : 加入
    • - : 除去
    • = : 設定
  • 存取權限
    • r : 讀取
    • w : 寫入
    • x : 執行

範例:群組用戶新增寫入db.sqlite3的權限。

chmod g+w db.sqlite3
查看檔案權限
ls -l

查看方式:

- --- --- ---
- rwx rwx rwx
  • 由左而右依序代表擁有者群組用戶其他用戶rwx權限。

Test RESTful API

curl -X POST http://localhost/api/test

Create a User with a Home Directory

useradd -m bob

The above command will create a /home/bob folder for the user bob.

Change a User's Password

passwd bob

The above command will allow you to set the bob user's password.

Remove a User and its files

userdel -r -f bob

results matching ""

    No results matching ""