马哥教育第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

相关推荐

  • 马哥教育网络班21期+第四周博客作业

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 [root@C67-X64-A0 ~]# cp -a /etc/skel/ /home/tuser1 [root@C67-X64-A0 ~]# ls&nb…

    Linux干货 2016-07-29
  • HTTP协议

    HTTP协议   HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传送协议。HTTP是一个基于TCP/IP通信协议来传递数据(HTML 文件, 图片文件, 查询结果等)。HTTP协议工作于客户端-服务端架构之上。浏览器作为HT…

    Linux干货 2017-02-15
  • 三剑客-sed小结

     sed是一款流编辑器工具,通常我们用来对文本进行过滤与替换操作,特别是当你想要对几十个配置文件做统一更改时,你会感受到sed的魅力。它一次处理一行内容。处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕。接着处理下一行,这样不断重复,直到…

    系统运维 2016-07-26
  • 【招聘福利】三生石/郑州/6-10K

    三生石科技 岗位职责: 1、熟悉Linux系统环境/内核参数/系统调用接口等,对系统、网络和应用的原理等有较深刻的理解; 2、熟悉Linux操作系统的管理部署、配置和调优; 3、熟悉服务器架构部署、负载均衡、CDN等; 4、了解mysql数据库的基本管理技能,有Apache/Tomcat/MySQL等服务的优化配置经验; 5、了解常用系统自动化监控软件的使用…

    Linux干货 2015-11-10
  • lvs-keepalived

    keepalived: vrrp协议:Virtual Redundant Routing Protocol        术语:        虚拟路由器:Virtual Router &n…

    Linux干货 2017-05-13
  • 如何在CentOS上构架一个简易的局域网web服务器

    首先,要取得适用你系统版本的http源码包,这里推荐两个网站: httpd.apache.org www.kernel.org 根据自己系统的版本下载相应的源码包; CentOS7 下载 httpd-2.4.25.tar CentOS6 下载 httpd-2.2.32.tar 以CentOS 6 示例: 首先,我们先来为http…

    2017-03-09

评论列表(1条)

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

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