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 12:01
下一篇 2018-02-09 21:23

相关推荐

  • 马哥教育网络班22期+第6周课程练习 忍者乱太郎喻成

    请详细总结vim编辑器的使用并完成以下练习题 1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#cp /etc/rc.d/rc.sysinit /tmp方法一 vim法在vim下用 : 进入命令行模式     %s/^&nbs…

    Linux干货 2016-10-24
  • 高级文件文件系统管理之btrfs系统

    一.概述 btrfs文件系统:     技术预览版     btrfs (B-tree,Butter FS,Better FS),GPL,Oracle,2007,CoW     ext3/ext4,xfs 核心特性:  &nbsp…

    Linux干货 2016-09-11
  • Shell脚本编程—数组、字符串处理

    数组 变量:存储单个元素的内存空间 数组:存储多个元素的连续的内存空间     数组名:整个数组只有一个名字;     数组索引:编号从0开始;          [数组名索引]  &nbs…

    Linux干货 2016-08-30
  • sed命令及vim编辑器

    sed[option]… 'script' inputfile…选项:-n:不输出模式空间内容的自动打印-e: 多点编辑-f /PATH/TO/SCRIPT_FILE: 从指定文件中读取编辑脚本-r: 支持使用扩展正则表达式-i: 原处编辑script:'地址命令' 1.地址定界:(1) 不给地…

    Linux干货 2016-08-11
  • 防火墙

    iptables笔记整理

    Linux干货 2018-03-05
  • 马哥教育网络班21期+第17周课程练习

    1、结合图形描述LVS的工作原理; lvs是基于内核的虚拟主机用来做四层的负载均衡,工作在netfilter框架的INPUT链上,有四种模式,上图为lvs-nat lvs-nat:有DNAT功能,支持端口映射,请求报文和响应报文都需要经过Director 请求过程:cip–>vip,Director,cip–>rip 响应…

    Linux干货 2016-12-26