groupadd,useradd,passwd,gpasswd,id,su
groupadd
- image.png
- 命令演示
[root@localhost ~]# tail /etc/group
tail /etc/group
rpcuser:x:29:
nfsnobody:x:65534:
gnome-initial-setup:x:985:
stapusr:x:156:
stapsys:x:157:
stapdev:x:158:
slocate:x:21:
ntp:x:38:
avahi:x:70:
tcpdump:x:72:
[root@localhost ~]#
[root@localhost ~]# groupadd redhat
[root@localhost ~]# tail -1 /etc/group
redhat:x:1000:
[root@localhost ~]# groupadd -g 1010 redhat1
[root@localhost ~]# tail -2 /etc/group
redhat:x:1000:
redhat1:x:1010:
[root@localhost ~]# groupadd redhat2
[root@localhost ~]# tail -3 /etc/group
redhat:x:1000:
redhat1:x:1010:
redhat2:x:1011:
[root@localhost ~]# groupadd -r sysred
[root@localhost ~]# tail -3 /etc/group
redhat1:x:1010:
redhat2:x:1011:
sysred:x:984:
[root@localhost ~]# groupadd -r sysred1
[root@localhost ~]# tail -3 /etc/group
redhat2:x:1011:
sysred:x:984:
sysred1:x:983:
groupmod
- image.png
命令演示
[root@localhost ~]# tail -5 /etc/group
redhat:x:1000:
redhat1:x:1010:
redhat2:x:1011:
sysred:x:984:
sysred1:x:983:
[root@localhost ~]# groupmod -g 1001 redhat
[root@localhost ~]# tail -5 /etc/group
redhat:x:1001:
redhat1:x:1010:
redhat2:x:1011:
sysred:x:984:
sysred1:x:983:
[root@localhost ~]# groupmod -n redhat3 redhat2
[root@localhost ~]# tail -5 /etc/group
redhat:x:1001:
redhat1:x:1010:
sysred:x:984:
sysred1:x:983:
redhat3:x:1011:
[root@localhost ~]#
groupdel
- image.png
命令演示
[root@localhost ~]# groupdel redhat
[root@localhost ~]# tail -5 /etc/group
tcpdump:x:72:
redhat1:x:1010:
sysred:x:984:
sysred1:x:983:
redhat3:x:1011:
[root@localhost ~]# groupdel redhat1
[root@localhost ~]# groupdel redhat3
[root@localhost ~]# groupdel sysred
[root@localhost ~]# groupdel sysred1
[root@localhost ~]# tail -5 /etc/group
stapdev:x:158:
slocate:x:21:
ntp:x:38:
avahi:x:70:
tcpdump:x:72:
[root@localhost ~]#
useradd
- image.png
命令演示
[root@localhost ~]# tail -5 /etc/passwd
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
gnome-initial-setup:x:990:985::/run/gnome-initial-setup/:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
[root@localhost ~]# useradd centos
[root@localhost ~]# useradd -u 1005 fedora
[root@localhost ~]# useradd suse
[root@localhost ~]# !tail
tail -5 /etc/passwd
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
centos:x:1000:1000::/home/centos:/bin/bash
fedora:x:1005:1005::/home/fedora:/bin/bash
suse:x:1006:1006::/home/suse:/bin/bash
[root@localhost ~]# groupadd redhat
[root@localhost ~]# groupadd redhat1
[root@localhost ~]# tail -5 /etc/group
centos:x:1000:
fedora:x:1005:
suse:x:1006:
redhat:x:1007:
redhat1:x:1008:
[root@localhost ~]# id centos
uid=1000(centos) gid=1000(centos) 組=1000(centos)
[root@localhost ~]# useradd -G redhat,redhat1 centos
useradd:用戶“centos”已存在
[root@localhost ~]# id centos
uid=1000(centos) gid=1000(centos) 組=1000(centos)
[root@localhost ~]# useradd -G redhat,redhat1 rhel
[root@localhost ~]# id rhel
uid=1007(rhel) gid=1009(rhel) 組=1009(rhel),1007(redhat),1008(redhat1)
[root@localhost ~]# useradd -c 'i am a family of redhat' centos1
[root@localhost ~]# tail -1 /etc/passwd
centos1:x:1008:1010:i am a family of redhat:/home/centos1:/bin/bash
[root@localhost ~]# mkdir /tmp/centos2
[root@localhost ~]# ls -a /tmp/centos2
. ..
[root@localhost ~]# useradd -d /tmp/centos2 centos2
useradd:警告:此主目錄已經存在。
不從 skel 目錄里向其中復制任何文件。
[root@localhost ~]# tail -1 /etc/passwd
centos2:x:1009:1011::/tmp/centos2:/bin/bash
[root@localhost ~]# ls -a /tmp/centos2
. ..
[root@localhost tmp]# ls -d /tmp/cent*
/tmp/centos2
[root@localhost tmp]# useradd -d /tmp/centos3 centos3
useradd: cannot set SELinux context for home directory /tmp/centos3
[root@localhost tmp]# setenforce 0
[root@localhost tmp]# useradd -d /tmp/centos3 centos3
useradd:用戶“centos3”已存在
[root@localhost tmp]# ls -d /tmp/cent*
/tmp/centos2
[root@localhost tmp]# tail -1 /etc/passwd
centos3:x:1010:1012::/tmp/centos3:/bin/bash
[root@localhost tmp]# userdel -r centos3
userdel: centos3 郵件池 (/var/spool/mail/centos3) 未找到
userdel:未找到 centos3 的主目錄“/tmp/centos3”
[root@localhost tmp]# useradd -d /tmp/centos3 centos3
[root@localhost tmp]# ls -d /tmp/cent*
/tmp/centos2 /tmp/centos3
[root@localhost tmp]# ls -a /tmp/centos3/
. .. .bash_logout .bash_profile .bashrc .mozilla
[root@localhost tmp]# ls -a /etc/skel/
. .. .bash_logout .bash_profile .bashrc .mozilla
[root@localhost tmp]# tail -2 /etc/passwd
suse:x:1006:1006::/home/suse:/bin/bash
rhel:x:1007:1009::/home/rhel:/bin/bash
centos1:x:1008:1010:i am a family of redhat:/home/centos1:/bin/bash
centos2:x:1009:1011::/tmp/centos2:/bin/bash
centos3:x:1010:1012::/tmp/centos3:/bin/bash
[root@localhost ~]# cd ~centos2
[root@localhost centos2]# pwd
/tmp/centos2
[root@localhost centos2]# ll -d
drwxr-xr-x. 2 root root 6 7月 25 22:05 .
[root@localhost centos2]# cd ~centos3
[root@localhost centos3]# pwd
/tmp/centos3
[root@localhost centos3]# ll -d
drwx------. 3 centos3 centos3 78 7月 25 22:21 .
[root@localhost ~]# useradd -M centos4
[root@localhost ~]# ll /home
總用量 0
drwx------. 3 centos centos 78 7月 25 21:56 centos
drwx------. 3 centos1 centos1 78 7月 25 22:04 centos1
drwx------. 3 fedora fedora 78 7月 25 21:56 fedora
drwx------. 3 rhel rhel 78 7月 25 22:02 rhel
drwx------. 3 suse suse 78 7月 25 21:57 suse
[root@localhost ~]# tail -2 /etc/passwd
centos3:x:1010:1012::/tmp/centos3:/bin/bash
centos4:x:1011:1013::/home/centos4:/bin/bash
[root@localhost ~]# cd ~centos4
-bash: cd: /home/centos4: 沒有那個文件或目錄
[root@localhost ~]# cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin
/bin/tcsh
/bin/csh
[root@localhost ~]# useradd -s /bin/sh centos5
[root@localhost ~]# tail -2 /etc/passwd
centos4:x:1011:1013::/home/centos4:/bin/bash
centos5:x:1012:1014::/home/centos5:/bin/sh
[root@localhost ~]# useradd -s /bin/zsh centos6
[root@localhost ~]# tail -2 /etc/passwd
centos5:x:1012:1014::/home/centos5:/bin/sh
centos6:x:1013:1015::/home/centos6:/bin/zsh
[root@localhost ~]# useradd -r syscent
[root@localhost ~]# tail -2 /etc/passwd
centos6:x:1013:1015::/home/centos6:/bin/zsh
syscent:x:989:984::/home/syscent:/bin/bash
[root@localhost ~]# useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
[root@localhost ~]# useradd -D -b /tmp
[root@localhost ~]# useradd -D -f 0
[root@localhost ~]# useradd -D -s /etc/csh
[root@localhost ~]# useradd -D
GROUP=100
HOME=/tmp
INACTIVE=0
EXPIRE=
SHELL=/etc/csh
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
[root@localhost ~]# useradd centos7
[root@localhost ~]# tail -2 /etc/passwd
syscent:x:989:984::/home/syscent:/bin/bash
centos7:x:1014:1016::/home/centos7:/etc/csh
[root@localhost ~]# useradd -D -s /etc/bash
[root@localhost ~]# useradd -D -b /home
[root@localhost ~]# useradd -D -s /etc/bash
[root@localhost ~]# useradd -D -f -1
[root@localhost ~]# useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/etc/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
[root@localhost ~]# cat /etc/default/useradd
# useradd defaults file
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/etc/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
[root@localhost ~]#
usermod
- image.png
命令演示
[root@localhost ~]# tail /etc/passwd
suse:x:1006:1006::/home/suse:/bin/bash
rhel:x:1007:1009::/home/rhel:/bin/bash
centos1:x:1008:1010:i am a family of redhat:/home/centos1:/bin/bash
centos2:x:1009:1011::/tmp/centos2:/bin/bash
centos3:x:1010:1012::/tmp/centos3:/bin/bash
centos4:x:1011:1013::/home/centos4:/bin/bash
centos5:x:1012:1014::/home/centos5:/bin/sh
centos6:x:1013:1015::/home/centos6:/bin/zsh
syscent:x:989:984::/home/syscent:/bin/bash
centos7:x:1014:1016::/home/centos7:/etc/csh
[root@localhost ~]# usermod -u 1018 centos1
[root@localhost ~]# tail /etc/passwd
suse:x:1006:1006::/home/suse:/bin/bash
rhel:x:1007:1009::/home/rhel:/bin/bash
centos1:x:1018:1010:i am a family of redhat:/home/centos1:/bin/bash
centos2:x:1009:1011::/tmp/centos2:/bin/bash
centos3:x:1010:1012::/tmp/centos3:/bin/bash
centos4:x:1011:1013::/home/centos4:/bin/bash
centos5:x:1012:1014::/home/centos5:/bin/sh
centos6:x:1013:1015::/home/centos6:/bin/zsh
syscent:x:989:984::/home/syscent:/bin/bash
centos7:x:1014:1016::/home/centos7:/etc/csh
[root@localhost ~]# usermod -g redhat centos1
[root@localhost ~]# usermod -g 1007 centos2
[root@localhost ~]# tail /etc/passwd
suse:x:1006:1006::/home/suse:/bin/bash
rhel:x:1007:1009::/home/rhel:/bin/bash
centos1:x:1018:1007:i am a family of redhat:/home/centos1:/bin/bash
centos2:x:1009:1007::/tmp/centos2:/bin/bash
centos3:x:1010:1012::/tmp/centos3:/bin/bash
centos4:x:1011:1013::/home/centos4:/bin/bash
centos5:x:1012:1014::/home/centos5:/bin/sh
centos6:x:1013:1015::/home/centos6:/bin/zsh
syscent:x:989:984::/home/syscent:/bin/bash
centos7:x:1014:1016::/home/centos7:/etc/csh
[root@localhost ~]# id centos1
uid=1018(centos1) gid=1007(redhat) 組=1007(redhat)
[root@localhost ~]# usermod -G centos centos1
[root@localhost ~]# id centos1
uid=1018(centos1) gid=1007(redhat) 組=1007(redhat),1000(centos)
[root@localhost ~]# tail -15 /etc/group
tcpdump:x:72:
centos:x:1000:centos1
fedora:x:1005:
suse:x:1006:
redhat:x:1007:rhel
redhat1:x:1008:rhel
rhel:x:1009:
centos1:x:1010:
centos2:x:1011:
centos3:x:1012:
centos4:x:1013:
centos5:x:1014:
centos6:x:1015:
syscent:x:984:
centos7:x:1016:
[root@localhost ~]# id centos1
uid=1018(centos1) gid=1007(redhat) 組=1007(redhat),1000(centos)
[root@localhost ~]# usermod -G rhel centos1
[root@localhost ~]# id centos1
uid=1018(centos1) gid=1007(redhat) 組=1007(redhat),1009(rhel)
[root@localhost ~]# tail -15 /etc/group
tcpdump:x:72:
centos:x:1000:
fedora:x:1005:
suse:x:1006:
redhat:x:1007:rhel
redhat1:x:1008:rhel
rhel:x:1009:centos1
centos1:x:1010:
centos2:x:1011:
centos3:x:1012:
centos4:x:1013:
centos5:x:1014:
centos6:x:1015:
syscent:x:984:
centos7:x:1016:
[root@localhost ~]# usermod -aG redhat centos1
[root@localhost ~]# usermod -aG 1000 centos1
[root@localhost ~]# id centos1
uid=1018(centos1) gid=1007(redhat) 組=1007(redhat),1000(centos),1009(rhel)
[root@localhost ~]# tail -15 /etc/group
tcpdump:x:72:
centos:x:1000:centos1
fedora:x:1005:
suse:x:1006:
redhat:x:1007:rhel,centos1
redhat1:x:1008:rhel
rhel:x:1009:centos1
centos1:x:1010:
centos2:x:1011:
centos3:x:1012:
centos4:x:1013:
centos5:x:1014:
centos6:x:1015:
syscent:x:984:
centos7:x:1016:
[root@localhost ~]# usermod -c 'also is rhel' centos1
[root@localhost ~]# tail /etc/passwd
suse:x:1006:1006::/home/suse:/bin/bash
rhel:x:1007:1009::/home/rhel:/bin/bash
centos1:x:1018:1007:also is rhel:/home/centos1:/bin/bash
centos2:x:1009:1007::/tmp/centos2:/bin/bash
centos3:x:1010:1012::/tmp/centos3:/bin/bash
centos4:x:1011:1013::/home/centos4:/bin/bash
centos5:x:1012:1014::/home/centos5:/bin/sh
centos6:x:1013:1015::/home/centos6:/bin/zsh
syscent:x:989:984::/home/syscent:/bin/bash
centos7:x:1014:1016::/home/centos7:/etc/csh
[root@localhost ~]# ls /tmp/cent*
/tmp/centos2:
/tmp/centos3:
[root@localhost ~]# tail /etc/passwd
suse:x:1006:1006::/home/suse:/bin/bash
rhel:x:1007:1009::/home/rhel:/bin/bash
centos1:x:1018:1007:also is rhel:/home/centos1:/bin/bash
centos2:x:1009:1007::/tmp/centos2:/bin/bash
centos3:x:1010:1012::/tmp/centos3:/bin/bash
centos4:x:1011:1013::/home/centos4:/bin/bash
centos5:x:1012:1014::/home/centos5:/bin/sh
centos6:x:1013:1015::/home/centos6:/bin/zsh
syscent:x:989:984::/home/syscent:/bin/bash
centos7:x:1014:1016::/home/centos7:/etc/csh
[root@localhost ~]# usermod -d /tmp/centos4 centos4
[root@localhost ~]# tail /etc/passwd
suse:x:1006:1006::/home/suse:/bin/bash
rhel:x:1007:1009::/home/rhel:/bin/bash
centos1:x:1018:1007:also is rhel:/home/centos1:/bin/bash
centos2:x:1009:1007::/tmp/centos2:/bin/bash
centos3:x:1010:1012::/tmp/centos3:/bin/bash
centos4:x:1011:1013::/tmp/centos4:/bin/bash
centos5:x:1012:1014::/home/centos5:/bin/sh
centos6:x:1013:1015::/home/centos6:/bin/zsh
syscent:x:989:984::/home/syscent:/bin/bash
centos7:x:1014:1016::/home/centos7:/etc/csh
[root@localhost ~]# !ls
ls /tmp/cent*
/tmp/centos2:
/tmp/centos3:
[root@localhost ~]# cd ~centos4
-bash: cd: /tmp/centos4: 沒有那個文件或目錄
[root@localhost ~]# ls -a /home/centos5
. .. .bash_logout .bash_profile .bashrc .mozilla
[root@localhost ~]# usermod -md /tmp/centos5 centos5
[root@localhost ~]# tail /etc/passwd
suse:x:1006:1006::/home/suse:/bin/bash
rhel:x:1007:1009::/home/rhel:/bin/bash
centos1:x:1018:1007:also is rhel:/home/centos1:/bin/bash
centos2:x:1009:1007::/tmp/centos2:/bin/bash
centos3:x:1010:1012::/tmp/centos3:/bin/bash
centos4:x:1011:1013::/tmp/centos4:/bin/bash
centos5:x:1012:1014::/tmp/centos5:/bin/sh
centos6:x:1013:1015::/home/centos6:/bin/zsh
syscent:x:989:984::/home/syscent:/bin/bash
centos7:x:1014:1016::/home/centos7:/etc/csh
[root@localhost ~]# ls -a /tmp/cent*
/tmp/centos2:
. ..
/tmp/centos3:
. .. .bash_logout .bash_profile .bashrc .mozilla
/tmp/centos5:
. .. .bash_logout .bash_profile .bashrc .mozilla
[root@localhost ~]# cd ~centos5
[root@localhost centos5]# pwd
/tmp/centos5
[root@localhost ~]# tail -3 /etc/passwd
centos7:x:1014:1016::/home/centos7:/etc/csh
centos6:x:1013:1015::/home/centos6:/bin/zsh
centos:x:1001:1000::/home/centos:/bin/bash
[root@localhost ~]# usermod -l CENTOS6 centos6
[root@localhost ~]# tail -3 /etc/passwd
centos7:x:1014:1016::/home/centos7:/etc/csh
centos:x:1001:1000::/home/centos:/bin/bash
CENTOS6:x:1013:1015::/home/centos6:/bin/zsh
[root@localhost ~]# usermod -s /bin/bash CENTOS6
[root@localhost ~]# tail -3 /etc/passwd
centos7:x:1014:1016::/home/centos7:/etc/csh
centos:x:1001:1000::/home/centos:/bin/bash
CENTOS6:x:1013:1015::/home/centos6:/bin/bash
[root@localhost ~]# tail -3 /etc/shadow
centos7:$6$PcwwrZ6y$OhQHjDxBQPlMYd6gYasW2119EJlTbnV...iqx8gUhJaBDerqNy4UIrmbvFhDTQrjlWl0yPG/sx1xDUISBpxO0.:17373:0:99999:7:::
centos:!!:17372:0:99999:7:::
CENTOS6:!!:17372:0:99999:7:::
[root@localhost ~]# usermod -L centos7 \centos7的加密密碼前面多一個"!"號
[root@localhost ~]# tail -3 /etc/shadow
centos7:!$6$PcwwrZ6y$OhQHjDxBQPlMYd6gYasW2119EJlTbnV...iqx8gUhJaBDerqNy4UIrmbvFhDTQrjlWl0yPG/sx1xDUISBpxO0.:17373:0:99999:7:::
centos:!!:17372:0:99999:7:::
CENTOS6:!!:17372:0:99999:7:::
[root@localhost ~]# su - centos1
上一次登錄:三 7月 26 11:45:44 CST 2017pts/3 上
[centos1@localhost ~]$ pwd
/home/centos1
[centos1@localhost ~]$ su - centos7
密碼:
su: 鑒定故障
[centos1@localhost ~]$ su - centos7
密碼:
su: 鑒定故障
[centos1@localhost ~]$ su - centos7 \\由于centos7的密碼被鎖定,不能從centos1切到用戶centos7
密碼:
su: 鑒定故障
[centos1@localhost ~]$ exit
登出
[root@localhost ~]# pwd
/root
[root@localhost ~]# usermod -U centos7
[root@localhost ~]# !tail
tail -5 /etc/shadow
centos5:!!:17372:0:99999:7:::
syscent:!!:17372::::::
centos7:$6$PcwwrZ6y$OhQHjDxBQPlMYd6gYasW2119EJlTbnV...iqx8gUhJaBDerqNy4UIrmbvFhDTQrjlWl0yPG/sx1xDUISBpxO0.:17373:0:99999:7:::
centos:!!:17372:0:99999:7:::
CENTOS6:!!:17372:0:99999:7:::
[root@localhost ~]# su - centos1
上一次登錄:三 7月 26 11:47:13 CST 2017pts/3 上
[centos1@localhost ~]$ pwd
/home/centos1
[centos1@localhost ~]$ su - centos7 \\centos7的密碼解鎖后,從centos1切到用戶centos7
密碼:
上一次登錄:三 7月 26 11:46:11 CST 2017pts/3 上
最后一次失敗的登錄:三 7月 26 11:47:52 CST 2017pts/3 上
最有一次成功登錄后有 3 次失敗的登錄嘗試。
[centos7@localhost ~]$
[centos7@localhost ~]$
[centos7@localhost ~]$ pwd
/home/centos7
[centos7@localhost ~]$
userdel
- image.png
- 命令演示
[root@localhost ~]# tail /etc/passwd
rhel:x:1007:1009::/home/rhel:/bin/bash
centos1:x:1018:1007:also is rhel:/home/centos1:/bin/bash
centos2:x:1009:1007::/tmp/centos2:/bin/bash
centos3:x:1010:1012::/tmp/centos3:/bin/bash
centos4:x:1011:1013::/tmp/centos4:/bin/bash
centos5:x:1012:1014::/tmp/centos5:/bin/sh
syscent:x:989:984::/home/syscent:/bin/bash
centos7:x:1014:1016::/home/centos7:/bin/bash
centos:x:1001:1000::/home/centos:/bin/bash
CENTOS6:x:1013:1015::/home/centos6:/bin/bash
[root@localhost ~]# lls /home
bash: lls: 未找到命令...
相似命令是: 'ls'
[root@localhost ~]# ll /home
總用量 0
drwx------. 3 centos centos 78 7月 25 21:56 centos
drwx------. 5 centos1 redhat 128 7月 26 11:46 centos1
drwx------. 3 CENTOS6 centos6 78 7月 25 22:26 centos6
drwx------. 5 centos7 centos7 128 7月 26 11:42 centos7
drwx------. 3 fedora fedora 78 7月 25 21:56 fedora
drwx------. 3 rhel rhel 78 7月 25 22:02 rhel
drwx------. 3 suse suse 78 7月 25 21:57 suse
[root@localhost ~]# ls /tmp/cen*
/tmp/centos2:
/tmp/centos3:
/tmp/centos5:
[root@localhost ~]# ls -d /tmp/cen*
/tmp/centos2 /tmp/centos3 /tmp/centos5
[root@localhost ~]# ls -a /tmp/cen*
/tmp/centos2:
. ..
/tmp/centos3:
. .. .bash_logout .bash_profile .bashrc .mozilla
/tmp/centos5:
. .. .bash_logout .bash_profile .bashrc .mozilla
[root@localhost ~]# userdel centos6
userdel:用戶“centos6”不存在
[root@localhost ~]# userdel CENTOS6
[root@localhost ~]# userdel -r centos7
[root@localhost ~]# userdel centos3
[root@localhost ~]# userdel -r centos5
[root@localhost ~]# ll /home
總用量 0
drwx------. 3 centos centos 78 7月 25 21:56 centos
drwx------. 5 centos1 redhat 128 7月 26 11:46 centos1
drwx------. 3 1013 centos6 78 7月 25 22:26 centos6
drwx------. 3 fedora fedora 78 7月 25 21:56 fedora
drwx------. 3 rhel rhel 78 7月 25 22:02 rhel
drwx------. 3 suse suse 78 7月 25 21:57 suse
[root@localhost ~]# ll /tmp/cent*
/tmp/centos2:
總用量 0
/tmp/centos3:
總用量 0
[root@localhost ~]# ll -d /tmp/cent*
drwxr-xr-x. 2 root root 6 7月 25 22:05 /tmp/centos2
drwx------. 3 1010 1012 78 7月 25 22:21 /tmp/centos3
[root@localhost ~]#
[root@localhost ~]# userdel -r centos
userdel:組“centos”沒有移除,因為它包含其它成員。
userdel:/var/spool/mail/centos 并不屬于 centos,所以不會刪除
[root@localhost ~]# userdel -r centos1
userdel:組“centos1”沒有移除,因為它不是用戶 centos1 的主組
[root@localhost ~]# userdel -r centos2
userdel:組“centos2”沒有移除,因為它不是用戶 centos2 的主組
userdel:/tmp/centos2 并不屬于 centos2,所以不會刪除
[root@localhost ~]# userdel -r centos3
userdel:用戶“centos3”不存在
[root@localhost ~]# userdel -r centos4
userdel:未找到 centos4 的主目錄“/tmp/centos4”
passwd
- image.png
- -k 選項以上的中文解釋偏差較大,本人在網(wǎng)上搜索的解釋也多種多樣,只好粘出英文原文“ The option -k is used to indicate that the update should only be for expired authentication tokens (passwords)”;大家自會理解吧。
- 我的一種理解是只用來更新過期的認證令牌,一個賬戶只有一個paaswd,要么過期了,要么沒過期,難道一個賬戶可以有多個passwd,不同的過期時間?即使是這樣,使用該選項又怎么知道到底更新的是那個過期的passwd呢?
- 我的另一種理解是,在設置用戶passwd時,passwd -k USERNAME,這樣就設置了用戶只有在passwd過期后才能更新自己的passwd,期限內是無法自己通過passwd更改自己的passwd的。但我演示了操作,沒有預想的結果。唯一的不同就是,如下的加粗部分
[root@localhost ~]# useradd centos7 \\新增一普通用戶
[root@localhost ~]# tail -1 /etc/passwd \\密碼為空
centos7:x:1003:1003::/home/centos7:/bin/bash
[root@localhost ~]# tail -1 /etc/shadow
centos7:!!:17381:0:99999:7:::
[root@localhost ~]#
[root@localhost ~]# passwd -k centos7
更改用戶 centos7 的密碼 。
為 centos7 更改 STRESS 密碼。
(當前)UNIX 密碼:
passwd: 鑒定令牌操作錯誤
[root@localhost ~]# passwd -S centos7 \\新建賬戶,密碼為空,默認賬戶被鎖定
centos7 LK 2017-08-03 0 99999 7 -1 (密碼已被鎖定。)
[root@localhost ~]# passwd centos7 \\顯設置個passwd
更改用戶 centos7 的密碼 。
新的 密碼:
重新輸入新的 密碼:
passwd:所有的身份驗證令牌已經成功更新。
[root@localhost ~]# chage -l centos7
最近一次密碼修改時間 :8月 03, 2017
密碼過期時間 :從不
密碼失效時間 :從不
帳戶過期時間 :從不
兩次改變密碼之間相距的最小天數(shù) :0
兩次改變密碼之間相距的最大天數(shù) :99999
在密碼過期之前警告的天數(shù) :7
[root@localhost ~]# passwd -x 10 centos7 \\自定義用戶passwd過期時間為10天后
調整用戶密碼老化數(shù)據(jù)centos7。
passwd: 操作成功
[root@localhost ~]# chage -l centos7 \\passwd密碼到8月13日才會過期
最近一次密碼修改時間 :8月 03, 2017
密碼過期時間 :8月 13, 2017
密碼失效時間 :從不
帳戶過期時間 :從不
兩次改變密碼之間相距的最小天數(shù) :0
兩次改變密碼之間相距的最大天數(shù) :10
在密碼過期之前警告的天數(shù) :7
[root@localhost ~]#
[root@localhost ~]# passwd -k centos7 \\選項k
更改用戶 centos7 的密碼 。
為 centos7 更改 STRESS 密碼。
(當前)UNIX 密碼:
新的 密碼:
重新輸入新的 密碼:
passwd:過期的身份驗證令牌已經成功更新。
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# su - centos2
上一次登錄:日 8月 13 09:00:12 CST 2017pts/1 上
[centos2@localhost ~]$ su - centos7
密碼:
[centos7@localhost ~]$ passwd \\期限內更改密碼,依然可以修改
更改用戶 centos7 的密碼 。
為 centos7 更改 STRESS 密碼。
(當前)UNIX 密碼:
新的 密碼:
重新輸入新的 密碼:
passwd:所有的身份驗證令牌已經成功更新。
[centos7@localhost ~]$ - 以上兩個疑問,可能是自己對選項k的理解有誤吧(大家不要被誤導,希望看到的可以不吝賜教,留言噢。),但google了,百度了,都沒有k的用法示例。沒能解決真夠郁悶的,整整糾結兩個晚上了,沒辦法只有把我的疑問寫出來,以抒心中塊壘了!!!現(xiàn)在內心還是一疙瘩。
- 命令演示
- 演示之前,先說一下幾個天數(shù)的計算原則
- -x DAYS,如days=5,5天后過期,不含命令最后一次修改時間的當天,且都以日為單位計算,以UTC時區(qū)記錄時間。如密碼最新更改為3日,則過完8日后,即到9日00:00:00后,密碼就過期了,用戶需在下次登錄修改密碼
- -n DAYS,如days=2,2天內用戶無法自行修改密碼,含命令最后一次修改時間的當天,且都以日為單位計算,以UTC時區(qū)記錄時間。如密碼最新更改為3日,則過完2日后,即到5日00:00:00后,用戶才能自行修改密碼。
- -w DAYS,如days=2,密碼過期前2天開始提醒用戶,這個需要和-x的時間一起算,且都以日為單位計算,以UTC時區(qū)記錄時間。如最大過期設置日期為8日,則此時提醒開始時間為從7日00:00:00開始。
- 可能有寫啰嗦了,簡單的時間計算不值一提,可這個困擾了我很久,啰嗦一下,一吐為快。
[root@localhost ~]# useradd centos1
[root@localhost ~]# tail -1 /etc/passwd
centos1:x:1004:1004::/home/centos1:/bin/bash
[root@localhost ~]# tail -1 /etc/shadow
centos1:!!:17381:0:99999:7:::
[root@localhost ~]# passwd -S centos1 \\可以看出新增賬戶沒有設置密碼,賬戶默認被鎖定
centos1 LK 2017-08-03 0 99999 7 -1 (密碼已被鎖定。)
[root@localhost ~]# chage -l centos1
最近一次密碼修改時間 :8月 03, 2017
密碼過期時間 :從不
密碼失效時間 :從不
帳戶過期時間 :從不
兩次改變密碼之間相距的最小天數(shù) :0
兩次改變密碼之間相距的最大天數(shù) :99999
在密碼過期之前警告的天數(shù) :7
[root@localhost ~]# passwd centos1
更改用戶 centos1 的密碼 。
新的 密碼:
重新輸入新的 密碼:
passwd:所有的身份驗證令牌已經成功更新。
[root@localhost ~]# passwd -S centos1 \\密碼最近更新時間以UTC時區(qū)記錄的
centos1 PS 2017-08-03 0 99999 7 -1 (密碼已設置,使用 SHA512 算法。)
[root@localhost ~]# date
2017年 08月 04日 星期五 06:57:29 CST
[root@localhost ~]# date -u
2017年 08月 03日 星期四 22:57:31 UTC
[root@localhost ~]# passwd -x 5 centos1
調整用戶密碼老化數(shù)據(jù)centos1。
passwd: 操作成功
[root@localhost ~]# chage -l centos1
最近一次密碼修改時間 :8月 03, 2017
密碼過期時間 :8月 08, 2017
密碼失效時間 :從不
帳戶過期時間 :從不
兩次改變密碼之間相距的最小天數(shù) :0
兩次改變密碼之間相距的最大天數(shù) :5
在密碼過期之前警告的天數(shù) :7
[root@localhost ~]# passwd -S centos1
centos1 PS 2017-08-03 0 5 7 -1 (密碼已設置,使用 SHA512 算法。)
[root@localhost ~]# date -s "170809 07:59:30"
2017年 08月 09日 星期三 07:59:30 CST
[root@localhost ~]# date -u
2017年 08月 08日 星期二 23:59:32 UTC
[root@localhost ~]# su - centos2
上一次登錄:三 8月 9 07:59:38 CST 2017pts/0 上
[centos2@localhost ~]$ date -u
2017年 08月 08日 星期二 23:59:49 UTC
[centos2@localhost ~]$ su - centos1
密碼:
警告:您的密碼將在 0天后過期
最后一次失敗的登錄:三 8月 9 08:00:02 CST 2017pts/0 上
最有一次成功登錄后有 11 次失敗的登錄嘗試。
[centos1@localhost ~]$ date -u
2017年 08月 09日 星期三 00:00:01 UTC
[centos1@localhost ~]$ exit
登出
[centos2@localhost ~]$ su - centos1
密碼:
[centos2@localhost ~]$ date -u \\以UTC時間為準,8日過完后進入9日,密碼過期
2017年 08月 09日 星期三 00:00:16 UTC
[centos2@localhost ~]$ su - centos1
密碼:
您需要立即更改密碼(密碼過期)
為 centos1 更改 STRESS 密碼。
(當前)UNIX 密碼:
新的 密碼:
無效的密碼: 這個密碼和原來的相同
新的 密碼:
重新輸入新的 密碼:
上一次登錄:三 8月 9 07:59:57 CST 2017pts/0 上
最后一次失敗的登錄:三 8月 9 08:00:02 CST 2017pts/0 上
最有一次成功登錄后有 3 次失敗的登錄嘗試。
[centos1@localhost ~]$ whoami
centos1
[centos1@localhost ~]$ 登出
[centos2@localhost ~]$ 登出
[root@localhost ~]#
[root@localhost ~]# date
2017年 08月 09日 星期三 08:01:22 CST
[root@localhost ~]# hwclock -s \\將系統(tǒng)時間恢復和硬件時間一致
[root@localhost ~]# date
2017年 08月 04日 星期五 07:02:03 CST
[root@localhost ~]# passwd -S centos1
centos1 PS 2017-08-09 0 5 7 -1 (密碼已設置,使用 SHA512 算法。)
[root@localhost ~]# passwd centos1 \\以當前系統(tǒng)時間更新密碼
更改用戶 centos1 的密碼 。
新的 密碼:
重新輸入新的 密碼:
passwd:所有的身份驗證令牌已經成功更新。
[root@localhost ~]# passwd -n 1 centos1
調整用戶密碼老化數(shù)據(jù)centos1。
passwd: 操作成功
[root@localhost ~]# passwd -S centos1
centos1 PS 2017-08-03 1 5 7 -1 (密碼已設置,使用 SHA512 算法。)
[root@localhost ~]# date -u
2017年 08月 03日 星期四 23:04:05 UTC
[root@localhost ~]# su - centos1 \\切換賬戶至centos1
[centos1@localhost ~]$ passwd \\修改密碼
更改用戶 centos1 的密碼 。
為 centos1 更改 STRESS 密碼。
(當前)UNIX 密碼:
您必須等待更長時間以更改密碼
passwd: 鑒定令牌操作錯誤
[centos1@localhost ~]$ date -u \\當前UTC時間為3日,用戶無法自行修改密碼
2017年 08月 03日 星期四 23:04:25 UTC
[centos1@localhost ~]$ 登出
[root@localhost ~]# date -s 07:59:30 \\手工設置時間,使時間即將到4日(UTC時間)
2017年 08月 04日 星期五 07:59:30 CST
[root@localhost ~]# date -u
2017年 08月 03日 星期四 23:59:32 UTC
[root@localhost ~]# su - centos1
[centos1@localhost ~]$ date -u
2017年 08月 03日 星期四 23:59:43 UTC
[centos1@localhost ~]$ passwd
更改用戶 centos1 的密碼 。
為 centos1 更改 STRESS 密碼。
(當前)UNIX 密碼:
您必須等待更長時間以更改密碼
^C
[centos1@localhost ~]$ date -u \\時間進入4日,用戶可以修改自己的密碼
2017年 08月 04日 星期五 00:00:04 UTC
[centos1@localhost ~]$ passwd
更改用戶 centos1 的密碼 。
為 centos1 更改 STRESS 密碼。
(當前)UNIX 密碼:
新的 密碼:
重新輸入新的 密碼:
passwd:所有的身份驗證令牌已經成功更新。
[centos1@localhost ~]$ 登出
[root@localhost ~]# hwclock -s
[root@localhost ~]# date
2017年 08月 04日 星期五 07:11:12 CST
[root@localhost ~]# passwd centos1
更改用戶 centos1 的密碼 。
新的 密碼:
重新輸入新的 密碼:
passwd:所有的身份驗證令牌已經成功更新
[root@localhost ~]# passwd -n 2 centos1 \\將最小時間改為2為例
調整用戶密碼老化數(shù)據(jù)centos1。
passwd: 操作成功
[root@localhost ~]# passwd -S centos1
centos1 PS 2017-08-03 2 5 7 -1 (密碼已設置,使用 SHA512 算法。)
[root@localhost ~]# date -s "170805 7:59:30"
2017年 08月 05日 星期六 07:59:30 CST
[root@localhost ~]# date -u
2017年 08月 04日 星期五 23:59:32 UTC
[root@localhost ~]# su - centos1
[centos1@localhost ~]$ date -u
2017年 08月 04日 星期五 23:59:41 UTC
[centos1@localhost ~]$ passwd
更改用戶 centos1 的密碼 。
為 centos1 更改 STRESS 密碼。
(當前)UNIX 密碼:
您必須等待更長時間以更改密碼
^C
[centos1@localhost ~]$ date -u
2017年 08月 05日 星期六 00:00:04 UTC
[centos1@localhost ~]$ passwd
更改用戶 centos1 的密碼 。
為 centos1 更改 STRESS 密碼。
(當前)UNIX 密碼:
新的 密碼:
重新輸入新的 密碼:
passwd:所有的身份驗證令牌已經成功更新。
[centos1@localhost ~]$ 登出
[root@localhost ~]# passwd -S centos1
centos1 PS 2017-08-05 2 5 7 -1 (密碼已設置,使用 SHA512 算法。)
[centos1@localhost ~]$ passwd
更改用戶 centos1 的密碼 。
為 centos1 更改 STRESS 密碼。
(當前)UNIX 密碼:
您必須等待更長時間以更改密碼
passwd: 鑒定令牌操作錯誤
[centos1@localhost ~]$ 登出
[root@localhost ~]#
[root@localhost ~]# hwclock -s
[root@localhost ~]# passwd centos1
更改用戶 centos1 的密碼 。
新的 密碼:
重新輸入新的 密碼:
抱歉,密碼不匹配。
新的 密碼:
重新輸入新的 密碼:
passwd:所有的身份驗證令牌已經成功更新。
[root@localhost ~]# passwd -S centos1
centos1 PS 2017-08-03 2 5 7 -1 (密碼已設置,使用 SHA512 算法。)
[root@localhost ~]# passwd -w 2 centos1
調整用戶密碼老化數(shù)據(jù)centos1。
passwd: 操作成功
[root@localhost ~]# passwd -S centos1
centos1 PS 2017-08-03 2 5 2 -1 (密碼已設置,使用 SHA512 算法。)
[root@localhost ~]# chage -l centos1
最近一次密碼修改時間 :8月 03, 2017
密碼過期時間 :8月 08, 2017
密碼失效時間 :從不
帳戶過期時間 :從不
兩次改變密碼之間相距的最小天數(shù) :2
兩次改變密碼之間相距的最大天數(shù) :5
在密碼過期之前警告的天數(shù) :2
[root@localhost ~]# date -s "170807 07:59:30"
2017年 08月 07日 星期一 07:59:30 CST
[root@localhost ~]# date -u
2017年 08月 06日 星期日 23:59:32 UTC
[root@localhost ~]# su - centos2
上一次登錄:三 8月 9 07:59:38 CST 2017pts/0 上
[centos2@localhost ~]$ date -u
2017年 08月 06日 星期日 23:59:43 UTC
[centos2@localhost ~]$ su - centos1
密碼:
上一次登錄:六 8月 5 08:00:57 CST 2017pts/0 上
最后一次失敗的登錄:三 8月 9 08:00:02 CST 2017pts/0 上
最有一次成功登錄后有 6 次失敗的登錄嘗試。
[centos1@localhost ~]$ 登出
[centos2@localhost ~]$ date -u
2017年 08月 06日 星期日 23:59:58 UTC
[centos2@localhost ~]$ date -u
2017年 08月 07日 星期一 00:00:03 UTC
[centos2@localhost ~]$ su - centos1
密碼:
[centos2@localhost ~]$ su - centos1 \\8日后過期,則在進入7日就開始提醒用戶,7和8日,提前2天開始提醒
密碼:
警告:您的密碼將在 1 天后過期
上一次登錄:一 8月 7 07:59:49 CST 2017pts/0 上
最后一次失敗的登錄:三 8月 9 08:00:02 CST 2017pts/0 上
最有一次成功登錄后有 6 次失敗的登錄嘗試。
[centos1@localhost ~]$ date -u
2017年 08月 07日 星期一 00:00:33 UTC
[centos1@localhost ~]$ 登出
[root@localhost ~]# hwclock -s
[root@localhost ~]# date
2017年 08月 04日 星期五 07:23:28 CST
[root@localhost ~]# passwd -S centos1
centos1 PS 2017-08-03 2 5 2 -1 (密碼已設置,使用 SHA512 算法。)
[root@localhost ~]# chage -l centos1
最近一次密碼修改時間 :8月 03, 2017
密碼過期時間 :8月 08, 2017
密碼失效時間 :從不
帳戶過期時間 :從不
兩次改變密碼之間相距的最小天數(shù) :2
兩次改變密碼之間相距的最大天數(shù) :5
在密碼過期之前警告的天數(shù) :2
[root@localhost ~]# tail -1 /etc/shadow
centos1:$6$zTbGXG.g$X65MSjIPklzRf4P2xbmbiSFAxENr2iij1qC356fiHLNDklOqvoIknSYVDdBr.amcDTR7U8FXMianPvaThWGIQ/:17381:2:5:2:::
[root@localhost ~]# passwd -e centos1
正在終止用戶 centos1 的密碼。
passwd: 操作成功
[root@localhost ~]# passwd -S centos1
centos1 PS 1970-01-01 2 5 2 -1 (密碼已設置,使用 SHA512 算法。)
[root@localhost ~]# chage -l centos1
最近一次密碼修改時間 :密碼必須更改
密碼過期時間 :密碼必須更改
密碼失效時間 :密碼必須更改
帳戶過期時間 :從不
兩次改變密碼之間相距的最小天數(shù) :2
兩次改變密碼之間相距的最大天數(shù) :5
在密碼過期之前警告的天數(shù) :2
[root@localhost ~]# tail -1 /etc/shadow
centos1:$6$zTbGXG.g$X65MSjIPklzRf4P2xbmbiSFAxENr2iij1qC356fiHLNDklOqvoIknSYVDdBr.amcDTR7U8FXMianPvaThWGIQ/:0:2:5:2:::
[root@localhost ~]# su - centos2
上一次登錄:五 8月 4 07:25:58 CST 2017pts/0 上
[centos2@localhost ~]$ su - centos1
密碼:
您需要立即更改密碼(root 強制)
為 centos1 更改 STRESS 密碼。
(當前)UNIX 密碼:
新的 密碼:
重新輸入新的 密碼:
上一次登錄:五 8月 4 07:27:06 CST 2017pts/0 上
最后一次失敗的登錄:五 8月 4 07:29:38 CST 2017pts/0 上
最有一次成功登錄后有 7 次失敗的登錄嘗試。
[centos1@localhost ~]$
[centos2@localhost ~]$ 登出
[root@localhost ~]# passwd -S centos1
centos1 PS 2017-08-03 2 5 2 -1 (密碼已設置,使用 SHA512 算法。)
[root@localhost ~]# passwd -d centos1
清除用戶的密碼 centos1。
passwd: 操作成功
[root@localhost ~]# tail -1 /etc/shadow \\密碼那以列為空
centos1::17381:2:5:2:::
[root@localhost ~]# passwd -S centos1
centos1 NP 2017-08-03 2 5 2 -1 (密碼為空。)
[root@localhost ~]# passwd centos1
更改用戶 centos1 的密碼 。
新的 密碼:
重新輸入新的 密碼:
passwd:所有的身份驗證令牌已經成功更新。
[root@localhost ~]# passwd -l centos1
鎖定用戶 centos1 的密碼 。
passwd: 操作成功
[root@localhost ~]# tail -1 /etc/shadow
centos1:!!$6$vKejG2c1$kIwCcZAb6It1Tgv2FE5B4jeYFm5B3307vxaTxn92hanfoSn2Q63mYvFaXIgK/.A3mSHwROSUri36Ut1kKXkMv1:17381:2:5:2:::
[root@localhost ~]# passwd -S centos1
centos1 LK 2017-08-03 2 5 2 -1 (密碼已被鎖定。)
[root@localhost ~]# su - centos2
上一次登錄:五 8月 4 07:34:20 CST 2017pts/1 上
[centos2@localhost ~]$ su - centos1
密碼:
su: 鑒定故障
[centos2@localhost ~]$ 登出
[root@localhost ~]# su - centos1
[centos1@localhost ~]$ passwd
更改用戶 centos1 的密碼 。
為 centos1 更改 STRESS 密碼。
(當前)UNIX 密碼:
passwd: 鑒定令牌操作錯誤
[centos1@localhost ~]$ 登出
[root@localhost ~]# passwd -u centos1
解鎖用戶 centos1 的密碼。
passwd: 操作成功
[root@localhost ~]# su - centos1
[centos1@localhost ~]$ passwd
更改用戶 centos1 的密碼 。
為 centos1 更改 STRESS 密碼。
(當前)UNIX 密碼:
您必須等待更長時間以更改密碼
passwd: 鑒定令牌操作錯誤
[centos1@localhost ~]$ 登出
[root@localhost ~]# echo alwin111 | passwd --stdin centos1
更改用戶 centos1 的密碼 。
passwd:所有的身份驗證令牌已經成功更新。
[root@localhost ~]#
補充
passwd -S ,顯示用戶密碼的狀態(tài)信息,如下;
[root@localhost ~]# passwd -S centos1
centos1 PS 2017-08-03 2 5 2 -1 (密碼已設置,使用 SHA512 算法。)
在上面的輸出中,第一個字段顯示的用戶名,第二個字段顯示密碼狀態(tài)(PS = 密碼設置,LK = 密碼鎖定,NP = 無密碼),第三個字段顯示了上次修改密碼的時間,后面四個字段分別顯示了密碼能更改的最小期限和最大期限,警告期限和口令不會失效(-1)
- 演示之前,先說一下幾個天數(shù)的計算原則
gpasswd&newgrp
- image.png
- image.png
命令演示
[root@localhost ~]# useradd centos1
[root@localhost ~]# useradd centos2
[root@localhost ~]# useradd centos3
[root@localhost ~]# useradd centos4
[root@localhost ~]# groupadd centos
[root@localhost ~]# grep centos /etc/passwd /etc/group /etc/gshadow
/etc/passwd:centos1:x:1000:1000::/home/centos1:/bin/bash
/etc/passwd:centos2:x:1001:1001::/home/centos2:/bin/bash
/etc/passwd:centos3:x:1002:1002::/home/centos3:/bin/bash
/etc/passwd:centos4:x:1003:1003::/home/centos4:/bin/bash
/etc/group:centos1:x:1000:
/etc/group:centos2:x:1001:
/etc/group:centos3:x:1002:
/etc/group:centos4:x:1003:
/etc/group:centos:x:1004:
/etc/gshadow:centos1:!::
/etc/gshadow:centos2:!::
/etc/gshadow:centos3:!::
/etc/gshadow:centos4:!::
/etc/gshadow:centos:!::
[root@localhost ~]# id centos1
uid=1000(centos1) gid=1000(centos1) 組=1000(centos1)
[root@localhost ~]# id centos2
uid=1001(centos2) gid=1001(centos2) 組=1001(centos2)
[root@localhost ~]# id centos3
uid=1002(centos3) gid=1002(centos3) 組=1002(centos3)
[root@localhost ~]# id centos4
uid=1003(centos4) gid=1003(centos4) 組=1003(centos4)
[root@localhost ~]# gpasswd -a centos4 centos \\將centos4加入到組centos
正在將用戶“centos4”加入到“centos”組中
[root@localhost ~]# id centos4
uid=1003(centos4) gid=1003(centos4) 組=1003(centos4),1004(centos)
[root@localhost ~]# grep centos /etc/group /etc/gshadow \\通過這兩個配置文件可以看出cento組的成員中包含centos
/etc/group:centos1:x:1000:
/etc/group:centos2:x:1001:
/etc/group:centos3:x:1002:
/etc/group:centos4:x:1003:
/etc/group:centos:x:1004:centos4
/etc/gshadow:centos1:!::
/etc/gshadow:centos2:!::
/etc/gshadow:centos3:!::
/etc/gshadow:centos4:!::
/etc/gshadow:centos:!::centos4
[root@localhost ~]# gpasswd -M centos2,centos3 centos \\向組中添加成員列表
[root@localhost ~]# grep centos /etc/group /etc/gshadow \--M選項會覆蓋掉組中已有的成員
/etc/group:centos1:x:1000:
/etc/group:centos2:x:1001:
/etc/group:centos3:x:1002:
/etc/group:centos4:x:1003:
/etc/group:centos:x:1004:centos2,centos3
/etc/gshadow:centos1:!::
/etc/gshadow:centos2:!::
/etc/gshadow:centos3:!::
/etc/gshadow:centos4:!::
/etc/gshadow:centos:!::centos2,centos3
[root@localhost ~]# id centos4
uid=1003(centos4) gid=1003(centos4) 組=1003(centos4)
[root@localhost ~]# id centos2
uid=1001(centos2) gid=1001(centos2) 組=1001(centos2),1004(centos)
[root@localhost ~]# id centos3
uid=1002(centos3) gid=1002(centos3) 組=1002(centos3),1004(centos)
[root@localhost ~]# gpasswd -a centos4 centos \\再次通過-a選項將centos4加入到組中
正在將用戶“centos4”加入到“centos”組中
[root@localhost ~]# id centos4
uid=1003(centos4) gid=1003(centos4) 組=1003(centos4),1004(centos)
[root@localhost ~]# grep centos /etc/group /etc/gshadow
/etc/group:centos1:x:1000:
/etc/group:centos2:x:1001:
/etc/group:centos3:x:1002:
/etc/group:centos4:x:1003:
/etc/group:centos:x:1004:centos2,centos3,centos4
/etc/gshadow:centos1:!::
/etc/gshadow:centos2:!::
/etc/gshadow:centos3:!::
/etc/gshadow:centos4:!::
/etc/gshadow:centos:!::centos2,centos3,centos4
[root@localhost ~]# id centos1
uid=1000(centos1) gid=1000(centos1) 組=1000(centos1)
[root@localhost ~]# gpasswd -A centos1 centos \\將centos1用戶設置為組管理員,即使其事先不是該組的成員
[root@localhost ~]# id centos1
uid=1000(centos1) gid=1000(centos1) 組=1000(centos1)
[root@localhost ~]# !grep
grep centos /etc/group /etc/gshadow
/etc/group:centos1:x:1000:
/etc/group:centos2:x:1001:
/etc/group:centos3:x:1002:
/etc/group:centos4:x:1003:
/etc/group:centos:x:1004:centos2,centos3,centos4
/etc/gshadow:centos1:!::
/etc/gshadow:centos2:!::
/etc/gshadow:centos3:!::
/etc/gshadow:centos4:!::
/etc/gshadow:centos:!:centos1:centos2,centos3,centos4
[root@localhost ~]# gpasswd -a centos1 centos \\將centos1加入到組中
正在將用戶“centos1”加入到“centos”組中
[root@localhost ~]# id centos1
uid=1000(centos1) gid=1000(centos1) 組=1000(centos1),1004(centos)
[root@localhost ~]# !grep
grep centos /etc/group /etc/gshadow
/etc/group:centos1:x:1000:
/etc/group:centos2:x:1001:
/etc/group:centos3:x:1002:
/etc/group:centos4:x:1003:
/etc/group:centos:x:1004:centos2,centos3,centos4,centos1
/etc/gshadow:centos1:!::
/etc/gshadow:centos2:!::
/etc/gshadow:centos3:!::
/etc/gshadow:centos4:!::
/etc/gshadow:centos:!:centos1:centos2,centos3,centos4,centos1
[root@localhost ~]# gpasswd -d centos4 centos \\將用戶移除出組
正在將用戶“centos4”從“centos”組中刪除
[root@localhost ~]# id centos4
uid=1003(centos4) gid=1003(centos4) 組=1003(centos4)
[root@localhost ~]# !grep
grep centos /etc/group /etc/gshadow
/etc/group:centos1:x:1000:
/etc/group:centos2:x:1001:
/etc/group:centos3:x:1002:
/etc/group:centos4:x:1003:
/etc/group:centos:x:1004:centos2,centos3,centos1
/etc/gshadow:centos1:!::
/etc/gshadow:centos2:!::
/etc/gshadow:centos3:!::
/etc/gshadow:centos4:!::
/etc/gshadow:centos:!:centos1:centos2,centos3,centos1
[root@localhost ~]# su - centos2
[centos2@localhost ~]$ gpasswd -d centos3 centos \\centos2沒有權限對組操作
gpasswd:沒有權限。
[centos2@localhost ~]$ 登出
[root@localhost ~]# su - centos1
[centos1@localhost ~]$ id centos3
uid=1002(centos3) gid=1002(centos3) 組=1002(centos3),1004(centos)
[centos1@localhost ~]$ gpasswd -d centos3 centos \\通過組管理員centos1來移除用戶
正在將用戶“centos3”從“centos”組中刪除
[centos1@localhost ~]$ id centos3
uid=1002(centos3) gid=1002(centos3) 組=1002(centos3)
[centos1@localhost ~]$ 登出
[root@localhost ~]# !grep
grep centos /etc/group /etc/gshadow
/etc/group:centos1:x:1000:
/etc/group:centos2:x:1001:
/etc/group:centos3:x:1002:
/etc/group:centos4:x:1003:
/etc/group:centos:x:1004:centos2,centos1
/etc/gshadow:centos1:!::
/etc/gshadow:centos2:!::
/etc/gshadow:centos3:!::
/etc/gshadow:centos4:!::
/etc/gshadow:centos:!:centos1:centos2,centos1
[root@localhost ~]# su - centos1 \\用centos1登錄系統(tǒng)
[centos1@localhost ~]$ id \\此時centos為輔助組
uid=1000(centos1) gid=1000(centos1) 組=1000(centos1),1006(centos) 環(huán)境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[centos1@localhost ~]$ newgrp - centos \\臨時切換到組centos
[centos1@localhost ~]$ id \\centos1的主組前后發(fā)生了變化,變?yōu)閏entos
uid=1000(centos1) gid=1006(centos) 組=1006(centos),1000(centos1) 環(huán)境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[centos1@localhost ~]$ 登出
[centos1@localhost ~]$ 登出
[root@localhost ~]# su - centos3
[centos3@localhost ~]$ newgrp - centos \\centos3不是組中成員,需要密碼才能擁有組的權限,而組還未設置密碼,所以拒絕用戶訪問
密碼:
無效的密碼。
[centos3@localhost ~]$
[centos3@localhost ~]$ 登出
[root@localhost ~]# gpasswd centos \\設置組密碼
正在修改 centos 組的密碼
新密碼:
請重新輸入新密碼:
[root@localhost ~]# su - centos1
[centos1@localhost ~]$ newgrp - centos \\centos1為組中成員,無需密碼即可切換到組centos
[centos1@localhost ~]$ id
uid=1000(centos1) gid=1006(centos) 組=1006(centos),1000(centos1) 環(huán)境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[centos1@localhost ~]$ 登出
[centos1@localhost ~]$ 登出
[root@localhost ~]# su - centos3 \\用centos3登錄系統(tǒng)
[centos3@localhost ~]$ id
uid=1002(centos3) gid=1002(centos3) 組=1002(centos3) 環(huán)境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[centos3@localhost ~]$ id centos3
uid=1002(centos3) gid=1002(centos3) 組=1002(centos3)
[centos3@localhost ~]$ newgrp - centos \\輸入密碼獲取組的權限
密碼:
[centos3@localhost ~]$ id
uid=1002(centos3) gid=1006(centos) 組=1006(centos),1002(centos3) 環(huán)境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[centos3@localhost ~]$ id centos
id: centos: no such user
[centos3@localhost ~]$ id centos3
uid=1002(centos3) gid=1002(centos3) 組=1002(centos3)
[centos3@localhost ~]$ 登出
[centos3@localhost ~]$ 登出
[root@localhost ~]# su - centos3
[centos3@localhost ~]$ pwd
/home/centos3
[centos3@localhost ~]$ touch du1 \\用戶在自己的主組下創(chuàng)建文件,其屬組是用戶所在的主組
[centos3@localhost ~]$ ll
總用量 0
-rw-rw-r--. 1 centos3 centos3 0 8月 5 16:54 du1
[centos3@localhost ~]$ newgrp - centos
密碼:
[centos3@localhost ~]$ id
uid=1002(centos3) gid=1006(centos) 組=1006(centos),1002(centos3) 環(huán)境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[centos3@localhost ~]$ touch du2 \\獲取組權限后,用戶在自己的主組下創(chuàng)建文件,其屬組是用戶所獲取的組
[centos3@localhost ~]$ ll
總用量 0
-rw-rw-r--. 1 centos3 centos3 0 8月 5 16:54 du1
-rw-r--r--. 1 centos3 centos 0 8月 5 16:54 du2
[root@localhost ~]# grep centos /etc/gshadow
centos1:!::
centos2:!::
centos3:!::
centos4:!::
centos:$6$7OdwRIMUo8//v$9SvuMjm7Ixoim3ON97sGEt07I.BhQu/r5.6eWwaqqdnQMN6XUZqJdHXkJki7Z9CAGVvZgr4Eef9frGi9iuteX0:centos1:centos1,centos2
[root@localhost ~]# gpasswd -r centos \\清楚組密碼,gshadow文件記錄密碼的一列為空
[root@localhost ~]# !grep
grep centos /etc/gshadow
centos1:!::
centos2:!::
centos3:!::
centos4:!::
centos::centos1:centos1,centos2
[root@localhost ~]#
至于-R的命令演示,和man手冊上說明的有很大的不同,用-R后,成員依然無需密碼就能獲取組權限,而非成員組無法通過密碼獲取組權限,僅僅限制了非成員組的訪問,而成員的訪問沒有起到效果。等待大神幫忙解決了,再進行補充吧
終于找到了原因,原來是系統(tǒng)man手冊的介紹錯誤,我的天哪,還能有這樣的錯誤,弄了一天了,原來是OS的鍋。好吧,畢竟man手冊也是人寫的,如下:看下我系統(tǒng)的關于-R參數(shù)的解釋圖一和別人的解釋圖二對比
圖一
圖二
圖二才是正解(限制用戶登入組,只有組中的成員才可以用newgrp加入改組),趕緊把我之前的錯誤解釋改掉!
和網(wǎng)上搜到的中文解釋也是一致的。都怪自己太相信自己系統(tǒng)的解釋,中文解釋可能會有誤差(與英文原文),從沒有懷疑自己系統(tǒng)的man手冊解釋。導致被折磨了整個周六一天。
好了不扯淡了,趕緊補充完命令演示
[root@localhost ~]# gpasswd centos \\給組設置密碼alwinqqq
正在修改 centos 組的密碼
新密碼:
請重新輸入新密碼:
[root@localhost ~]# !grep
grep centos /etc/gshadow /etc/group
/etc/gshadow:centos1:!::
/etc/gshadow:centos2:!::
/etc/gshadow:centos3:!::
/etc/gshadow:centos4:!::
/etc/gshadow:centos:$6$s7YXXfFhDh$F8Z05QeuZdBe.ePxf8wz4Qlxs25EK3ohEVniaDt7QwlZDthBcvvcb67/OLy3zCpCYLsObYBU1GDOs9YMFCQen0::centos2
/etc/group:centos1:x:1000:
/etc/group:centos2:x:1001:
/etc/group:centos3:x:1002:
/etc/group:centos4:x:1003:
/etc/group:centos:x:1006:centos2
[root@localhost ~]# su - centos2 \\切換組成員centos2登錄系統(tǒng)
上一次登錄:六 8月 5 23:08:43 CST 2017從 10.1.18.1pts/2 上
[centos2@localhost ~]$ id
uid=1001(centos2) gid=1001(centos2) 組=1001(centos2),1006(centos) 環(huán)境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[centos2@localhost ~]$ newgrp centos \\無需密碼即可切換主組
[centos2@localhost ~]$ id
uid=1001(centos2) gid=1006(centos) 組=1006(centos),1001(centos2) 環(huán)境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[centos2@localhost ~]$ exit
[centos2@localhost ~]$ 登出
[root@localhost ~]# su - centos1 \\切換非組成員centos2登錄系統(tǒng)
上一次登錄:六 8月 5 18:14:47 CST 2017pts/0 上
最后一次失敗的登錄:三 8月 9 08:00:02 CST 2017pts/0 上
最有一次成功登錄后有 6 次失敗的登錄嘗試。
[centos1@localhost ~]$ id
uid=1000(centos1) gid=1000(centos1) 組=1000(centos1) 環(huán)境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[centos1@localhost ~]$ newgrp centos \\需要密碼切換主組
密碼:
[centos1@localhost ~]$ id
uid=1000(centos1) gid=1006(centos) 組=1006(centos),1000(centos1) 環(huán)境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[centos1@localhost ~]$ exit
[centos1@localhost ~]$ 登出
[root@localhost ~]#
[root@localhost ~]# gpasswd -R centos \\R參數(shù)限制組外成員訪問
[root@localhost ~]# !grep \\密碼處變?yōu)閲@號
grep centos /etc/gshadow /etc/group
/etc/gshadow:centos1:!::
/etc/gshadow:centos2:!::
/etc/gshadow:centos3:!::
/etc/gshadow:centos4:!::
/etc/gshadow:centos:!::centos2
/etc/group:centos1:x:1000:
/etc/group:centos2:x:1001:
/etc/group:centos3:x:1002:
/etc/group:centos4:x:1003:
/etc/group:centos:x:1006:centos2
[root@localhost ~]# su - centos2
上一次登錄:日 8月 6 00:52:12 CST 2017pts/0 上
[centos2@localhost ~]$ id
uid=1001(centos2) gid=1001(centos2) 組=1001(centos2),1006(centos) 環(huán)境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[centos2@localhost ~]$ newgrp centos \\組成員切換不受影響,前后無變化
[centos2@localhost ~]$ id
uid=1001(centos2) gid=1006(centos) 組=1006(centos),1001(centos2) 環(huán)境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[centos2@localhost ~]$ exit
[centos2@localhost ~]$ 登出
[root@localhost ~]#
[root@localhost ~]# su - centos1
上一次登錄:日 8月 6 00:52:36 CST 2017pts/0 上
最后一次失敗的登錄:三 8月 9 08:00:02 CST 2017pts/0 上
最有一次成功登錄后有 6 次失敗的登錄嘗試。
[centos1@localhost ~]$ id
uid=1000(centos1) gid=1000(centos1) 組=1000(centos1) 環(huán)境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[centos1@localhost ~]$ newgrp centos \\組外成員無法切換,即時知道密碼也無用
密碼:
無效的密碼。
[centos1@localhost ~]$ 登出
[root@localhost ~]# su - centos3
上一次登錄:六 8月 5 16:53:13 CST 2017pts/0 上
[centos3@localhost ~]$ id
uid=1002(centos3) gid=1002(centos3) 組=1002(centos3) 環(huán)境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[centos3@localhost ~]$ newgrp centos \\組外成員無法切換,即時知道密碼也無用
密碼:
無效的密碼。
[centos3@localhost ~]$ 登出
[root@localhost ~]#
最后在啰嗦幾句吧,因為被折磨的原因,不吐不快
- gpasswd組成員管理的功能,可以增加、刪除用戶、以及設置組管理員;并且可以實現(xiàn)用戶主組的臨時切換,組內用戶無需密碼可以實現(xiàn)自由切換,通過newgrp命令切換;若非組中的成員也可通過newgrp切換,此時需要給newgrp設置組密碼,非組成員用戶通過密碼實現(xiàn)臨時切換主組;也可以通過R參數(shù)限制非組成員登錄,即使其知道組的密碼,所以此時只有組內成員可以臨時切換到改組
id
- image.png
命令演示
[root@localhost ~]# grep centos2 /etc/passwd /etc/group
/etc/passwd:centos2:x:1001:1001::/home/centos2:/bin/bash
/etc/group:centos2:x:1001:
/etc/group:centos:x:1006:centos1,centos2
[root@localhost ~]# id centos2
uid=1001(centos2) gid=1001(centos2) 組=1001(centos2),1006(centos)
[root@localhost ~]# id -u centos2
1001
[root@localhost ~]# id -g centos2
1001
[root@localhost ~]# id -G centos2
1001 1006
[root@localhost ~]# id -Gn centos2
centos2 centos
[root@localhost ~]# id -gn centos2
centos2
[root@localhost ~]# id -un centos2
centos2
[root@localhost ~]# su - centos2
[centos2@localhost ~]$ id
uid=1001(centos2) gid=1001(centos2) 組=1001(centos2),1006(centos) 環(huán)境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[centos2@localhost ~]$ newgrp - centos
[centos2@localhost ~]$ id
uid=1001(centos2) gid=1006(centos) 組=1006(centos),1001(centos2) 環(huán)境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[centos2@localhost ~]$ grep centos2 /etc/passwd /etc/group \\通過newgrp臨時切換主組,配置文件里的主組并沒有發(fā)生改變
/etc/passwd:centos2:x:1001:1001::/home/centos2:/bin/bash
/etc/group:centos2:x:1001:
/etc/group:centos:x:1006:centos1,centos2
[centos2@localhost ~]$ id -u
1001
[centos2@localhost ~]$ id -g \\主組變成了centos
1006
[centos2@localhost ~]$ id -G
1006 1001
[centos2@localhost ~]$ id -nG
centos centos2
[centos2@localhost ~]$
su
- image.png
命令演示
[root@localhost ~]# su - centos1
上一次登錄:六 8月 5 16:33:58 CST 2017pts/0 上
最后一次失敗的登錄:三 8月 9 08:00:02 CST 2017pts/0 上
最有一次成功登錄后有 6 次失敗的登錄嘗試。
[centos1@localhost ~]$ pwd
/home/centos1
[centos1@localhost ~]$ 登出
[root@localhost ~]# su -l centos1
上一次登錄:六 8月 5 17:57:40 CST 2017pts/0 上
最后一次失敗的登錄:三 8月 9 08:00:02 CST 2017pts/0 上
最有一次成功登錄后有 6 次失敗的登錄嘗試。
[centos1@localhost ~]$ pwd
/home/centos1
[centos1@localhost ~]$ 登出
[root@localhost ~]# su centos1
[centos1@localhost root]$ pwd
/root
[root@localhost ~]# ll xiangjis
ls: 無法訪問xiangjis: 沒有那個文件或目錄
[root@localhost ~]# su -c "mkdir xiangjis" centos1
mkdir: 無法創(chuàng)建目錄"xiangjis": 權限不夠
[root@localhost ~]# su -c "mkdir /tmp/xiangjis" centos1
[root@localhost ~]#[root@localhost ~]#
drwxr-xr-x. 2 centos1 centos1 6 8月 5 17:59 /tmp/xiangjis
[root@localhost ~]# date
2017年 08月 05日 星期六 17:59:28 CST
[root@localhost ~]#