在Linux中用戶是很重要的驰弄,我們想使用linux乾闰,不論遠(yuǎn)程還是本機(jī),都必須擁有一個賬號疏日,并且對于不同的系統(tǒng)資源擁有不同的使用權(quán)限偿洁。其中對文件/目錄的權(quán)限包括:r -- 4 read;w -- 2 write沟优;x --1 execute
Linux的權(quán)限等級主要分為三種:組權(quán)限涕滋、用戶權(quán)限和其他權(quán)限。
例如挠阁,drwxr-xr-x 7 keyboard wheel 119120 Mar 14 2019 test.txt
- d # directory宾肺,如果是 - 代表文件
- rwxr-xr-x # 可以分為三組,第一組
rwx
代表wheel組權(quán)限侵俗,第二組r-x
代表keyboard用戶權(quán)限锨用,第三組r-x
代表其他權(quán)限 - 119120 # 文件的大小,單位為字節(jié)
- Mar 14 2019 # 文件的最后修改日期
- test.txt # 文件名稱
chmod +/-rwx 文件名/目錄名 # 修改用戶或者組的權(quán)限
sudo chmod -w test.txt # 移除keyboard用戶的可寫權(quán)限
sudo chmod 777 test.txt # 給文件test.txt的不同用戶添加權(quán)限r(nóng)wx|rwx|rwx->擁有者|組|其他用戶
sudo chmod -R 775 test01 # 給文件夾test01的不同用戶添加權(quán)限r(nóng)wx|rwx|rx
chgrp -R 組名 文件/目錄 # 修改文件/目錄所屬組
sudo chgrp -R dev test01 # 修改目錄test01的所屬組為dev
cat /etc/group # 查看組
sudo groupadd test # 創(chuàng)建test組
sudo groupdel test # 刪除test組
chown 用戶名 文件/目錄 # 修改文件/目錄的擁有者
sudo chown launcher test.txt # 將test.txt文件的擁有者改為launcher