zoukankan      html  css  js  c++  java
  • 上机作业三 账号管理

    1、创建/guanli 目录,在/guanli下创建zonghe 和 jishu 两个目录(一条命令)

    [root@localhost ~]# mkdir -pv /guanli/zonghe | mkdir -pv /guanli/jishu
    mkdir: 已创建目录 "/guanli"
    mkdir: 已创建目录 "/guanli/jishu"
    [root@localhost ~]# ls -R /guanli/
    /guanli/:
    jishu zonghe

    /guanli/jishu:

    /guanli/zong
    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


    3、创建jerry、kylin、tsengia、obama用户,其中的kylin用户帐号在2020年12月30日后失效
    [root@localhost ~]# useradd jerry
    [root@localhost ~]# useradd -e 2020-12-30 kylin
    [root@localhost ~]# useradd tsengia
    [root@localhost ~]# useradd obama


    4、将jerry、kylin、tsengia、obama等用户添加到zonghe组内
    [root@localhost ~]# gpasswd -a jerry zonghe
    正在将用户“jerry”加入到“zonghe”组中
    [root@localhost ~]# gpasswd -a kylin zonghe
    正在将用户“kylin”加入到“zonghe”组中
    [root@localhost ~]# gpasswd -a tsengia zonghe
    正在将用户“tsengia”加入到“zonghe”组中
    [root@localhost ~]# gpasswd -a obama zonghe
    正在将用户“obama”加入到“zonghe”组中


    5、创建handy、cucci用户,其中cucci帐号的登录Shell设置为“/sbin/nologin”
    [root@localhost ~]# useradd handy
    [root@localhost ~]# useradd -s /sbin/nologin cucci


    6、将handy、cucci等用户添加到jishu组内
    [root@localhost ~]# gpasswd -a handy jishu
    正在将用户“handy”加入到“jishu”组中
    [root@localhost ~]# gpasswd -a cucci jishu
    正在将用户“cucci”加入到“jishu”组中


    7、将上述的所有用户均要求加入到guanli组内
    [root@localhost ~]# groupadd guanli
    [root@localhost ~]# vi /etc/group


    8、将zonghe组内的obama用户删除
    [root@localhost ~]# gpasswd -d obama zonghe
    正在将用户“obama”从“zonghe”组中删除


    9、为jerry用户设置密码为“123456”(使用普通方法)
    为cucci用户设置密码为“redhat”(使用--stdin方法) 
    [root@localhost ~]# passwd jerry
    更改用户 jerry 的密码 。
    新的 密码:
    无效的密码: 密码少于 8 个字符
    重新输入新的 密码:
    passwd:所有的身份验证令牌已经成功更新。

    [root@localhost ~]# echo 'redhat' | passwd --stdin cucci
    更改用户 cucci 的密码 。
    passwd:所有的身份验证令牌已经成功更新。

    10、将jerry用户锁定,并查看锁定状态
    [root@localhost ~]# passwd -l jerry
    锁定用户 jerry 的密码 。
    passwd: 操作成功
    [root@localhost ~]# passwd -S jerry
    jerry LK 2019-07-30 0 99999 7 -1 (密码已被锁定。)


    11、打开两个xshell窗口,通过(who 或者 w)命令查看连接状态,并通过fuser杀掉其中一个
    [root@localhost ~]# w
    10:09:41 up 6:08, 4 users, load average: 0.00, 0.01, 0.05
    USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
    root :0 :0 一14 ?xdm? 1:50 0.21s gdm-session-worker [pam/gdm-password]
    root pts/0 :0 一14 30:37 0.04s 0.04s /bin/bash
    root pts/1 192.168.100.196 09:39 5.00s 0.38s 0.03s w
    root pts/2 192.168.100.196 10:09 4.00s 0.03s 0.03s -bash
    [root@localhost ~]# fuser -k /dev/pts/2
    /dev/pts/2: 7002


    12、查看cucci用户,属于那些组,并查看其详细信息
    [root@localhost ~]# id cucci
    uid=1008(cucci) gid=1008(cucci) 组=1008(cucci),2003(jishu),2005(guanli)
    [root@localhost ~]# groups cucci
    cucci : cucci jishu guanli

    13、手工创建账号student
    [root@localhost ~]# vi /etc/group
    在最后一行添加student:x:2000:
    [root@localhost ~]# vi /etc/passwd
    在最后一行添加student:x:2001:2000::/home/student:/bin/bash
    [root@localhost ~]# vi /etc/shadow
    在最后一行添加student:X:18107:0:99999:7:::
    [root@localhost ~]# ls /home/
    a b user
    [root@localhost ~]# mkdir /home/student
    [root@localhost ~]# chown -R student:student /home/student
    [root@localhost ~]# chmod -R go= /home/student
    [root@localhost ~]# cp /etc/skel/.bashrc /home/student/
    [root@localhost ~]# cp /etc/skel/.bash_profile /home/student/
    [root@localhost ~]# cp /etc/skel/.bash_logout /home/student/
    [root@localhost ~]# su student
    [student@localhost root]$


    14、设置权限及归属:
    /guanli目录属组设为guanli
    /guanli/zonghe目录的属组设为zonghe
    /guanli/jishu目录的属组设为jishu
    设置3个目录都是禁止其他用户访问的权限。
    [root@localhost ~]# chown :guanli /guanli
    [root@localhost ~]# chown :guanli /guanli/zonghe
    [root@localhost ~]# chown :jishu /guanli/jishu
    [root@localhost ~]# chmod -R 750 /guanli

    15、建立公共目录/ceshi
    允许技术组内的所有用户读取、写入、执行文件
    禁止其他用户读、写、执行
    [root@localhost ~]# mkdir /ceshi
    [root@localhost ~]# chmod g=rwx /ceshi
    [root@localhost ~]# chmod o=--- /ceshi
    [root@localhost ~]# getfacl /ceshi/
    getfacl: Removing leading '/' from absolute path names
    # file: ceshi/
    # owner: root
    # group: jishu
    user::rwx
    group::rwx
    other::---


    16、清除jerry用户密码
    [root@localhost ~]# passwd -d jerry
    清除用户的密码 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 
    [root@localhost ~]# tail /etc/passwd
    user:x:1000:1000:user:/home/user:/bin/bash
    a1:x:1001:1001::/home/a1:/bin/bash
    aa:x:1002:1002::/home/aa:/bin/bash
    jerry:x:1003:1003::/home/jerry:/bin/bash
    kylin:x:1004:1004::/home/kylin:/bin/bash
    tsengia:x:1005:1005::/home/tsengia:/bin/bash
    obama:x:8888:1006::/home/obama:/bin/bash

    19、通过passwd命令修改kylin用户的最长密码使用期限为60天
    [root@localhost ~]# passwd -x 60 obama 
    调整用户密码老化数据obama。
    passwd: 操作成功


    20、通过id groups finger等命令查看用户handy信息
    [root@localhost ~]# id handy
    uid=1007(handy) gid=1007(handy) 组=1007(handy),2003(jishu),2005(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.

  • 相关阅读:
    webrtc系列之-像老鼠一样打洞
    Ubuntu记录用户IP访问操作信息工具
    OPENVIDU实现同一用户同时发布多个流媒体
    如何使用Nginx-rtmp搭建简易的HLS直播系统
    python实现数据库主从状态监控
    简单分析实现运维利器---批量操作bashshell
    《我与Windows Server 2008R2那点事儿》之域控账户故障事件
    常用动态路由协议之IS-IS
    在云服务器上搭建Python开发环境
    基于Python3接口自动化测试开发相关常用方法
  • 原文地址:https://www.cnblogs.com/wangyuiming/p/11441293.html
Copyright © 2011-2022 走看看