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

相关推荐

  • keepalived双主模型的实现

    一、简介  keepalived 简介:是服务器高可用的一个重要软件,它的核心组件有vrrp ,stack, checker ,ipvs, warpper, watch dog  它是vrrp协议的实现,原生设计目的为高可用ipvs服务;keepalived能够通过配置文件中定义生成ipvs规则 并能够对RS的健康状态进行检测;vrrp_…

    Linux干货 2016-08-30
  • linux中管道重定向

    linux中管道重定向 Linux 给程序提供三种I/O设备:    查看是否成功  echo $?      需要再执行命令后直接使用               &n…

    Linux干货 2017-02-21
  • 浅谈bash shell 变量

    一、简述 变量是指内存空间的命名,指向内存中一个或一组地址。bash shell中的变量属于弱类型变量,使用变量无需声明、不需要指定类型,默认为字符型变量。 二、变量命名、赋值、引用 (1)命名规则:     1.只能使用字母,数字,下划线;并且不能使用数字开头。     2.不…

    Linux干货 2016-08-15
  • 利用heartbeat构建高可用http

    一、实验准备:  1)实验环境:          2)同步时间;确保可以使用主机名通信;确保可以使用ssh秘钥方式进行彼此登录;由于是两台设备,需要仲裁;  确保可以使用主机名通信 web1修改hosts文件如下: 172.16.2.12 web1.linux.com…

    Linux干货 2015-07-08
  • bind-9.9.5编译安装

    bind-9.9.5编译安装 §·bind-9.9.5编译安装大概步骤 步骤一 :下载源码包bind-9.9.5 ; 步骤二 :按需求选择模块或功能 ./configure ;  # ./configure  –prefix=/usr/local/bind9  –sysconfdir=…

    Linux干货 2016-10-09
  • 文件系统

    文件系统 文件和目录被组织成一个单根倒置树结构 文件系统从根目录下开始,用“/”表示 文件名称区分大小写 以.开头的文件为隐藏文件   一个.表示本目录。 两个..表示根目录 路径分隔的/      路径分割为正斜线分割 文件有两类数据:        元数据:metadata …

    Linux干货 2017-05-02

评论列表(1条)

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

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