linu

作者: mirror_jin | 来源:发表于2016-10-07 20:44 被阅读0次

    1.列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可
    [root@foundation0 ~]# who | cut -d ' ' -f 1 | sort -u
    root
    jin

    2.取出最后登录到当前系统的用户的相关信息
    [jin@foundation0 ~]$ who | sort -r -k 3 | head -n 1 > /tmp/haha.txt
    [jin@foundation0 ~]$ cat /tmp/haha.txt
    jin pts/5 2016-10-5 12:05 (192.168.0.100)

    3.取出当前系统上被用户当作其默认shell的最多的那个shell
    [jin@foundation0 ~]$ cut -d: -f /etc/passwd | sort | uniq -c | sort -f | tail -n 1 > /tmp/sh
    [jin@foundation0 ~]$ cat /tmp/shell.txt
    39 /sbin/nologin

    4.将/etc/passwd 中的第三个字段数值最大的后10个用户的信息全部改为大写后保存至/tmp/maxusers.txt文件中
    [jin@foundation0 ~]$ sort -t : -k 3 -n /etc/passwd | tail -n 10 | tr [a-z] [A-Z] > /tmp/maxus
    [jin@foundation0 ~]$ cat /tmp/maxusers.txt

    5.取出当前主机的IP地址,提示:对ifconfig命令的结果进行切分
    [jin@foundation0 ~]$ ifconfig eno16777736 | grep -w " inet" | cut -d ' ' -f 10
    192.168.0.100

    6.列出/etc目录下所有以.conf结尾的文件的文件名,并将其名字转换为大写后保存至/tmp/etc.conf文件中
    [root@foundation0 ~]# ls /etc/ |grep '.conf$' > /tmp/etc.conf
    [root@foundation0 ~]# cat /tmp/etc.conf
    asound.conf
    autofs.conf
    autofs_ldap_auth.conf
    brltty.conf
    cgconfig.conf
    cgrules.conf
    cgsnapshot_blacklist.conf
    chrony.conf
    dleyna-server-service.conf
    dnsmasq.conf
    dracut.conf
    e2fsck.conf
    fprintd.conf
    fuse.conf
    hba.conf
    host.conf
    idmapd.conf
    ipsec.conf
    kdump.conf
    krb5.conf
    ksmtuned.conf
    ld.so.conf
    libaudit.conf
    libuser.conf
    locale.conf
    logrotate.conf
    man_db.conf
    mke2fs.conf
    mtools.conf
    nfsmount.conf
    nsswitch.conf
    ntp.conf
    numad.conf
    oddjobd.conf
    pbm2ppa.conf
    pnm2ppa.conf
    radvd.conf
    request-key.conf
    resolv.conf
    rsyncd.conf
    rsyslog.conf
    sestatus.conf
    sos.conf
    sudo.conf
    sudo-ldap.conf
    sysctl.conf
    tcsd.conf
    updatedb.conf
    usb_modeswitch.conf
    vconsole.conf
    wvdial.conf
    7.显示/var目录下一级子目录或文件的总个数
    [root@foundation0 ~]# 11 -a /var/ | wc -1
    26

    8.取出/etc/group文件中第三个字段数值最小的10个组的名字
    [jin@foundation0 ~]$ cat /etc/group | sort -t: -k 3 -n -r | tail -n 10
    kmem:x:9:
    mem:x:8:
    lp:x:7:
    disk:x:6:
    tty:x:5:
    adm:x:4:
    sys:x:3:
    daemon:x:2:
    bin:x:1:
    root:x:0:

    9.将/etc/fstab和/etc/issue文件的内容合并为同一个内容后保存至/tmp/etc.test文件中
    [jin@foundation0 ~]$ cat /etc/fstab /etc/issue > /tmp/etc.test
    [jin@foundation0 ~]$ cat /tmp/etc.test

    10.请总结描述用户和组管理类命令的使用方法并完成以下练习:
    (1)、创建组distro,其GID为2016
    [root@foundation0 ~]# groupadd -g 2016 distro

    (2)、创建用户mandriva, 其ID号为1005;基本组为distro
    [root@foundation0 ~]# useradd -u 1005 -g distro mandriva

    (3)、创建用户mageia,其ID号为1100,家目录为/home/linux
    [root@foundation0 ~]# useradd -u 1100 -d /home/linux mageia

    (4)、给用户mageia添加密码,密码为redhat
    [root@foundation0 ~]# passwd mageia
    Changing password for user mageia.
    New password:
    BAD PASSWORD: The password is shorter than 8 characters
    Retype new password:
    passwd: all authentication tokens updated successfully

    (5)、删除mandriva,但保留其家目录
    [root@foundation0 ~]# userdel mandriva

    (6)、创建用户slackware,其ID号为2002,基本组为distro,附加组peguin
    [root@foundation0 ~]# groupadd peguin
    [root@foundation0 ~]# useradd -u 2002 -g distro -G peguin slackware
    [root@foundation0 ~]# id slackware
    uid=2002(slackware) gid=2016(distro) groups=2016(distro),2017(peguin)

    (7)、修改slackware的默认shell为/bin/tcsh
    [root@foundation0 home]# usermod -s /bin/tcsh slackware
    [root@foundation0 home]# tail -n 1 /etc/passwd
    slackware:x:2002:2016::/home/slackware:/bin/tcsh

    (8)、为用户slackware新增附加组admins
    [root@foundation0 ~]# usermod -a -G admins slackware
    [root@foundation0 ~]# id slackware

    (9)、为slackware添加密码,且要求密码最短使用期限为3天,最长为180天,警告为3天
    [root@foundation0 ~]# # passwd redhat | passwd slackware -n 3 -x 180 -w 3
    Adjusting aging data for user slackware.
    passwd: Success
    New password:
    BAD PASSWORD: The password is shorter than 7 characters
    Retype new password:
    [root@localhost jun_shao]# tail -n 1 /etc/shadow
    slackware:$6$6SP2wfD/$9OyF6m0WBSnB/QvMeKcy/Qaa494ctEDVDWX2jktapof..6Ud.yCEnkPE3bYUWfr20wy6DWdIU6x1FIoum6Kd20:17033:3:180:3:::

    (10)、添加用户openstack,其ID号为3003, 基本组为clouds,附加组为peguin和nova
    [root@foundation0 ~]# useradd -u 3003 -g clouds -G peguin,nova openstack
    [root@foundation0 ~]# id openstack
    uid=3003(openstack)gid=2019(clouds)groups=2019(clouds),2017(peguin),2020(nova)

    (11)、添加系统用户mysql,要求其shell为/sbin/nologin
    [root@foundation0 ~]# useradd -r -s /sbin/nologin mysq1
    [root@foundation0 ~]# tail -n 1 /etc/passwd
    mysql:x:987:982::/home/mysql:/sbin/nologin

    (12)、使用echo命令,非交互式为openstack添加密码
    [root@foundation0 ~]# echo "redhat" | passwd --stdin openstack

    相关文章

      网友评论

          本文标题: linu

          本文链接:https://www.haomeiwen.com/subject/vqnyyttx.html