1. 程式人生 > 其它 >Linux之使用者管理

Linux之使用者管理

1,Linux使用者是什麼?

能正常登入LinuxWindows系統的都稱之為使用者。

1.1,使用者的作用究竟是什麼呢?

  • 1,系統上的每一個程序(執行的程式),都需要一個特定的使用者執行。
  • 2,因為root許可權太大,容易造成故障,所以通常在公司是使用普通使用者管理伺服器,。

1.2,使用者有哪些分類

使用者UID(User ID) 系統中約定的含義
0 超級管理員,擁有最高許可權,有著極強的破壞能力rm -rf /*
1~200 系統使用者,用來執行系統自帶的程序,預設已建立
201~999 系統使用者,用來執行使用者安裝的程式,所以此類使用者無需登入系統
1000+ 普通使用者,正常可以登入系統的使用者,許可權比較小,能執行的任務有限

1.3 查詢使用者ID資訊

  • 使用id命令查詢當前登入使用者的資訊
[[email protected]: ~]#id #當前使用者
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

[[email protected]: ~]#id carol #i檢視其它使用者資訊
uid=1000(carol) gid=1000(carol) groups=1000(carol)

1.4 使用者相關配置檔案

  • 當我們建立一個新的使用者,系統會將使用者的資訊存放在/etc/passwd
    中,而密碼資訊則單獨儲存在/etc/shadow中,也就是說這兩個檔案非常的重要,不要輕易的刪除和修改。
    1.4.1 passwd檔案
  • /etc/passwd 配置檔案解釋如下圖,或者也可以使用命令man 5 passwd獲取幫助

1.4.2 shadow檔案

  • /etc/shadow配置檔案解釋如下圖,或者使用命令 man 5 shadow獲取幫助

  • 如何使用change命令改變密碼的屬性


-d //設定最近一次更改密碼時間, 0下次登陸系統強制修改密碼
-m //設定使用者兩次改變密碼之間使用"最小天數"
-M //設定使用者兩次改變密碼之間使用"最大天數" 
-W //設定密碼更改警告時間 將過期警告天數設為“警告天數” 
-I //設定密碼過期天數後, 密碼為失效狀態 
-E //設定使用者過期時間, 賬戶失效後無法登陸 
-l //顯示使用者資訊 


#修改時間為2014年08月31日,和圖中時間匹配,方便後續驗證 
[root@carol ~]# date -s '20140831' 
Sun Aug 31 00:00:00 CST 2014 
[root@carol ~]# date 
Sun Aug 31 00:00:01 CST 2014 
[root@carol ~]# usereadd bgx1 
[root@carol ~]# echo "123" |passwd --stdin bgx1 
[root@carol ~]# tail -1 /etc/shadow 
bgx1:!!:16312:0:99999:7::: 


#設定最近一次修改密碼時間 
[root@carol ~]# chage -d "2014-09-01" bgx1 
[root@carol ~]# tail -n1 /etc/shadow 
bgx1:!!:16314:0:99999:7::: 


#設定最短使用密碼時間 
[root@carol ~]# chage -m 2 bgx1 
[root@carol ~]# tail -n1 /etc/shadow 
bgx1:!!:16314:2:99999:7::: 

#設定密碼最長使用時間 
[root@carol ~]# chage -M 15 bgx1 
[root@carol ~]# tail -n1 /etc/shadow 
bgx1:!!:16314:2:15:7::: 

#設定密碼警告時間 
[root@carol ~]# chage -W 6 bgx1 
[root@carol ~]# tail -n1 /etc/shadow 
bgx1:!!:16314:2:15:6::: 
[root@carol ~]# chage -W 7 bgx1 
[root@carol ~]# tail -n1 /etc/shadow 
bgx1:!!:16314:2:15:7:::


#設定密碼過期時間 
[root@carol ~]# chage -I 5 bgx1 
[root@carol ~]# tail -n1 /etc/shadow 
bgx1:!!:16314:2:15:6:5:: 
#設定使用者過期時間 
[root@carol ~]# chage -E "20115-08-31" bgx1 
[root@carol ~]# tail -n1 /etc/shadow bgx1:!!:16314:2:15:6:5:6627567: 
[root@carol ~]# chage -l bgx1 
Last password change : Sep 01, 2014 #最近一次更改密碼時間 
Password expires : Sep 16, 2014 #密碼過期時間 
Password inactive : Sep 21, 2014 #密碼失效時間 
Account expires : Aug 31, 2015 #使用者失效時間 
Minimum number of days between password change : 2 #密碼最短使用時間 
Maximum number of days between password change : 15 #密碼最長使用時間 
Number of days of warning before password expires : 7 #密碼過期前警告天數 


#如何驗證,只調整時間為如下進行驗證: 
1.驗證普通使用者是否能修改密碼, 不需要調整時間。
2.普通使用者登陸系統後, 會提示警告密碼還剩多少天過期 
[root@carol ~]# date -s "2014-09-12" 

3.普通使用者登陸系統後, 強制要求修改密碼 
[root@carol ~]# date -s "2014-09-18" 

4.普通使用者登陸系統後, 提示賬戶已過期 
[root@carol ~]# date -s "2014-09-23"