4、linux建組

來源:互聯網
上載者:User

標籤:chown   linu   jin   png   tom   su -   技術分享   blog   目錄   

一 手動建立使用者流程

1)  建立使用者natasha,uid為1000,gid為555,備忘資訊為“master”

  vim /etc/passwd

       natasha:x:1000:555:master:/home/Natasha:/bin/bash


2)  修改natasha使用者的家目錄為/Natasha

 

[[email protected] ~]# vim /etc/passwd
[[email protected] ~]# vim /etc/shadow
[[email protected] ~]# vim /etc/group
[[email protected] ~]# vim /etc/gshadow
[[email protected] ~]# mkdir /home/Natasha
[[email protected] ~]# ls -a /home/Natasha/
. ..

[[email protected] ~]# cp -r /etc/skel/.[!.]* /Natasha/

[[email protected] ~]# touch /var/spool/mail/Ntasha

[[email protected] ~]# id natasha
uid=1000(natasha) gid=555(natasha) 組=555(natasha)

3)  查看使用者資訊設定檔的最後一行

[[email protected] ~]# tail -1 /etc/passwd
natasha:x:1001:555:master:/home/Natasha:/bin/bash


4)  為natasha使用者佈建密碼“123”

[[email protected] ~]# passwd natasha
更改使用者 natasha 的密碼 。
新的 密碼:
無效的密碼: 密碼少於 8 個字元
重新輸入新的 密碼:
passwd:所有的身分識別驗證令牌已經成功更新。


5)  查看使用者密碼設定檔的最後一行

[[email protected] ~]# tail -1 /etc/shadow
natasha:$6$J9U/RNhi$YKp4XbjYxqhZo1QdFbS62hRzN5wGXxfUcGx80iJBIFuNcJSXeSZQ.Q2m8X/FeEECzK5EEQ0ooo3ivKymyL2Az0:17310:0:99999:7:::


6)  將natasha使用者賬戶鎖定

[[email protected] ~]# usermod -L natasha


7)  將natasha使用者賬戶解鎖

[[email protected] ~]# usermod -U natasha


8)  新群組police,gid為999

[[email protected] ~]# groupadd -g 999 police

police:x:999:


9)  查看組設定檔的最後一行

[[email protected] ~]# tail -1 /etc/group
police:x:999:


10) 將natasha使用者加入police組

[[email protected] ~]# usermod natasha -G police
[[email protected] ~]# id natasha
uid=1000(natasha) gid=555(natasha) 組=555(natasha),999(police)


11) 修改police組的組名為jingcha

[[email protected] ~]# groupmod -n jingcha police
[[email protected] ~]# tail -1 /etc/group
jingcha:x:999:natasha


12) 刪除natasha使用者,連家目錄和郵箱一起刪除

userdel -r natasha
13) 刪除jingcha組

[[email protected] ~]# groupdel jingcha
id[[email protected] ~]# tail /etc/group
sshd:x:74:
avahi:x:70:
slocate:x:21:
postdrop:x:90:
postfix:x:89:
stapusr:x:156:
stapsys:x:157:
stapdev:x:158:
tcpdump:x:72:
love:x:1000:love

二 建立目錄test

1)  在使用者的主目錄下建立目錄test,進入test建立空檔案file1

[[email protected] ~]# mkdir test
[[email protected] ~]# cd test
[[email protected] test]# touch file1

2)  以長格式形式顯示檔案資訊,注意檔案的許可權和所屬使用者和組

[[email protected] test]# ll
總用量 0
-rw-r--r--. 1 root root 0 5月 25 04:07 file1
3)  為檔案file1設定許可權,使其他使用者可以對此檔案進行寫操作。

[[email protected] test]# chmod o+w file1


4)  查看設定結果,

[[email protected] test]# ll
總用量 0
-rw-r--rw-. 1 root root 0 5月 25 04:07 file1
5)  取消同組使用者對檔案file1的讀取許可權,並查看設定結果。

[[email protected] test]# chmod g=- file1
[[email protected] test]# ll
總用量 0
-rw----rw-. 1 root root 0 5月 25 04:07 file1


6)  用數字標記法為檔案file設定許可權,所有者可讀、可寫、可執行,所屬組使用者和其他使用者只具有讀和執行的許可權。設定完成後查看設定結果。

[[email protected] test]# chmod 733 file1
[[email protected] test]# ll
總用量 0
-rwx-wx-wx. 1 root root 0 5月 25 04:07 file1


7)  用數字形式變更檔file1的許可權,使所有者只能讀取此檔案。其他任何使用者都沒有許可權。查看設定結果。

[[email protected] test]# chmod 400 file1
[[email protected] test]# ll
總用量 0
-r--------. 1 root root 0 5月 25 04:07 file1


8)  回到上層目錄,查看test的許可權

[[email protected] test]# cd ..
[[email protected] ~]# ll d test
ls: 無法訪問d: 沒有那個檔案或目錄
test:
總用量 0
-r--------. 1 root root 0 5月 25 04:07 file1


9)  為其他使用者添加對此目錄的寫入權限

[[email protected] ~]# chmod o+w test/

[[email protected] ~]# ll -d test
drwxr-xrwx. 2 root root 19 5月 25 04:07 test

三 以操作檔案的方式,建立一個使用者alex

1、[[email protected] ~]# vim /etc/passwd   ----->1,2 ---->編輯使用者檔案2、[[email protected] ~]# tail -1 /etc/passwd            添加新使用者,查看操作      alex:1111:1111::/home/alex:/bin/bash

3、[[email protected] ~]# vim /etc/shadow   ----->3,4 ---->編輯使用者密碼

4、[[email protected] ~]# tail -1 /etc/shadow           檔案,查看操作
        alex:!!:17310:0:99999:7:::

5、[[email protected] ~]# vim /etc/group  ------->5,6 ----->編輯組檔案

6、[[email protected] ~]# tail -1 /etc/group                       查看操作

        alex:x:1111:

7、[[email protected] ~]# vim /etc/gshadow  ---->7,8 --->編輯組密碼檔案

8、[[email protected] ~]# tail -1 /etc/gshadow                  查看操作

        alex:!::

9,10,11------>常見檔案,把使用者模板複製給alex使用者

9、[[email protected] ~]# mkdir /home/alex 

10、[[email protected] ~]# cp -r /etc/skel/.[!.]* /home/alex

11、[[email protected] ~]# ls -a /home/alex
         . .. .bash_logout .bash_profile .bashrc .mozilla

12,13,14---->由於使用者alex是‘root’使用者建立,更改使用者屬主與屬組,

                          改為alex

12、[[email protected] ~]# ll -d /home/alex

         drwxr-xr-x. 3 alex alex 78 5月 25 06:47 /home/alex

13、[[email protected] ~]# chown -R alex:alex /home/alex

14、[[email protected] ~]# touch /var/spool/mail/alex

15,16,17----->建立使用者郵箱,由於使用者alex是‘root‘使用者建立,更改屬主與屬組分別為alex、mail

15、[[email protected] ~]# chown -R alex:mail /var/spool/mail/alex

16、[[email protected] ~]# ll -d /var/spool/mail/alex
         -rw-r--r--. 1 alex mail 0 5月 25 06:56 /var/spool/mail/alex

17、[[email protected] ~]# id alex
         uid=1111(alex) gid=1111(alex) 組=1111(alex)

四 驗證許可權

 

1) 建立目錄/test/dir,屬主為tom,數組為group1,/test目錄的許可權為777

[[email protected] ~]# mkdir -p /test/dir
[[email protected] ~]# ll -d /test/dir
drwxr-xr-x. 2 root root 6 5月 25 22:26 /test/dir

[[email protected] ~]# useradd tom

[[email protected] ~]# groupadd group1

[[email protected] ~]# chown tom:group1 /test/dir/
[[email protected] ~]# ll -d /test/dir
drwxr-xr-x. 2 tom group1 6 5月 25 22:26 /test/dir

[[email protected] ~]# chmod 777 /test
[[email protected] ~]# ll -d /test
drwxrwxrwx. 3 root root 17 5月 25 22:26 /test


2) [[email protected] tmp]# mkdir test

[[email protected] ~]# cd /tmp
[[email protected] tmp]# mkdir test
3) [[email protected] tmp]# ll -d test

[[email protected] tmp]# ll -d test

 

4) drwxr-xr-x. 2 root root 6 5月 25 08:32 test

drwxr-xr-x. 2 root root 6 5月 25 22:40 test
2) 建立使用者jack,切換到jack使用者下,驗證jack使用者對dir目錄的rwx許可權(開啟另外一個終端,依次修改dir目錄的others許可權)

[[email protected] tmp]# useradd jack

[[email protected] tmp]# id jack
uid=1009(jack) gid=1011(jack) 組=1011(jack)

[[email protected] tmp]# su - jack
[[email protected] ~]$ ll /test/dir/
總用量 0

[[email protected] ~]# chmod o+w /test/dir/

[[email protected] ~]$ touch /test/dir/a.txt
[[email protected] ~]$ ll -d /test/dir/a.txt
-rw-rw-r--. 1 jack jack 0 5月 25 22:52 /test/dir/a.txt

[[email protected] ~]$ cd /test/dir/
[[email protected] dir]$ cd -
/home/jack

[[email protected] ~]# echo "date" > /test/dir/a.txt

[[email protected] ~]# chmod o-x /test/dir/
[[email protected] ~]# chmod o-r /test/dir/

 

 

3)將jack加入group1組,驗證jack使用者對dir目錄的rwx許可權(開啟另外一個終端,依次修改dir目錄的group許可權)

 

 

4)切換到tom使用者,驗證tom使用者對dir目錄的rwx許可權(開啟另外一個終端,依次修改dir目錄的user許可權)

 

 

5)在dir目錄內建立檔案tom.txt,屬主為tom,屬組為group1,/test目錄的許可權為777

 

 

6)建立使用者rose,切換到rose使用者下,驗證rose使用者對tom.txt的rwx許可權(開啟另外一個終端,依次修改tom.txt的others許可權來配合驗證過程)

 

 

7)將rose加入group1組,在rose使用者下,驗證rose使用者對tom.txt的rwx許可權(開啟另外一個終端,依次修改tom.txt的group1許可權來配合驗證過程)

 

 

8)切換到tom使用者,驗證tom使用者對tom.txt的rwx許可權(開啟另外一個終端,依次修改tom.txt的user許可權來配合驗證過程)

 

4、linux建組

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.