<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          用戶與組管理全攻略:確保權(quán)限分配無(wú)懈可擊

          共 10533字,需瀏覽 22分鐘

           ·

          2024-11-13 18:14

          目錄

          • 用戶和組管理

            • 用戶管理

            • 密碼管理

            • 組管理

            • 用戶創(chuàng)建命令useradd

            • 用戶刪除命令userdel

            • 查看用戶帳號(hào)的信息命令id

            • usermod 修改用戶帳號(hào)屬性的命令

            • 切換用戶命令su

            • 密碼管理命令passwd

            • 密碼生成工具openssl

            • 創(chuàng)建組命令groupadd

            • 刪除組命令groupdel

            • 各配置文件說(shuō)明

            • 密碼復(fù)雜性

            • 用戶和組概念

            • 用戶分類

            • Linux安全上下文

            • Linux用戶組類別

            • 何為用戶何為組?

            • Linux用戶和組相關(guān)的配置文件

            • 用戶和組相關(guān)的管理命令


          何為用戶何為組?

          用戶和組概念

          例子
          進(jìn)火車站刷臉
          上下班刷指紋
          天地會(huì)接頭暗號(hào)

          用戶存在的目的是為了實(shí)現(xiàn)資源的分派。

          例子
          共享單車抱回家
          總經(jīng)理行使權(quán)利

          Authentication:認(rèn)證
          Authorization:授權(quán)
          Accouting:審計(jì)

          用戶分類

          Linux用戶分為管理員和普通用戶兩種:

          用戶類別 用戶ID
          管理員 0
          普通用戶 1-65535

          其中普通用戶又分為系統(tǒng)用戶和登錄用戶兩種:

          用戶類別 用戶ID
          系統(tǒng)用戶 1-999(為守護(hù)類進(jìn)程獲取系統(tǒng)資源而完成權(quán)限指派的用戶)
          登錄用戶 1000-60000(為了完成交互式登錄使用的用戶)

          Linux安全上下文

          1. 運(yùn)行中的程序:進(jìn)程(process)
            1.2 以進(jìn)程發(fā)起者的身份運(yùn)行
            1.2.1 root:cat
            1.2.2 tom:cat
            1.3 進(jìn)程所能夠訪問(wèn)的所有資源的權(quán)限取決于進(jìn)程的發(fā)起者的身份

          2. Linux通過(guò)安全上下文的概念完成用戶權(quán)限的指派。
            2.2 先判斷用戶是否是某文件的屬主
            2.3 再判斷用戶是否屬于某個(gè)組
            2.4 最后定其為其他用戶

          Linux用戶組類別

          用戶組類別 特性
          私有組 創(chuàng)建用戶時(shí),如果沒(méi)有為其指定所屬的組,
          系統(tǒng)會(huì)自動(dòng)為其創(chuàng)建一個(gè)與用戶名相同的組
          基本組 用戶的默認(rèn)組
          附加組(額外組) 默認(rèn)組以外的其它組

          Linux用戶和組相關(guān)的配置文件

          各配置文件說(shuō)明

          配置文件 作用
          /etc/passwd 用戶及其屬性信息(名稱、uid、基本組id等等)
          /etc/group 組及其屬性信息
          /etc/shadow 用戶密碼及其相關(guān)屬性
          /etc/gshadow 組密碼及其相關(guān)屬性。在用戶執(zhí)行基本組切換時(shí)使用
          配置文件 /etc/passwd /etc/group
          第一字段 用戶名 組名
          第二字段 密碼占位符 組密碼
          第三字段 UID GID
          第四字段 GID 以當(dāng)前組為附加組的用戶列表(分隔符為逗號(hào))
          第五字段 用戶的描述信息
          第六字段 用戶家目錄
          第七字段 用戶的登錄shell
          配置文件 /etc/shadow
          第一字段 登錄名
          第二字段 加密后的密碼
          第三字段 最近一次更改密碼的日期
          第四字段 密碼的最小使用期限
          第五字段 密碼的最大使用期限
          第六字段 密碼警告時(shí)間段
          第七字段 密碼禁用期
          第八字段 帳號(hào)的過(guò)期日期
          第九字段 保留字段

          密碼復(fù)雜性

          1. 密碼復(fù)雜性策略:
            1.2 使用數(shù)字、大寫字母、小寫字母及特殊字符中至少3種
            1.3 足夠長(zhǎng)
            1.4 使用隨機(jī)密碼,不要使用有意義的單詞或數(shù)字
            1.5 定期更換,不要使用最近曾經(jīng)使用過(guò)的密碼

          用戶和組相關(guān)的管理命令

          用戶管理

          用戶創(chuàng)建命令useradd

          -u UID
          useradd命令用來(lái)建立用戶賬號(hào)和創(chuàng)建用戶的起始目錄,使用權(quán)限是終極用戶。-g:指定用戶所屬的起始群組。-G:指定用戶所屬的附加群組。

          [root@lnh ~]# id root
          uid=0(root) gid=0(root) groups=0(root)
          //查看root用戶信息
          [root@lnh ~]# useradd xbz
          [root@lnh ~]# id xbz
          uid=1000(xbz) gid=1000(xbz) groups=1000(xbz)
          //查看用戶id, 組id ,所屬組
          [root@lnh ~]# useradd -u 2000 xbz1
          [root@lnh ~]# id xbz1
          uid=2000(xbz1) gid=2000(xbz1) groups=2000(xbz1)
          //定義用戶id,一般組id也會(huì)和其一樣

          -g GID

          [root@lnh ~]# useradd -g 2000 xbz1
          [root@lnh ~]# id xbz1
          uid=1001(xbz1) gid=2000(xbz1) groups=2000(xbz1)
          //定義gid組id

          -G groupname(組名)

          [root@lnh ~]# useradd -G xbz1  xbz2
          [root@lnh ~]# id xbz2
          uid=1002(xbz2) gid=1002(xbz2) groups=1002(xbz2),2000(xbz1)
          //給xbz2添加xbz1附屬組

          -c "COMMENT"

          [root@lnh ~]# useradd -c xbz1 xbz3
          [root@lnh ~]# id xbz3
          uid=1003(xbz3) gid=1003(xbz3) groups=1003(xbz3)
          [root@lnh ~]# useradd -c xx hh
          [root@lnh ~]# tail -5 /etc/passwd
          xbz:x:1000:1000::/home/xbz:/bin/bash
          xbz1:x:1001:2000::/home/xbz1:/bin/bash
          xbz2:x:1002:1002::/home/xbz2:/bin/bash
          xbz3:x:1003:1003:xbz1:/home/xbz3:/bin/bash
          hh:x:1004:1004:xx:/home/hh:/bin/bash
          //注釋信息

          -d

          [root@lnh ~]# useradd -d /home/xbz5 xbz5
          [root@lnh ~]# cd ~xbz5/
          [root@lnh xbz5]# pwd
          /home/xbz5
          //指定用戶的家目錄。此目錄必須不能事先存在, 否則將不會(huì)從/home/xbz5中復(fù)制環(huán)境設(shè)置文件

          -s,-M,-r

          [root@lnh ~]# useradd -rMs /sbin/nologin tsb
          [root@lnh ~]# ll /home/
          total 0
          drwx------. 2 hh hh 62 Jul 3 18:24 hh
          drwx------. 2 xbz xbz 62 Jul 3 17:44 xbz
          //-r添加一個(gè)系統(tǒng)用戶,-M創(chuàng)建用戶時(shí)不創(chuàng)建家目錄,-s登錄shell不允許登錄這個(gè)用戶

          用戶刪除命令userdel

          [root@lnh ~]# userdel aaa
          [root@lnh ~]# ls /home/
          aaa bbb
          [root@lnh ~]# userdel -r bbb
          [root@lnh ~]# ls /home/
          aaa
          //直接用userdel刪除,其是默認(rèn)不刪除家目錄,-r刪除是連著家目錄一起刪除

          查看用戶帳號(hào)的信息命令id

          id,-u,-g,-G

          [root@lnh ~]# id xbz
          uid=1000(xbz) gid=1000(xbz) groups=1000(xbz)
          //查看用戶信息
          [root@lnh ~]# id -u xbz
          1000
          //用戶id
          [root@lnh ~]# id -g xbz
          1000
          //組id
          [root@lnh ~]# id -G xbz
          1000
          //附屬組

          usermod 修改用戶帳號(hào)屬性的命令

          -u UID ,-g GID,-ag

          [root@lnh ~]# id tsb
          uid=995(tsb) gid=992(tsb) groups=992(tsb)
          [root@lnh ~]# usermod -u 111 tsb
          //-u 修改用戶id,不能和其他用戶相同
          [root@lnh ~]# usermod -g 993 tsb
          [root@lnh ~]# id tsb
          uid=111(tsb) gid=993(rngd) groups=993(rngd)
          //修改組id,組必須事先存在
          [root@lnh ~]# usermod -G xxxb tsb
          [root@lnh ~]# id tsb
          uid=111(tsb) gid=993(rngd) groups=993(rngd),1112(xxxb)
          [root@lnh ~]# usermod -G xbz tsb
          [root@lnh ~]# id tsb
          uid=111(tsb) gid=993(rngd) groups=993(rngd),1000(xbz)
          [root@lnh ~]# usermod -aG xxxb tsb
          [root@lnh ~]# id tsb
          uid=111(tsb) gid=993(rngd) groups=993(rngd),1000(xbz),1112(xxxb)
          //-G修改附加組,沒(méi)有加-a會(huì)覆蓋前面的附加組

          -md

          [root@lnh ~]# ll /home/
          total 0
          drwx------. 2 1007 1007 62 Jul 3 18:53 aaa
          drwx------. 2 xxxb xxxb 62 Jul 3 19:04 xxxb
          [root@lnh ~]# usermod -md /opt/shan xxxb
          [root@lnh ~]# ll /home/
          total 0
          drwx------. 2 1007 1007 62 Jul 3 18:53 aaa
          [root@lnh ~]# ll /opt/
          total 0
          drwx------. 2 xxxb xxxb 62 Jul 3 19:04 shan
          -rw-r--r--. 1 root root 0 Jul 3 07:55 xbz
          //改變用戶家目錄的同時(shí)把原來(lái)家目錄的文件移動(dòng)到新的家目錄中

          -e -f

          [root@lnh ~]# usermod -e 2022-7-7 xxxb
          [root@lnh ~]# usermod -f 2 xxxb
          [root@lnh ~]# cat /etc/shadow |grep xxxb
          xxxb:!!:19176:0:99999:7:2:19180:
          //-e YYYY-MM-DD 指明用戶帳號(hào)過(guò)期日期
          //-f 設(shè)置過(guò)期的延緩期限

          -L -U

          [root@lnh ~]# passwd xxxb
          Changing password for user xxxb.
          New password:
          BAD PASSWORD: The password is a palindrome
          Retype new password:
          passwd: all authentication tokens updated successfully.
          [root@lnh ~]# usermod -L xxxb
          [root@lnh ~]# cat /etc/shadow |grep xxxb
          xxxb:!$6$6RKtLUh/iJRAf5aq$J7MIzJ2sY2VrS5FmeNvrampnjO2S1HyRQKVJz2wYrRI0Qq35CrE/QyxjE6K8mhEV15JqmFOem9ICO0FbeEP6M/:19176:0:99999:7:2:19180:
          [root@lnh ~]# usermod -U xxxb
          [root@lnh ~]# cat /etc/shadow |grep xxxb
          xxxb:$6$6RKtLUh/iJRAf5aq$J7MIzJ2sY2VrS5FmeNvrampnjO2S1HyRQKVJz2wYrRI0Qq35CrE/QyxjE6K8mhEV15JqmFOem9ICO0FbeEP6M/:19176:0:99999:7:2:19180:
          //-L鎖定帳號(hào),被鎖定的帳號(hào)在/etc/shadow文件中密碼前面會(huì)有一個(gè)!感嘆號(hào)
          //-U 解鎖帳號(hào)

          -s shell

          [root@lnh ~]# usermod -s /sbin/nologin xxxb
          [root@lnh ~]# cat /etc/passwd |grep xxxb
          xxxb:x:1122:1112::/opt/shan:/sbin/nologin
          -s//禁止其登錄shell進(jìn)入xxxb

          切換用戶命令su

          切換用戶的方式 特點(diǎn)
          su USERNAME 非登錄式切換,即不會(huì)讀取目標(biāo)用戶的配置文件
          su - USERNAME 登錄式切換,即會(huì)讀取目標(biāo)用戶的配置文件。完全切換
          su - 不指定用戶時(shí)默認(rèn)切換至root用戶
          root su至其他用戶不需要密碼,非root用戶su至其他用戶時(shí)需要輸入目標(biāo)用戶的密碼

          [root@lnh ~]# su tushanbu
          [tushanbu@lnh root]$ su -
          Password:
          Last login: Sun Jul 3 19:56:01 CST 2022 from 192.168.222.1 on pts/0
          [root@lnh ~]# su - tushanbu
          Last login: Sun Jul 3 19:57:00 CST 2022 on pts/0
          [tushanbu@lnh ~]$ su -
          Password:
          Last login: Sun Jul 3 19:57:31 CST 2022 on pts/0
          //在root用戶下可以直接su tushanbu進(jìn)入,su -是不指定用戶默認(rèn)切換到root用戶,su - tushanbu是登錄的方式進(jìn)行切換
          [root@lnh ~]# su - tushanbu -c "mkdir xxx"
          [root@lnh ~]# ls /home/tushanbu/
          xxx
          //不進(jìn)入用戶進(jìn)行創(chuàng)建

          bash的配置文件:

          配置文件類型 配置文件路徑
          全局配置 etc/profile
          /etc/profile.d/*.sh
          /etc/bashrc
          個(gè)人配置 ~/.bash_profile
          ~/.bashrc
          配置文件類型 功能
          profile類 為交互式登錄的shell提供配置,用來(lái)設(shè)定環(huán)境變量、運(yùn)行命令或腳本
          bashrc類 為非交互式登錄的shell提供配置,用來(lái)設(shè)定本地變量、定義命令別名
          登錄式shell如何讀取配置文件?
          /etc/profile --> /etc/profile.d/*.sh --> ~/.bash_profile --> ~/.bashrc --> /etc/bashrc

          非登錄式shell如何讀取配置文件?
          ~/.bashrc --> /etc/bashrc --> /etc/profile.d/*.sh

          密碼管理

          密碼管理命令passwd

          passwd , --stdin

          [root@lnh ~]# passwd tushanbu 
          Changing password for user tushanbu.
          New password:
          BAD PASSWORD: The password is a palindrome
          Retype new password:
          passwd: all authentication tokens updated successfully.
          //在root下可以直接進(jìn)行設(shè)置密碼
          [root@lnh ~]# echo 1 |passwd --stdin tushanbu
          Changing password for user tushanbu.
          passwd: all authentication tokens updated successfully.
          //標(biāo)準(zhǔn)輸入獲取用戶密碼

          -l ,-u ,-d

          [root@lnh ~]# passwd -l tushanbu 
          Locking password for user tushanbu.
          passwd: Success
          //鎖定用戶
          [root@lnh ~]# passwd -u tushanbu
          Unlocking password for user tushanbu.
          passwd: Success
          //解鎖用戶
          [root@lnh ~]# passwd -d tushanbu
          Removing password for user tushanbu.
          passwd: Success
          //刪除用戶密碼

          -n ,-x,-w,-i

          [root@lnh ~]# passwd -n 20 tushanbu 
          Adjusting aging data for user tushanbu.
          passwd: Success
          //-n mindays最短使用天數(shù)20天
          [root@lnh ~]# passwd -x 200 tushanbu
          Adjusting aging data for user tushanbu.
          passwd: Success
          //-x maxdays最長(zhǎng)使用天數(shù)200天
          [root@lnh ~]# passwd -w 10 tushanbu
          Adjusting aging data for user tushanbu.
          passwd: Success
          //-w warndays提前10天前發(fā)出過(guò)期警告
          [root@lnh ~]# passwd -i 10 tushanbu
          Adjusting aging data for user tushanbu.
          passwd: Success
          //-i inactivedays可以延期10天
          [root@lnh ~]# cat /etc/passwd |grep tushanbu
          tushanbu:x:1123:1123::/home/tushanbu:/bin/bash

          密碼生成工具openssl

          //語(yǔ)法:openssl command [ command_opts ] [ command_args ]
          command //包含標(biāo)準(zhǔn)命令、消息摘要命令、加密命令
          version //查看程序版本號(hào)
          dgst //提取特征碼
          passwd //生成密碼
          rand //生成偽隨機(jī)數(shù)

          [root@lnh ~]# openssl dgst -md5 /etc/fstab
          MD5(/etc/fstab)= 431fca5169ffb3a30eb83c94a11dc2f6
          //提取特征碼
          [root@lnh ~]# openssl passwd -1 -salt hellotom
          Password:
          $1$hellotom$o9rUZ07NstylvbqW9RrdV/
          //生成密碼 openssl passwd -1 -salt string string一般為8
          [root@lnh ~]# openssl rand -base64 20
          aDsYyelB9h6ksGSke6A3bN4OzfI=
          //生成隨機(jī)數(shù) openssl rand -base64 NUM,NUM表示隨機(jī)數(shù)的長(zhǎng)度
          [root@lnh ~]# tr -dc A-Za-z0-9_ < /dev/urandom | head -c 30 |xargs
          VnRr0QqXyGGS5SHuv1Rl1KK3TYPbcb
          //生成30位的密碼

          組管理

          創(chuàng)建組命令groupadd

          -g GID ,-r

          [root@lnh ~]# groupadd bnx
          //創(chuàng)建組
          [root@lnh ~]# groupadd -g 1222 xnx
          //指定組id
          [root@lnh ~]# groupadd -r xbn
          //-r 創(chuàng)建一個(gè)系統(tǒng)組
          [root@lnh ~]# cat /etc/passwd |grep xnx
          [root@lnh ~]# cat /etc/passwd |grep xbn
          [root@lnh ~]# cat /etc/group |grep xbn
          xbn:x:991:
          [root@lnh ~]# cat /etc/group |grep xnx
          xnx:x:1222:
          [root@lnh ~]# cat /etc/group |grep bnx
          bnx:x:2001:

          刪除組命令groupdel

          [root@lnh ~]# groupdel bnx
          [root@lnh ~]# groupdel xbn
          [root@lnh ~]# groupdel xnx
          [root@lnh ~]# cat /etc/group |grep bnx
          [root@lnh ~]# cat /etc/group |grep xbn
          [root@lnh ~]# cat /etc/group |grep xnx

          鏈接:https://www.cnblogs.com/tushanbu/p/16449412.html

          (版權(quán)歸原作者所有,侵刪)


          瀏覽 54
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  99久久黄色 | 三级片av在线 | 五月综合激情网 | 99久久人妻无码精品系列 | 国产精品经典视频 |