Linux 使用者
/etc/passwd
檔案解釋:
root:x:0:0:root:/root:/bin/bash
使用者名:密碼:UID:GID:注釋性描述:家目錄:登入Shell
備注:UID 和 GID 為 0 即有 root 權限。在 1000 以内的 UID 為系統保留。
/etc/shadow
檔案解釋:
devops:$1$Lrm8gMZ.$Shta9mJZB0/1ReF3BTOg5lUav1:18067:0:99999:7:::
使用者名:密碼:最後一次修改時間:最小時間間隔:最大時間間隔:警告時間:不活動時間:失效時間:标志
檢視密碼政策:
[[email protected] ~]# chage -l root
Last password change : Jun 20, 2019
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7
最近一次密碼修改時間 :3月 12, 2013
密碼過期時間 :從不
密碼失效時間 :從不
帳戶過期時間 :從不
兩次改變密碼之間相距的最小天數 :0
兩次改變密碼之間相距的最大天數 :99999
在密碼過期之前警告的天數 :7
将使用者密碼立即過期:
[ro[email protected] ~]# chage -d 0 user01
[[email protected] ~]# chage -l user01
最近一次密碼修改時間 :密碼必須更改
密碼過期時間 :密碼必須更改
密碼失效時間 :密碼必須更改
帳戶過期時間 :從不
兩次改變密碼之間相距的最小天數 :0
兩次改變密碼之間相距的最大天數 :99999
在密碼過期之前警告的天數 :7
[c:\~]$ ssh [email protected]
Connecting to 192.168.1.24:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
You are required to change your password immediately (root enforced)
Last login: Tue Apr 24 21:04:22 2018 from 192.168.1.5
WARNING: Your password has expired.
You must change your password now and login again!
chage
指令用法補充:chage 修改帳号和密碼的有效期限
添加使用者:
useradd test # 添加名為 test 的使用者
-s<shell> 指定使用者登入後所使用的shell
-g<群組> 指定使用者所屬的群組。
-G<群組> 指定使用者所屬的附加群組。
-u<uid> 指定使用者ID。
-d<登入目錄> 指定使用者登入時的家目錄。
删除使用者:
userdel -r test # 删除名為 test 的使用者,同時删除對應的 home 目錄
修改使用者:
usermod -u 777 root # 修改 root 的 UID 為777
-s<shell> 修改使用者登入後所使用的shell
-g<群組> 修改使用者所屬的群組。
-G<群組> 修改使用者所屬的附加群組。
-l<帳号名稱> 修改使用者帳号名稱。
-d登入目錄> 修改使用者登入時的家目錄。
檢視使用者 UID:
[[email protected] network-scripts]# id devops
uid=12345(devops) gid=12345(devops) groups=12345(devops)
其他指令:
-
:查詢目前線上使用者who
-
:查詢目前線上使用者的詳細資訊w
-
:查詢目前使用者所屬的組groups
使用指令行修改密碼:
echo "redhat" | passwd --stdin root