006---Linux用户、群组和权限
用戶、組、權(quán)限管理
用戶管理
增
語法:useradd -c '添加用戶1' user1
選項(xiàng)和參數(shù):
- -c:用戶的備注信息
- -d:用戶的家目錄
- -g:指定用戶所屬的用戶組(gid)
- -s:指定用戶登錄所用的Shell
- -u:指定用戶的uid
- -G:指定用戶所屬的附加組
新建用戶實(shí)際上也是創(chuàng)建一堆文件,一切皆文件。
[root@online1 ~]# tail -1 /etc/passwd JiangZiYa:x:1000:1000::/home/JiangZiYa:/bin/bash [root@online1 ~]# tail -1 /etc/shadow JiangZiYa:$6$So5kNCs5$/AOhUm9XYzF7JDGvURiNDc9MXnXx2Q0kFUl953e5DNztAZZJoYrxOQ.3xLZT7pQiR05m5pDbgGAOVLqLT.Xq//:17931:0:99999:7::: [root@online1 ~]# tail -1 /etc/group JiangZiYa:x:1000: [root@online1 ~]# tail -1 /etc/gshadow JiangZiYa:!:: [root@online1 ~]# ls /var/spool/mail/ JiangZiYa [root@online1 ~]# ls /home/ JiangZiYa刪
如果一個(gè)用戶的賬號(hào)不再使用,可以從系統(tǒng)中刪除。刪除用戶賬號(hào)就是要將/etc/passwd等系統(tǒng)文件中的該用戶記錄刪除,必要時(shí)還刪除用戶的主目錄。語法如下:userdel -r user1。此命令是把用戶的主目錄一起刪除。
改
修改用戶賬號(hào)就是根據(jù)實(shí)際情況更改用戶的有關(guān)屬性,如用戶號(hào)、主目錄、用戶組、登錄Shell等。
usermod 選項(xiàng) 用戶名
選項(xiàng)和添加用戶的參數(shù)一樣。
查
語法:id user1
口令管理
語法:passwd 選項(xiàng) 用戶名
選項(xiàng)和參數(shù):
- -l: 鎖定用戶
- -u: 解鎖用戶。
- -d: 使賬號(hào)無口令
- -f: 強(qiáng)迫用戶下次登錄時(shí)修改口令
組管理
增
語法:groupadd 選項(xiàng) group1
選項(xiàng):
- -g:GID,組標(biāo)識(shí)號(hào)
刪
語法:groupdel group1
改
語法:groupmod -n group2 group1
選項(xiàng):
- -n:重命名組
查
[root@online1 ~]# id JiangZiYa uid=1000(JiangZiYa) gid=1000(JiangZiYa) groups=1000(JiangZiYa),0(root)權(quán)限管理
文件基本屬性
使用ll or ls -l來查看文件詳細(xì)信息。如:
drwxr-xr-x. 5 root root 52 Feb 2 01:11 pm drwxr-xr-x. 5 root root 72 Feb 2 01:12 polkit-1 drwxr-xr-x. 2 root root 6 Jun 10 2014 popt.d drwxr-xr-x. 2 root root 154 Feb 2 01:13 postfix drwxr-xr-x. 3 root root 123 Feb 2 01:12 ppp drwxr-xr-x. 2 root root 78 Feb 2 01:12 prelink.conf.d -rw-r--r--. 1 root root 233 Jun 7 2013 printcap -rw-r--r--. 1 root root 1819 Oct 31 03:48 profile drwxr-xr-x. 2 root root 280 Feb 4 21:39 profile.d -rw-r--r--. 1 root root 6545 Oct 31 03:48 protocols drwxr-xr-x. 2 root root 35 Feb 2 01:11 python lrwxrwxrwx. 1 root root 10 Feb 2 01:11 rc0.d -> rc.d/rc0.d lrwxrwxrwx. 1 root root 10 Feb 2 01:11 rc1.d -> rc.d/rc1.d- 文件類型(1)
第一個(gè)字符代表這個(gè)文件是目錄、文件、鏈接等- d:目錄、文件夾
- -:文件
- l:鏈接
- c:串行端口設(shè)備,例如鍵盤、鼠標(biāo)
- 文件權(quán)限(2-10)
- 權(quán)限擁有者
- user
- group
- others
- 權(quán)限分類
- r:可讀-->4
- w:可寫-->2
- x:可執(zhí)行-->1
- 權(quán)限擁有者
目錄權(quán)限
r:ls查看該目錄下的子文件名,子目錄名
w:可以在該目錄下創(chuàng)建、刪除、重命名。(會(huì)被x權(quán)限限制)
x:可以cd 到該目錄下。文件屬主和組(12-14)
文件大小(15)
更改文件屬性
- 更改文件9個(gè)屬性(r-w-x)
可以根據(jù)數(shù)字也可以根據(jù)權(quán)限對(duì)應(yīng)的字母
語法:- chomd u=rwx,g=r,o=- a.py
- chmod 777 a.py
- chmod u+r,g-x,o+rwx a.py
- chmod u-r a.py
- 更改文件所屬主
語法:- 全改:chown root.root a.py
- 只改前面:chown .root a.py
- 只改后面:chown root a.py
- 全改:chown root.root a.py
- 更改文件所屬組
語法:- chgrp group a.py
- 遞歸更改
語法:亦即連同次目錄下的所有文件都會(huì)變更- chmod [-R] xyz 文件或目錄(對(duì)于文件或目錄都生效)
轉(zhuǎn)載于:https://www.cnblogs.com/xjmlove/p/10352969.html
總結(jié)
以上是生活随笔為你收集整理的006---Linux用户、群组和权限的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: opentack-openstack组件
- 下一篇: 在统一软件开发过程中使用UML