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

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

[root@root@iZ23olnit2eZ ~]# who | cut -d' ' -f1 | sort -u
root

2.列出最后登录到当前系统的用户的相关信息

[root@iZ23olnit2eZ ~]# lastlog | egrep 'root'
root             pts/0    58.251.228.49    Sun Jul 24 22:23:22 +0800 2016

3.读取当前系统上被用户当做其默认shell最多的那个shell

[root@iZ23olnit2eZ ~]# cut -d: -f7 /etc/passwd | uniq -cd | sort -n | tail -1
     18 /sbin/nologin

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

[root@iZ23olnit2eZ ~]# sort -t : -k 3 -n /etc/passwd | tail -10 | tr 'a-z' 'A-Z' > /tmp/etc.conf

5.取出当前主机的ip地址

[root@iZ23olnit2eZ ~]# ifconfig eth0 | grep 'inet addr' | cut -d: -f2 | cut -d' ' -f1

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

[root@iZ23olnit2eZ ~]# ls /etc/*.conf | tr '[:lower:]' '[:upper:]' >> /tmp/etc.conf

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

[root@iZ23olnit2eZ ~]# ls /var | wc -l
21

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

[root@iZ23olnit2eZ ~]# sort -t : -k 3 -n /etc/group | head -10 | cut -d: -f1

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

[root@iZ23olnit2eZ ~]# cat /etc/issue /etc/fstab >> /tmp/etc.test

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

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

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

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

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

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

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

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

[root@iZ23olnit2eZ ~]# echo 'mageedu' | passwd --stdin mageia
更改用户 mageia 的密码 。
passwd: 所有的身份验证令牌已经成功更新。

(5)删除mandriva,但保留其家目录

[root@iZ23olnit2eZ ~]# userdel mandriva

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

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

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

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

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

[root@iZ23olnit2eZ ~]# usermod -G admins slackware

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

[root@iZ23olnit2eZ ~]# passwd -n 3 -x 180 -w 3 slackware
[root@iZ23olnit2eZ ~]# chage -m 3 -M 180 -W 3 slackware

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

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

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

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

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

[root@iZ23olnit2eZ ~]#  echo 'redhat' | passwd --stdin openstack

原创文章,作者:N21_郁蓝,如若转载,请注明出处:http://www.178linux.com/25865

(0)
N21_郁蓝N21_郁蓝
上一篇 2016-07-26 16:56
下一篇 2016-07-26 17:00

相关推荐

  • Linux基础知识之选择循环执行

    1.选择执行:     a.单分支if语句:         if 判断条件;then(此处必须有;和then  then可以单独占一行)        &nb…

    Linux干货 2016-08-18
  • xen虚拟化基础篇

    Xen介绍:  xen是一个开放的源代码虚拟机监视器,有剑桥大学研发。它打算在单个计算机上运行多达128个满足特征的操作系统,操作系统必须进行显示地修改("移植")以在Xen上运行(但是提供对用户应用的兼容性)。这使得无需特殊硬件支持,就能达到高性能的虚拟化。 Xen由三部分组成:     第一部分…

    Linux干货 2015-08-26
  • 马哥教育网络班21期-第六周课程练习

    请详细总结vim编辑器的使用并完成以下练习题1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#; #cp /etc/rc.d/rc.sysinit /tmp #vim /tmp/rc.sysinit :%s/^[[:space:]]/#…

    Linux干货 2016-08-15
  • N31-5

    rpm包管理、计划和周期任务、sed命令

    Linux笔记 2018-07-18
  • grub知识与故障排除

    知识点回顾 at 任务的存放位置:/var/spool/at/ crond 任务存放位置:/var/spool/cron/username 查看服务有没有运行 centos6:  service  atd  status    chkconfig –list atd chkconfig atd o…

    Linux干货 2016-09-13

评论列表(1条)

  • 马哥教育
    马哥教育 2016-07-27 11:34

    写的很好,排版也很棒,如果有多个网卡怎么取ip地址?加油