马哥教育网络班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
下一篇 2016-07-29

相关推荐

  • 浅谈TCP三次握手和四次分手

          TCP(Transmission Control Protocol传输控制协议)是一种面向连接的、可靠的、基于字节流的传输层通信协议提供可靠的连接服务,采用三次握手确认建立一个连接,比如我们去访问一个网站,从输入网址到页面显示我们所想要浏览的内容,这个过程其中就包含了小编要说的三次握手和四次挥手。 一、首先我们来了解…

    2017-09-02
  • linux 常用命令

    linux   常用命令:      pwd: printing working directory                     显示工作目录       cd:cha…

    Linux干货 2016-10-28
  • iptables练习

    iptables实战 1.开启防火墙 systemctl start firewalld 2.清空所有的默认规则,定义自己的规则 iptables -F 查看此时的iptables iptables -nL Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD…

    2015-03-15
  • N25-第二周做业

    一.Linux上的文件管理类命令都有哪些,其常用的使用方法和演示        1.目录管理的命令    mkdir rmdir              1)…

    Linux干货 2016-12-11
  • memcache

      memcached: memcached is a high-performance, distributed memory object caching system, generic in nature, but&nbsp…

    Linux干货 2016-11-01
  • 高级文件系统管理

    高级文件系统管理 本章内容  设定文件系统配额  设定和管理软RAID设备  配置逻辑卷  设定LVM快照  btrfs文件系统 配置配额系统 综述 • 在内核中执行 • 以文件系统为单位启用 • 对不同组或者用户的策略不同    &nb…

    Linux干货 2016-09-01

评论列表(1条)

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

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