N24 W3 博客作业

第三周 "

 

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

[root@localhost ~]# who | cut –d’ ‘ –f1 | uniq

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

[root@localhost ~]# id `who | tail -n 1 | cut –d’ ‘ –f1`

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

[root@localhost ~]# cat /etc/passwd | cut -d: -f7 | uniq -c | sort -n | tail -n 1

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

[root@localhost ~]# cat /etc/passwd | sort –n –k 3 –t: | tail –n 10 | tr ‘a-z’ ‘A-Z’ > /tmp/maxusers.txt

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

[root@localhost ~]# ip addr | grep inet | cut -d' ' -f6 | sort -n -k 1 -t. | tail -n 1 | cut -d/ -f1

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

[root@localhost ~]# mkdir /tmp/etc

[root@localhost ~]# ls /etc | grep "".conf"$" | tr 'a-z' 'A-Z' >/tmp/etc/conf

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

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

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

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

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

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

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

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

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

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

[root@localhost ~]# useradd -u 1005 -g distro mandriva

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

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

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

[root@localhost ~]# passwd mageia

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

[root@localhost ~]# userdel mageia

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

[root@localhost ~]# groupadd peguin

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

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

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

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

[root@localhost ~]# usermod -G admins,peguin slackware

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

[root@localhost ~]# echo "123" | passwd –stdin slackware && chage -m 3 -M 180 -W 3 slackware

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

[root@localhost ~]# groupadd nova, clouds

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

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

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

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

[root@localhost ~]# echo "123" | passwd –stdin openstack

原创文章,作者:Net24-仙鹤,如若转载,请注明出处:http://www.178linux.com/58899

(0)
Net24-仙鹤Net24-仙鹤
上一篇 2016-11-14 08:29
下一篇 2016-11-14 11:07

相关推荐

  • 用户组管理系列(二):权限设置

    1、权限简介    操作系统中每个文件都拥有特定的权限、所属用户和所属组。权限是操作系统用来限制资源访问的机制,在Linux中权限一般分为读(readable)、写(writable)和执行(excutable),分为三组。分别对应文件的属主(owner),属组(group)和其他用户(other),通过这样的机制来限制哪些用户、哪些组可…

    Linux干货 2016-08-05
  • linux 目录结构

    该文章主要来自于网络资料进行整理 目录结构参考地址: http://www.iteye.com/topic/1125162 http://yangrong.blog.51cto.com/6945369/1288072 http://itlab.idcquan.com/linux/administer/939529_1.html http://itlab.id…

    系统运维 2015-12-19
  • echo

    echo命令详解

    Linux干货 2018-02-28
  • grep初步认识

    grep初步认识

    Linux干货 2017-12-03
  • 三.Linux博客-2016年7月24日帮助、history、别名、tree

    格式说明: 操作 概念 命令 说明及举例 三-1.帮助、history、别名、tree touch /etc/nologin 使普通用户不能登录(创建了一个文件,删掉就可以登陆)   ll /etc/nologin 查看那个文件 -rm -f /etc/  删…

    Linux干货 2016-08-23