RH124-05 管理本地用户和组-2
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RH124-05 管理本地用户和组-2相关的知识,希望对你有一定的参考价值。
管理本地账号
5.3 c
相关命令: useradd ,usermod ,userdel,passwd , groupadd ,groupmod,gpasswd,groupdel
相关文件: /etc/login.defs , /etc/passwd , /etc/shadow , /etc/gpasswd , /etc/gshadow
需要掌握: 创建,修改,删除用户、用户组,修改用户组身份,设定用户密码
添加用户前需要确定:
确定用户的默认组是否有特殊要求
确定用户是否允许登陆
确定用户的密码策略
确定用户的有效期
确定用户的uid是否有特殊要求
useradd,usermod 的参数:
-u 指定用户的uid
-c 添加用户注释
-g 指定用用户的默认组
-G 指定用户的附加组
-a 追加更多的附加组,必须和-G使用: -aG
-d 指定用户的家目录
-m 家目录迁移,必须和-d一起使用
-s 指定用户默认shell
-L 锁定用户
-U 解锁用户
groupadd命令的需要掌握的参数:
-g
groupmod命令的需要掌握的参数:
-g
-n
练习: 考试必考知识点
建立用户juliet, romeo, hamlet,reba, dolly, and elvis
建立用户组,组ID要求为30000,组名为shakespeare
建立用户组,组名为artists
要求把shakespeare作为用户juliet, romeo和 hamlet的附加组
要求把artists作为用户reba, dolly 和 elvis的附加组
要求artists同时作为用户romeo的另外一个附加组(之前的附加组还继续使用)
5.4 管理用户密码
相关文件: /etc/passwd,/etc/shadow
相关命令: chage,usermod
chage命令的参数:
-l 显示帐户年龄信息
-E # chage -E 2014-12-28 romeo
-d # -d 0 下次登陆系统强制修改密码
-M 将两次改变密码之间相距的最大天数设为“最大天数”
-m 将两次改变密码之间相距的最小天数设为“最小天数”
-W 将过期警告天数设为“警告天数”
-I 过期 INACTIVE 天数后,设定密码为失效状态
练习: 在server虚拟机上完成。 当romeo用户第一次登陆系统的时候(默认登陆密码为romeo),必须要求强制更改密码。密码有效期为90天,账号将在180天后过期
实验: 重置server虚拟机,然后在上面完成操作
新建用户sspade, bboop, and dtracy,密码有效期为30天,默认密码都为redhat
新建用户组consultants,组ID必须为40000,并且该组作为上面三个用户的附加组
把上述三个用户的账号有效期设定为90天后
bboop用户的密码有效期更改为15天
所有用户在第一登陆的时候都必须强制修改密码
实验完毕,提交# lab localusers grade
======================================================================================================================
第五章目录
useradd tom
[[email protected] ~]# grep tom /etc/passwd 在某个目录中的文件 找某个关键字,如果有则输出
tom:x:1001:1001::/home/tom:/bin/bash
[[email protected] ~]# id tom
uid=1001(tom) gid=1001(tom) groups=1001(tom)
[[email protected] ~]# grep tom /etc/group 如果没有指定组,则会默认加一个与它相同的组,并且会一个家目录。
tom:x:1001:
[[email protected] ~]# cd /home
[[email protected] home]# ls
student tom
[[email protected] home]# passwd tom 给用户加一个密码
Changing password for user tom.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
[[email protected] home]# ssh [email protected]
The authenticity of host ‘localhost (::1)‘ can‘t be established.
ECDSA key fingerprint is eb:24:0e:07:96:26:b1:04:c2:37:0c:78:2d:bc:b0:08.
Are you sure you want to continue connecting (yes/no)? yes
创建mary
[[email protected] home]# useradd -u 1500 -d /home/imary -s /sbin/nologin mary
[[email protected] home]# id mary
uid=1500(mary) gid=1500(mary) groups=1500(mary)
[[email protected] home]# grep mary /etc/gropu
grep: /etc/gropu: No such file or directory
[[email protected] home]# grep mary /etc/group
mary:x:1500:
修改mary的组和bash等信息
[[email protected] home]# usermod -c "i am mary ,i am a pretty girl" -G tom -s /bin/bash mary
[[email protected] home]# id mary
uid=1500(mary) gid=1500(mary) groups=1500(mary),1001(tom)
[[email protected] home]# grep mary /etc/passwd
mary:x:1500:1500:i am mary ,i am a pretty girl:/home/imary:/bin/bash
[[email protected] home]#
[[email protected] home]# usermod -aG daemon mary 再加一个组
[[email protected] home]# id mary
uid=1500(mary) gid=1500(mary) groups=1500(mary),2(daemon),1001(tom)
[[email protected] home]#
[[email protected] home]# usermod -L mary 锁定
[[email protected] home]# grep mary /etc/shadow
mary:!!:17306:0:99999:7:::
[[email protected] home]# ^C
[[email protected] home]# usermod -U mary 解锁
[[email protected] home]# grep mary /etc/shadow
mary:!:17306:0:99999:7:::
[[email protected] home]#
删除,不加-r会留下邮件和家目录
[[email protected] home]# userdel mary
[[email protected] home]# ls -ld /home/imary
drwx------. 4 1500 1500 88 May 20 14:13 /home/imary
[[email protected] home]# ls -l /var/mail
lrwxrwxrwx. 1 root root 10 May 7 2014 /var/mail -> spool/mail
[[email protected] home]# ls -l /var/mail/
total 0
-rw-rw----. 1 1500 mail 0 May 20 14:13 mary
-rw-rw----. 1 rpc mail 0 May 7 2014 rpc
-rw-rw----. 1 student mail 0 Jul 11 2014 student
-rw-rw----. 1 tom mail 0 May 20 13:57 tom
[[email protected] home]# userdel -r tom
[[email protected] home]# ls -l /var/mail
lrwxrwxrwx. 1 root root 10 May 7 2014 /var/mail -> spool/mail
[[email protected] home]# ls -l /var/mail/
total 0
-rw-rw----. 1 1500 mail 0 May 20 14:13 mary
-rw-rw----. 1 rpc mail 0 May 7 2014 rpc
-rw-rw----. 1 student mail 0 Jul 11 2014 student
[[email protected] home]# grep admin /etc/group
admin:x:1001:
[[email protected] home]# groupadd -g 1500 dba
[[email protected] home]# grep dba /etc/group
dba:x:1500:
[[email protected] home]# groupmod -g 2500 dba 改id
[[email protected] home]# grep dba /etc/group
dba:x:2500:
[[email protected] home]# groupmod -n dbadmin dba 改名字
[[email protected] home]# grep dba /etc/group
dbadmin:x:2500:
[[email protected] home]#
组加密码,并用student组临时改成admin,只是在这次的会话中登陆 ,重新登陆就没有了
[[email protected] home]# gpasswd admin
Changing the password for group admin
New Password:
Re-enter new password:
[[email protected] home]# grep admin /etc/gshadow
admin:$6$YCWYZDTZINF0tT$x.LHtjRsrVhLRQmdvyM3iCLLJkqp3DJqxlfPAoF.ozfegXjXC9kSK3k8cd7ckmstW7MHNJrpH9R7zaCv8xZiR.::
dbadmin:!::
[[email protected] home]# grep admin /etc/passwd
[[email protected] home]# ext
bash: ext: command not found...
[[email protected] home]# exit
logout
[[email protected] Desktop]$ newgrp admin
Password:
[[email protected] Desktop]$ id
uid=1000(student) gid=1001(admin) groups=1000(student),10(wheel),1001(admin) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[[email protected] Desktop]$
练习:
[[email protected] Desktop]# useradd juliet
[[email protected] Desktop]# useradd romeo
[[email protected] Desktop]# useradd hamlet
[[email protected] Desktop]# useradd dolly
[[email protected] Desktop]# useraddd elvis
bash: useraddd: command not found...
Similar command is: ‘useradd‘
[[email protected] Desktop]# useradd elvis
[[email protected] Desktop]# useradd reba
[[email protected] Desktop]# gropadd -g 3000 shakespeare
bash: gropadd: command not found...
[[email protected] Desktop]# groupadd -g 3000 shakespeare
[[email protected] Desktop]# tail -6 /etc/group
romeo:x:1002:
hamlet:x:1003:
dolly:x:1004:
elvis:x:1005:
reba:x:1006:
shakespeare:x:3000:
[[email protected] Desktop]# tail -7 /etc/group
juliet:x:2501:
romeo:x:1002:
hamlet:x:1003:
dolly:x:1004:
elvis:x:1005:
reba:x:1006:
shakespeare:x:3000:
[[email protected] Desktop]# tail -2 /etc/group
reba:x:1006:
shakespeare:x:3000:
加组两种访求
[[email protected] Desktop]# id juliet
uid=1001(juliet) gid=2501(juliet) groups=2501(juliet)
[[email protected] Desktop]# usermod -Gshakespeare juliet
[[email protected] Desktop]# id juliet
uid=1001(juliet) gid=2501(juliet) groups=2501(juliet),3000(shakespeare)
[[email protected] Desktop]# gpasswd -a romeo shakespeare
再加一个附加组 usrmod -aG artists romeo
本文出自 “IT正能量” 博客,谢绝转载!
以上是关于RH124-05 管理本地用户和组-2的主要内容,如果未能解决你的问题,请参考以下文章