马哥教育网络班21期第3周课程练习

1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。

who | cut -d" " -f 1 |sort |uniq

2、取出最后登录到当前系统的用户的相关信息。

last | head -1

3、取出当前系统上被用户当作其默认shell的最多的那个shell。

cat /etc/passwd | cut -d":" -f 7 | sort | uniq -c | sort -rn | head -1

4、将/etc/passwd中的第三个字段数值最大的后10个用户的信息全部改为大写后保存至/tmp/maxusers.txt文件中。

cat /etc/passwd | sort -t":" -k 3 -rn | cut -d":" -f 1 | tr "a-z" "A-Z" | head > /tmp/maxusers.txt

5、取出当前主机的IP地址,提示:对ifconfig命令的结果进行切分。

ifconfig | grep '\<inet\>' | sed 's/^[ \t]*//g' |cut -d" " -f 2

6、列出/etc目录下所有以.conf结尾的文件的文件名,并将其名字转换为大写后保存至/tmp/etc.conf文件中。

# ls /etc/*.conf | tr "a-z" "A-Z" >> /tmp/etc.conf

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

# ls -al /var | wc -l

8、取出/etc/group文件中第三个字段数值最小的10个组的名字。

# sort -n -t":" -k 3 /etc/group | head

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

# cat /etc/{fstab,issue} > /tmp/etc.test

10、请总结描述用户和组管理类命令的使用方法并完成以下练习:

   (1)、创建组distro,其GID为2016;

[root@centos7study ~]# groupadd -g 2016 distro

  (2)、创建用户mandriva, 其ID号为1005;基本组为distro;

[root@centos7study ~]# useradd -u 1005 -g 2016 mandriva

   (3)、创建用户mageia,其ID号为1100,家目录为/home/linux;

[root@centos7study ~]# useradd -u 1100 -d /home/linux mageia

   (4)、给用户mageia添加密码,密码为mageedu;

[root@centos7study ~]# 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@centos7study ~]# userdel mandriva

   (6)、创建用户slackware,其ID号为2002,基本组为distro,附加组peguin;

[root@centos7study ~]# groupadd peguin
[root@centos7study ~]# useradd -u 2002 -g distro -G peguin slackware

   (7)、修改slackware的默认shell为/bin/tcsh;

[root@centos7study ~]# usermod -s /bin/tcsh

   (8)、为用户slackware新增附加组admins;

[root@centos7study ~]# groupadd admins
[root@centos7study ~]# usermod  -a -G admins slackware

   (9)、为slackware添加密码,且要求密码最短使用期限为3天,最长为180天,警告为3天;

[root@centos7study ~]# passwd -n 3 -x 180 -w 3 slackware

   (10)、添加用户openstack,其ID号为3003, 基本组为clouds,附加组为peguin和nova;

[root@centos7study ~]# groupadd nova
[root@centos7study ~]# groupadd clouds
[root@centos7study ~]# useradd -u 3003 -g clouds -G peguin,nova openstack

   (11)、添加系统用户mysql,要求其shell为/sbin/nologin;

[root@centos7study ~]# useradd -r -s /sbin/nologin mysql

   (12)、使用echo命令,非交互式为openstack添加密码。

[root@centos7study ~]# echo "magedu" | passwd --stdin openstack
Changing password for user openstack.
passwd: all authentication tokens updated successfully.

原创文章,作者:N21-孟然,如若转载,请注明出处:http://www.178linux.com/25354

(0)
N21-孟然N21-孟然
上一篇 2016-07-29 12:11
下一篇 2016-07-29 15:22

相关推荐

  • web服务 初步

    Web Service初步 一、引言 Web服务也是一个C/S架构,服务器端就是一个进程,客户端是一个浏览器。我们打开浏览器的时候,都会看到hppt,https的字样,然后才是输入网址,这两个协议是web服务的应用层协议,用来实现某些具体应用的。像https,前面学习openssl的时候也接触过,https=http+ssl。 web的传输层协议用到了tcp…

    Linux干货 2016-12-09
  • Linux 第三天: (07月26日) Linux使用帮助

    Linux 第三天: (07月26日) Linux使用帮助         whatis 显示命令的简短描述makewhatis centos6 制作数据库mandb centos7 制作数据库 help COMMAND 内部命令man bash 内部命令COMMAND –help -h 外部命令man C…

    Linux干货 2016-08-08
  • 第五周作业

    1、显示当前系统上root,fedora或user1用户的默认shell。 [root@hostname ~]# grep -E ‘^(root|fedora|user1)’ /etc/passwd | cut -d: -f1,7 root:/bin/bash 2、找出/etc/rc.d/init.d/functions文件中某词后面跟一组小括号的行,形如:…

    Linux干货 2017-08-04
  • DNS 笔记

    Ø DNS查询。工作流程如下图         n  客户端的DNS:8.8.8.8 /etc/hosts  14.215.177.38 www.baidu.com n  客户端访问www.baidu.com 不用向DSN服务器发生查询,只需要查询本地的 /e…

    Linux干货 2016-08-15
  • Linux基础学习总结(三)

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

    Linux干货 2016-10-03
  • 全球敏捷运维峰会Gdevops 2017成都站嘉宾主题提前看!

    2017年全球敏捷运维峰会(Gdevops, Global Devops Summit)将于2017年在成都、上海、北京、广州四城全面启动,本次峰会由上海市经济和信息化委员会指导,上海市云计算产业促进中心、DBAplus社群主办,数十家媒体单位共同支持,活动家提供全球敏捷运维峰会在线报名服务。 成都站即将于13日启航,搭车地址:https://www.huo…

    Linux干货 2017-05-11

评论列表(1条)

  • 马哥教育
    马哥教育 2016-07-29 16:01

    写的很好,排版也很棒,加油