N-22-南京-修 第三周博客作业

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

[xujie@localhost ~]$ who | cut -d " " -f1 | sort -u

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

[root@localhost xujie]# last -x | head -1

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

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

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

[xujie@localhost ~]$ sort -t ':' -k 3 -n /etc/passwd | tail -10 | tr [[:lower:]] [[:upper:]] > /tmp/maxusers.txt

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

[root@localhost network-scripts]# ifconfig | grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'

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

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

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

 [root@localhost lib]# find /var -type f | wc -l

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

[root@localhost lib]# sort -n -t ":" -k 3 /etc/group | head -10 | cut -d ":" -f 1

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

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

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

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

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

   [root@localhost tmp]# cat /etc/group | grep distro

   distro:x:2016:

   

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

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

   [root@localhost tmp]# cat /etc/passwd | grep mandriva

    mandriva:x:1100:2016::/home/mandriva:/bin/bash

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

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

   [root@localhost tmp]# cat /etc/passwd | grep mageia

   mageia:x:1100:1100::/home/linux:/bin/bas

   

   

#   (4)、给用户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.

   

   

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

   [root@localhost xujie]# userdel mandriva

   [root@localhost xujie]# cd ..

   [root@localhost home]# ls

   arch  asdf  centos  gentoo  linux  mandriva  xujie

   

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

   [root@localhost home]# groupadd peguin

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

   [root@localhost home]# cat /etc/passwd | grep slackware

   slackware:x:2002:2016::/home/slackware:/bin/bash

   [root@localhost home]# id slackware

   uid=2002(slackware) gid=2016(distro) groups=2016(distro),2017(peguin)

   

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

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

   [root@localhost home]# cat /etc/passwd | grep slackware

   slackware:x:2002:2016::/home/slackware:/bin/tcsh

   [root@localhost home]# 

   

   

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

   [root@localhost home]# usermod -G admins slackware

   usermod: group 'admins' does not exist

   [root@localhost home]# groupadd admins

   [root@localhost home]# usermod -G admins slackware

   [root@localhost home]# id slackware

   uid=2002(slackware) gid=2016(distro) groups=2016(distro),2018(admins)

   [root@localhost home]# 

   

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

     [root@localhost home]# passwd slackware

     Changing password for user slackware.

     New password: 

     BAD PASSWORD: The password fails the dictionary check – it is too simplistic/systematic

     Retype new password: 

     passwd: all authentication tokens updated successfully.

     [root@localhost home]# passwd -n 3 -x 180 -w 3 slackware 

     Adjusting aging data for user slackware.

     passwd: Success

[root@localhost home]# cat /etc/shadow | grep slackware

     slackware:$6$gk2px/TP$bOxfKmZYQs0g15JyJ2elalp8lfQaAioXWb3F96sBUrfH0NQMitSu1H3COZ7dzIXltpuKt0.88TNuCWk9EIu7F.:17056:3:180:3:::

     [root@localhost home]# 

 

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

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

   useradd: group 'clouds' does not exist

   [root@localhost home]# groupadd clouds

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

   [root@localhost home]# groupadd nova

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

   [root@localhost home]# id openstack

   uid=3003(openstack) gid=2019(clouds) groups=2019(clouds),2017(peguin),2020(nova)

   [root@localhost home]# 

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

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

   useradd: group mysql exists – if you want to add this user to that group, use -g.

[root@localhost home]# id centos

uid=1001(centos) gid=1005(mysql) groups=1005(mysql)

[root@localhost home]# groupdel mysql

groupdel: cannot remove the primary group of user 'centos'

[root@localhost home]# userdel -r centos

userdel: group centos not removed because it is not the primary group of user centos.

[root@localhost home]# groupdel mysql

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

[root@localhost home]# id mysql

uid=996(mysql) gid=994(mysql) groups=994(mysql)

[root@localhost home]# 

   

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

   [root@localhost xujie]# echo "1234" | passwd –stdin "openstack"

Changing password for user openstack.

passwd: all authentication tokens updated successfully.

[root@localhost ~]# su -l xujie

Last login: Mon Sep 12 07:23:37 EDT 2016 on pts/0

[xujie@localhost ~]$ su -l openstack

Password: 

Last failed login: Mon Sep 12 07:24:02 EDT 2016 on pts/0

There were 5 failed login attempts since the last successful login.

[openstack@localhost ~]$

原创文章,作者:N22-南京-修,如若转载,请注明出处:http://www.178linux.com/45780

(0)
N22-南京-修N22-南京-修
上一篇 2016-09-15
下一篇 2016-09-15

相关推荐

  • 用户管理

    http://www.jianshu.com/p/a07ae29ca345

    Linux干货 2017-07-23
  • Ansible安装及简单使用

    简介: ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、cfengine、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。ansible是基于模块工作的,本身没有批量部署的能力。真正具有批量部署的是ansible所运行的模块,ansible只是提供一种框架。主要包…

    Linux干货 2016-08-07
  • vim编辑器

                                                      &nbsp…

    Linux干货 2015-12-19
  • FHS-文件系统层级结构标准

    文件系统层级结构标准(FHS:Filesystem Hierarchy Standard) 文件系统层次结构标准(英语:Filesystem Hierarchy Standard,FHS)定义了Linux操作系统中的主要目录及目录内容。当前的版本是2.3,在2004年1月29日公布。多数Linux发行版遵从FHS标准并且声明其自身政策以维护FHS的要求。然而…

    Linux干货 2016-10-16
  • 16 文本处理工具

    文本处理工具一 一、杂项知识整理 1、ps axo user,ruser,cmd 查看命令发起者的身份和真正的登录身份: [root@localhost test]# ps axo user,ruser,cmd USER     RUSER  &nb…

    Linux干货 2016-08-05
  • 第十八周

    “1、为LNMP架构添加memcached支持,并完成对缓存效果的测试报告; 架构(3台centos7) nginx与php 192.168.1.108    nginx,php-fpm,php-mysql php-pecl-memcache mysql         192…

    2017-08-21

评论列表(1条)

  • 马哥教育
    马哥教育 2016-09-19 18:42

    ip地址匹配不正确,没有好好听咱们的分享课吧,那里面讲过ip地址怎么匹配