马哥教育第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)
上一篇 2016-07-16 22:28
下一篇 2016-07-16 22:28

相关推荐

  • Linux发行版介绍

    一,Linux是什么?      Linux是一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和UNIX的多用户、多任务、支持多线程和多CPU的操作系统。它能运行主要的UNIX工具软件、应用程序和网络协议。它支持32位和64位硬件。Linux继承了Unix以网络为核心的设计思想,是一个性能稳定的多用户网络操作系统…

    2016-10-29
  • 通用二进制安装MySQL(MariaDB)

    一、前言     MySQL是一个关系型数据库管理系统,是最流行的关系型数据库管理系统,由于其体积小、速度快、总体拥有成本低,并且之前是完全开源,所以大受欢迎。但由于后面MySQL卖给了SUN,随后SUN被Oracle收购,虽然也有开源免费版本,但是很多功能都需要另外购买商业版本,导致现在MySQL使用份额逐渐减少。所…

    Linux干货 2015-10-15
  • 我的第一篇博客

        大家好,欢迎阅读我的博客!     今天是我生平第一次写博客,恩  为什么现在才开始写呢?     其实是作业要求 哈哈!虽然是写作业,本萌新也是很拼的!     希望在以后学习li…

    2017-07-10
  • 第六章:文本处理工具

    第六章:文本处理工具 文本查看命令(cat) 分页查看文件(more) 文本查看上下翻页(less) 显示头部(head) 显示尾部(tail) 按列抽取文本cut 合并文件paste 收集文本统计数据wc 文本排序sort 删除重复uniq 比较文件diff 复制对文件改变patch 文本搜索工具grep egrep 及扩展的正则表达式 作业: 第六章:文…

    Linux干货 2016-08-10
  • 第9天:压缩,任务,rpm包

    http://note.youdao.com/yws/public/redirect/share?id=b3e4fc37bdd98991638dce69ce3eea53&type=false

    Linux干货 2016-08-18
  • httpd功能配置之访问控制

       httpd服务可以实现对资源访问控制,可以根据IP地址和用户两种方式进行控制。    一、用户认证控制      1、在站点根目录下创建一个目录及一个页面文件      2、修改/var/httpd/conf/httpd.conf文件   &n…

    Linux干货 2016-03-11

评论列表(1条)

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

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