马哥教育网络班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

相关推荐

  • lvs初探

    LVS 简述 HA基础知识 lvs配置 简述 什么是lvs? lvs是linux virtual server linux虚拟服务的缩写,通过一台调度服务器来调度收到的请求并分发给后端的real server。 lvs的功能是什么? lvs能够实现在大并发的情况下,将前端调度器收到的请求分发给后端服务器处理,实现了负载均衡集群的作用。 lb基础知识 lb集群…

    Linux干货 2016-05-31
  • LAMP及部署wordpress/phpMyadmin

    LAMP详解 wordpress安装 一、引言 lamp含义:黄金组合。简要介绍一下下面这四个东西吧。linux,不用说了有很多发行版本,主流的三大版本是Debian系列,RedHat系列,slackware系列。apache,全称叫Apache HTTP Server,是世界使用排名第一的web服务器软件,httpd是超文本传输协议http服务器的主程序。…

    Linux干货 2016-12-13
  • 什么是文件系统

    文件系统:层级结构;有索引; /: 原初起点; 倒置树状结构; /dev/pts/2: 最左侧/: 表示根目录 其它的/: 表示路径分隔符 Linux的路径分隔符是/ Windows的是\ 文件的路径表示: 绝对路径:从根开始表示出的路径  相对路径:从当前位置开始表示出的路径 文件名使用法则: 严格区分字符大小写:file1, File1, FI…

    Linux干货 2016-10-29
  • 马哥教育网络班21期-第四周课程练习

    第四周作业 1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 [root@localhost ~]# cp -a /etc/skel /home/tuse1   [root@localhost …

    Linux干货 2016-07-17
  • 马哥教育21期网络班—第12周课程+练习—-LAMP练习下

    在LAMP架构中,请分别以fpm工作为独立守护进程的方式来支持http yum groupinstall "Development Tools" "Server Platform Development"——>安装包组1、编译安装Apacheht…

    Linux干货 2016-09-26
  • linux文件权限

                                                      &nbsp…

    Linux干货 2016-08-04

评论列表(1条)

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

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