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 22:21
下一篇 2016-09-15 22:21

相关推荐

  • 用户管理和组管理

         Linux是一个多用户多任务的系统 ,因此学习用户管理和组管理,对我们工作和学习有很大的帮助。用户是你登录这个操作系统的凭证,因此用户的创建和修改,删除是用户管理的基本工作,所以你掌握这些,对你的工作有很好的帮助。 用户账号管理 /etc/passwd username:x: UId:gid:comment:…

    Linux干货 2016-08-10
  • Linux之账号管理

    Linux之账号管理 一、新增与删除用户:useradd,相关配置文件,passwd,usermod,userdel 在Linux登录系统时会输入账号和密码,所以创建用户也需要这两个数据。新建用户用useradd命令,密码的给予则用passwd命令。 useradd 1.添加新用户 -u: -u  uid username 创建用户时指定uid(如…

    2017-07-23
  • 正则表达式基础以及grep的简单使用

    正则表达式基础以及grep的简单使用   1,定义 正则表达式是你所定义的模式模板,Linux可以用它来过滤文本。Linux工具(比如grep、sed、gawk)能够在处理数据时使用正则表达式对数据进行模式匹配。如果数据匹配模式,它就会被接受并进一步处理;如果数据不匹配,它就会被滤掉。 2,正则表达式的原则 (1)正则表达式模式都区分大小写。(2)…

    2017-04-09
  • sed的详细用法

    sed(Stream EDitor)是一款流编辑器,用来对文本进行过滤与替换操作。其原理是:通过文件或管道读取文件内容,但是sed默认并不直接修改源文件,而是一次仅读取文件的一行至模式空间(pattern space)根据sed指令进行编辑并输出结果后清除模式空间,即所有的操作都是在模式空间中进行的。 语法格式 sed [option]…&nb…

    Linux干货 2016-11-14
  • 推荐-常用RAID级别详解

    一、RAID是什么       RAID(Redundant Arrays of Indent Disks)的名称是独立磁盘冗余阵列,是一种通过将多块硬盘按照某种特定的结构组织起来当做一块硬盘来使用的技术,多块硬盘不同的组织结构我们称之为RAID的级别。而RAID技术的特性主要表现在两个方面: (1)提高硬盘…

    Linux干货 2016-03-27
  • 一步到位实现zabbix安装

    简介 zabbix是一个基于WEB界面的提供分布式网络监视功能的企业级的开源解决方案。相对于cacti和nagios而言,zabbix最大的特点是分布式监控,自动发现,自定义监控项目。 一、监控系统所具备的四个要素 1、数据采集       zabbix采集数据的手段有SNMP、zabbix的Agent、IPMI ag…

    2015-03-02

评论列表(1条)

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

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