Linux4

1、创建/guanli 目录,在/guanli下创建zonghe 和 jishu 两个目录(一条命令)
[root@localhost ~]# mkdir /guanli          //创建guanli目录
[root@localhost ~]# cd /guanli               //进入guanli 目录
[root@localhost guanli]# mkdir zonghe | mkdir jishu    //创建zonghe ,jishu 目录,可以用管道符号"|"表示
2、添加组帐号zonghe、caiwu、jishu,GID号分别设置为2001、2002、2003 
[root@localhost ~]# groupadd -g 2001 zonghe
[root@localhost ~]# groupadd -g 2002 caiwu
[root@localhost ~]# groupadd -g 2003 jishu              //用groupadd    -g(表示添加GID账号) 文件名
3、创建jerry、kylin、tsengia、obama用户,其中的kylin用户帐号在2020年12月30日后失效
[root@localhost ~]# useradd jerry | useradd -e 2020-12-30 kylin | useradd tsengia |useradd obama    //添加用户用useradd 【选项】用户名  ,-e表示指定账号失效时间
4、将jerry、kylin、tsengia、obama等用户添加到zonghe组内 
[root@localhost ~]# gpasswd -M jerry,kylin,tsengia,obama zonghe  //gpasswd -M 用户名,用户名,...,用户名 组名
5、创建handy、cucci用户,其中cucci帐号的登录Shell设置为“/sbin/nologin”
[root@localhost ~]# useradd handy | useradd -s /sbin/nologin cucci    //-s指定用户账号登录的shell
6、将handy、cucci等用户添加到jishu组内
[root@localhost ~]# gpasswd -M handy,cucci jishu   
7、将上述的所有用户均要求加入到guanli组内
[root@localhost ~]# groupadd guanli          //添加guanli 组用groupadd命令       
[root@localhost ~]# gpasswd -M cucci,handy,jerry,kylin,obama,tsengia guanli   
8、将zonghe组内的obama用户删除
[root@localhost ~]# gpasswd -d obama zonghe     //用gpasswd -d 删除组里面的用户
正在将用户“obama”从“zonghe”组中删除
9、为jerry用户设置密码为“123456”(使用普通方法)
   为cucci用户设置密码为“redhat”(使用--stdin方法) 
普通方法:
[root@localhost ~]# passwd jerry
更改用户 jerry 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
使用--studin方法
[root@localhost ~]# echo "redhat" | passwd --stdin cucci 
更改用户 cucci 的密码 。
passwd:所有的身份验证令牌已经成功更新。
10、将jerry用户锁定,并查看锁定状态
[root@localhost ~]# passwd -l jerry            //passwd -l 锁定用户状态
锁定用户 jerry 的密码 。
passwd: 操作成功
[root@localhost ~]# passwd -S jerry           //-S查看锁定状态
jerry LK 2019-07-30 0 99999 7 -1 (密码已被锁定。)
11、打开两个xshell窗口,通过(who 或者 w)命令查看连接状态,并通过fuser杀掉其中一个
[root@localhost ~]# who
root     :0           2019-07-25 22:09 (:0)
root     pts/0        2019-07-30 17:17 (:0)
root     pts/1        2019-07-25 22:22 (192.168.116.88)
root     pts/2        2019-07-27 13:41 (192.168.116.88)
root     pts/3        2019-07-30 17:18 (192.168.100.118)
root     pts/4        2019-07-30 19:09 (192.168.100.118)
root     pts/5        2019-07-30 19:31 (192.168.100.118)
root     pts/6        2019-07-30 19:31 (192.168.100.118)
[root@localhost ~]# w
 19:32:31 up  2:20,  8 users,  load average: 0.05, 0.04, 0.05
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     :0       :0               四22   ?xdm?   2:13   0.13s /usr/libexec/gnome-session-binary -
root     pts/0    :0               17:17    2:13m  0.02s  0.02s bash
root     pts/1    192.168.116.88   四22    4days  0.02s  0.02s -bash
root     pts/2    192.168.116.88   六13    3days  0.03s  0.03s -bash
root     pts/3    192.168.100.118  17:18    2:05m  0.34s  0.34s -bash
root     pts/4    192.168.100.118  19:09    7.00s  0.40s  0.01s w
root     pts/5    192.168.100.118  19:31    1:03   0.02s  0.02s -bash
root     pts/6    192.168.100.118  19:31   60.00s  0.02s  0.02s -bash
[root@localhost ~]# fuser -k /dev/pts/6
/dev/pts/6:          51259
[root@localhost ~]# fuser -k /dev/pts/5   //杀死进程,fuser -k  ,可以根据时间看刚打开的进程
/dev/pts/5:          51219
[root@localhost ~]# w
 19:34:42 up  2:22,  6 users,  load average: 0.01, 0.03, 0.05
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     :0       :0               四22   ?xdm?   2:14   0.13s /usr/libexec/gnome-session-binary -
root     pts/0    :0               17:17    2:16m  0.02s  0.02s bash
root     pts/1    192.168.116.88   四22    4days  0.02s  0.02s -bash
root     pts/2    192.168.116.88   六13    3days  0.03s  0.03s -bash
root     pts/3    192.168.100.118  17:18    2:07m  0.34s  0.34s -bash
root     pts/4    192.168.100.118  19:09    2.00s  0.54s  0.01s w
12、查看cucci用户,属于那些组,并查看其详细信息
[root@localhost ~]# groups cucci        //groups  
cucci : cucci jishu guanli
[root@localhost ~]# finger cucci            //finger 查看详细信息
Login: cucci             Name:
Directory: /home/cucci               Shell: /sbin/nologin
Never logged in.
No mail.
No Plan.
13、手工创建账号(jll)
[root@localhost ~]# vi /etc/passwd              //进入/etc/passwd里面进行编辑 ,添加如下内容
jll:x:1007:1007::/home/jll:/bin/bash        
[root@localhost ~]# vi /etc/shadow                //进入/etc/shadow/中添加 如下内容
jll::18107:0:99999:7:::
[root@localhost ~]# vi /etc/group               //进入/etc/group添加如下内容,注意这三次添加的内容,用户名要保持一致
jll:x:1007:
[root@localhost ~]# mkdir /home/jll           //在/home/中创建jll文件夹要与/etc/passwd中的路径保持一致
[root@localhost ~]# cp /etc/skel/.bash* /home/jll             将/etc/skel/.bash* 复制给/home/jll中
[root@localhost ~]# passwd jll                  //更改用户的登录密码
更改用户 jll 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
//对用户进行配更新,分别进入以下文本中进行添加相应内容
[root@localhost ~]# vi ~jll/.bash_profile         
echo "welcom jll"
[root@localhost ~]# vi ~jll/.bashrc              
echo "hi this is a new bash !"
[root@localhost ~]# vi ~jll/.bash_logout
echo "byby!"
[root@localhost ~]# su jll       //切换用户看是否能够登录   
hi this is a new bash !
[jll@localhost root]$ logout
bash: logout: 不是登录shell: 使用 `exit'
[jll@localhost root]$ exit
exit
[root@localhost ~]#
14、设置权限及归属:
   /guanli目录属组设为guanli
   /guanli/zonghe目录的属组设为zonghe
   /guanli/jishu目录的属组设为jishu
   设置3个目录都是禁止其他用户访问的权限
[root@localhost ~]# chown :guanli /guanli              //chown设置归属权
[root@localhost ~]# ll -d /guanli                               //查看目录归属
drwxr-xr-x. 4 root guanli 33 7月  30 19:11 /guanli
[root@localhost ~]# chown :zonghe /guanli/zonghe/           
[root@localhost ~]# chown :jishu /guanli/jishu/
[root@localhost ~]# ll /guanli/
总用量 0
drwxr-xr-x. 2 root jishu  6 7月  30 19:11 jishu
drwxr-xr-x. 2 root zonghe 6 7月  30 19:11 zonghe
[root@localhost ~]# chmod -R o-r /guanli/                 //chmod 设定用户权限,-R 表 示递归 ,o-r 表示其他人去掉读权限   
[root@localhost ~]# su elin                                           //切换至elin用户去访问/guanli/文件夹
[elin@localhost root]$ ls /guanli/                                   //显示无法打开目录,权限不够
ls: 无法打开目录/guanli/: 权限不够
15、建立公共目录/ceshi
   允许技术组内的所有用户读取、写入、执行文件
   禁止其他用户读、写、执行
[root@localhost ~]# mkdir -m 777 /ceshi              //-m 不看以前的权限掩码,为目标文件设置新的权限掩码,777表示文件满权限
[root@localhost ~]# chown :jishu /ceshi
[root@localhost ~]# ll -d /ceshi
drwxrwxrwx. 2 root jishu 6 7月  30 20:00 /ceshi
[root@localhost ~]# chmod -R o-r /ceshi
16、清除jerry用户密码
[root@localhost ~]# passwd -d jerry               //passwd -d 用户  ,删除用户 
清除用户的密码 jerry。
passwd: 操作成功
17、锁定cucci用户密码并查看状态
[root@localhost ~]# passwd -l cucci         
锁定用户 cucci 的密码 。
passwd: 操作成功
[root@localhost ~]# passwd -S cucci
cucci LK 2019-07-30 0 99999 7 -1 (密码已被锁定。)
18、修改obama用户的UID为8888
[root@localhost ~]# usermod -u 8888 obama             //usermod -u 修改ID
19、通过passwd命令修改kylin用户的最长密码使用期限为60天     
[root@localhost ~]# passwd -x 60 kylin                     
调整用户密码老化数据kylin。
passwd: 操作成功
20、通过id groups finger等命令查看用户handy信息
[root@localhost ~]# id handy
uid=1006(handy) gid=1006(handy) 组=1006(handy),2003(jishu),2004(guanli)
[root@localhost ~]# groups handy
handy : handy jishu guanli
[root@localhost ~]# finger handy
Login: handy             Name:
Directory: /home/handy               Shell: /bin/bash
Never logged in.
No mail.
No Plan.
原文地址:https://www.cnblogs.com/elin989898/p/11272779.html