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

相关推荐

  • LVS

    LVS概述 1.LVS:Linux Virtual Server全称叫做linux虚拟服务器,是一个虚拟的服务器集群系统。本项目在1998年5月由章文嵩博士成立,是中国国内最早出现的自由软件项目之一。四层路由器(交换),根据请求报文的目标IP和目标协议及端口将其调度转发至后端主机集群中的某台RealServer(真实服务器),根据调度算法来挑选RS; 主要有…

    Linux干货 2016-11-07
  • N25_第三周作业

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 [root@aio ~]# who|cut -d" " -f1|uniq root 2、取出最后登录到当前系统的用户的相关信息。 [root@aio ~]# who| …

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

    一、计算机原理及组成部分 数学家冯·诺依曼,按不同功能把计算机分成了五大组成部分:运算器、控制器、存储器、输入设备、输入出设备。 现代计算机把运算器和控制器集成在一起,称为CPU,主要进行各种数据运算和对各种命令进行解释;存储器被分为两类,一类以内存为代表的随机存储设备,主要特点是速度快,容量有限,断电后信息就消失,另一类是硬盘为代表的外部存储设备,容量大,…

    Linux干货 2016-06-26
  • SUID_SGID_Sticky简单总结

    参考: http://blog.chinaunix.net/uid-25314474-id-3313109.html —————————————权限——&#82…

    Linux干货 2015-09-14
  • N28_第二周

    linux文件管理命令

    Linux干货 2017-12-10
  • history命令详解

       有效地使用命令历史机制将会使效率获得极大提升。history:   保存你输入的命令历史。 可以用它来重复执行命令。   history [-c] [-d offset] [n]   history -anrw [filename]   history …

    2017-03-26

评论列表(1条)

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

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