linux用户管理实战

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

[root@localhost ~]# who |cut -d ‘ ‘ -f1 |sort -u

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

[root@localhost ~]# who |tail -1

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

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

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

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

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

[root@localhost tmp]# ifconfig|grep ‘inet’|grep -v ‘127.0.0.1’|grep -v ‘inet6’|cut -f10 -d ‘ ‘
10.1.12.210

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

[root@localhost tmp]# ls /etc/*.conf | tr ‘a-z’ ‘A-Z’ >> /tmp/etc.conf

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

[root@localhost tmp]# tree -L 1 /var/ |wc -l
24

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

[root@localhost tmp]# cat /etc/group |sort -t : -k 3 -n | head -10 |cut -d : -f1
root
bin
daemon
sys
adm
tty
disk
lp
mem
kmem

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

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

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

  • 创建组distro,其GID为2016;

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

  • 创建用户mandriva,其ID号为1005;基本组为distro;

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

  •  创建用户mageia,其ID号为1100;家目录为/home/linux;

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

  • 给用户mageia添加密码,密码为mageedu;

[root@localhost tmp]# 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.

  • 删除mandriva,但保留其家目录;

[root@localhost tmp]# userdel mandriva
[root@localhost tmp]# ls /home/
linux mandriva xingqitian

  • 创建用户slackware,其ID号为2002,基本组为distro,附加组peguin;

[root@localhost tmp]# groupadd peguin && useradd slackware -u 2002 -g distro -G peguin
[root@localhost tmp]# id slackware
uid=2002(slackware) gid=2016(distro) groups=2016(distro),2017(peguin)

  • 修改slackware的默认shell为/bin/tcsh;

[root@localhost tmp]# usermod -s /bin/tcsh slackware
[root@localhost tmp]# tail -1 /etc/passwd
slackware:x:2002:2016::/home/slackware:/bin/tcsh

  • 为用户slackware新增附加组admins;

[root@localhost tmp]# groupadd admins
[root@localhost tmp]# usermod -a -G admins slackware
[root@localhost tmp]# id slackware
uid=2002(slackware) gid=2016(distro) groups=2016(distro),2017(peguin),2018(admins)

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/91507

(0)
mgmt.cfgmgmt.cfg
上一篇 2018-02-08
下一篇 2018-02-09

相关推荐

  • Linux 第四天: (07月28日) 练习和作业

    Linux 第四天: (07月28日) 练习和作业         定义别名命令baketc, 每天将/etc/目录下所有文件, 备份到/testdir独立的子目录下, 并要求子目录格式为backupYYYY-mm-dd, 备份过程可见 alias baketc='cp -a /etc/ /testdir/b…

    Linux干货 2016-08-08
  • linux目录管理之整合篇

    目录配置:     1,根目录,所有目录都由根目录衍生出,与开机,还原,系统修复等操作有关。     2,根目录下各子目录应存放的文件。             I,/bin和/sbin目录,/bin放置的是单用户维护模式下能被操作的命令,可以被root和一般…

    Linux干货 2017-05-29
  • FHS文件系统各目录功能

        FHS文件系统各目录功能 前言                  FHS (Files system Hiserarchy Standard)…

    Linux干货 2016-10-17
  • linux安装

    点击开始运行\\172.16.0.1\python10 用户名:python10 密码:python10magedu 运行 ftp://172.16.0.1                                                                                                      …

    Linux干货 2018-03-17
  • 文本处理三剑客之sed

    文本处理三剑客之sed sed概述 sed使用示例 sed的高级应用 sed概述 sed, 作为文本三剑客之一,其定位就是一个编辑器, 而且sed是一个流式编辑器(stream editor),其主要功能是过滤和转换文本。 sed – stream editor for filtering and&…

    Linux干货 2016-08-12