马哥教育第21期-第三周博客作业

1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。
[root@localhost ~]# who | cut -d' ' -f1 | uniq
lqy
root

2、取出最后登录到当前系统的用户的相关信息。
  [root@localhost scripts]# who |tail -1

3、取出当前系统上被用户当作其默认shell的最多的那个shell。
cut -d':' -f7 /etc/passwd |sort|uniq -c | sort -nr | head -1

4、将/etc/passwd中的第三个字段数值最大的后10个用户的信息全部改为大写后保存至/tmp/maxusers.txt文件中。
 sort  -nr -t: -k3 /etc/passwd | head -n 10 | tr 'a-z' 'A-Z' > /tmp/maxusers.txt

5、取出当前主机的IP地址,提示:对ifconfig命令的结果进行切分。
ifconfig | head -2 | tail -1 | grep -o "[^[:space:]].*" | cut -d' ' -f2

6、列出/etc目录下所有以.conf结尾的文件的文件名,并将其名字转换为大写后保存至/tmp/etc.conf文件中。
ls /etc/*.conf | tr 'a-z' 'A-Z' > /tmp/etc.conf

7、显示/var目录下一级子目录或文件的总个数。
 du -sh /var

8、取出/etc/group文件中第三个字段数值最小的10个组的名字。
cat /etc/group | sort -t: -k3  -n | head -10 | cut -d: -f1

9、将/etc/fstab和/etc/issue文件的内容合并为同一个内容后保存至/tmp/etc.test文件中。
cat /etc/fstab /etc/issue > /tmp/etc.test

10、请总结描述用户和组管理类命令的使用方法并完成以下练习:
   (1)、创建组distro,其GID为2016;
      [root@localhost scripts]# groupadd -g 2016 distro
   (2)、创建用户mandriva, 其ID号为1005;基本组为distro;
         [root@localhost scripts]# useradd -u 1005 -g distro mandriva
         [root@localhost scripts]# id mandriva
         uid=1005(mandriva) gid=2016(distro) groups=2016(distro)

   (3)、创建用户mageia,其ID号为1100,家目录为/home/linux;
      [root@localhost scripts]# useradd mageia -u 1100 -d /home/linux
      [root@localhost scripts]# tail -1 /etc/passwd
      mageia:x:1100:1100::/home/linux:/bin/bash

   (4)、给用户mageia添加密码,密码为mageedu;
      [root@localhost scripts]# passwd mageia
   (5)、删除mandriva,但保留其家目录;
      [root@localhost scripts]# userdel mandriva
   (6)、创建用户slackware,其ID号为2002,基本组为distro,附加组peguin;
      [root@localhost scripts]# groupadd peguin
      [root@localhost scripts]# useradd slackware -u 2002 -g distro -G peguin
      [root@localhost scripts]# id slackware
      uid=2002(slackware) gid=2016(distro) groups=2016(distro),2017(peguin)

   (7)、修改slackware的默认shell为/bin/tcsh;
      [root@localhost scripts]# usermod -s /bin/tcsh slackware
      [root@localhost scripts]# cat /etc/passwd | grep "slackware"
      slackware:x:2002:2016::/home/slackware:/bin/tcsh
      [root@localhost scripts]# chsh -s /bin/tcsh slackware

   (8)、为用户slackware新增附加组admins;
      [root@localhost scripts]# usermod -G admins slackware
      [root@localhost scripts]# id slackware
      uid=2002(slackware) gid=2016(distro) groups=2016(distro),2020(admins)

   (9)、为slackware添加密码,且要求密码最短使用期限为3天,最长为180天,警告为3天;
      [root@localhost scripts]# passwd slackware -n 3 -x 108 -w 3
   (10)、添加用户openstack,其ID号为3003, 基本组为clouds,附加组为peguin和nova;
      [root@localhost scripts]# useradd openstack -u 3003 -g clouds -G peguin,nova
      [root@localhost scripts]# id openstack
      uid=3003(openstack) gid=2018(clouds) groups=2018(clouds),2017(peguin),2019(nova)

   (11)、添加系统用户mysql,要求其shell为/sbin/nologin;
      [root@localhost scripts]# useradd -s /bin/nologin mysql
   (12)、使用echo命令,非交互式为openstack添加密码。
      [root@localhost scripts]# echo "passwd" | passwd –stdin openstack

原创文章,作者:21期-扬州-蓝,如若转载,请注明出处:http://www.178linux.com/24253

(0)
21期-扬州-蓝21期-扬州-蓝
上一篇 2016-07-16
下一篇 2016-07-16

相关推荐

  • Nginx+Keepalived实现站点高可用

    Nginx+Keepalived实现站点高可用 vrrp 虚拟路由冗余协议(Virtual Router Redundancy Protocol,简称VRRP)是由IETF提出的解决局域网中配置静态网关出现单点失效现象的路由协议,1998年已推出正式的RFC2338协议标准。VRRP广泛应用在边缘网络中,它的设计目标是支持特定情况下IP数据流量失败转移不会引…

    Linux干货 2016-11-07
  • 我的linux学习方法

    目前记住Linux单词命令过于困难,现在主要记住linux的命令的作用及用处,不记得单词可以百度查找做多了自然就记住了。

    Linux干货 2018-03-17
  • 第二周作业

    Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。 ls命令 显示目标列表 ls 选项 参数 -a 显示所有目录文件 -A 显示所有文件目录除了 “.” “..” -d 仅显示目录名 -i 显示文件索引节点号(inode) cp命令 复制命令,将一个文件或目录复制到指定文件或目录、 cp 选项 参数 -f 强行复制文件或目录,不论目标文…

    Linux笔记 2018-07-29
  • 进程及任务管理

    进程概念 内核的功用:进程管理、文件系统、网络功能、内存管理、驱动程序、安全功能等 Process: 运行中的程序的一个副本,是被载入内存的一个指令集合     进程ID(Process ID,PID)号码被用来标记各个进程     UID、GID、和SELi…

    Linux干货 2016-09-09
  • 马哥教育网络班21期+第五周课程练习

    1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行; ~]# egrep ^[[:space:]] /boot/grub/grub.conf 2、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行; ~]# egrep …

    Linux干货 2016-08-08
  • Linux学习笔记——权限管理

    Linux学习笔记——权限管理 前言: Linux下的权限管理与日常使用的windows有众多与众不同之处。这些特性使得Linux在实际生产作业中更加安全与高效,发挥着各种灵活的作用。本文简要写下笔者对Linux权限管理的理解,供参考与复习,欢迎指正。 回顾: 确认文件的权限与所有者: 使用ll(即ls -l) 命令可查看这个文件的详细信息。 $ ll da…

    2018-04-07

评论列表(1条)

  • 马哥教育
    马哥教育 2016-07-17 20:13

    写的很好,排版还可以在改进一下,加油