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

相关推荐

  • N28 第三周【1】:grep和文本处理工具的使用

    grep一些练习 1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 [root@localhost ~]# who |cut -d” ” -f1 |sort -u root 2、取出最后登录到当前系统的用户的相关信息。 [root@localhost ~]# last |cut -d” ” -f1|head -1 |…

    Linux干货 2017-12-19
  • btrfs 文件系统

    简介   Btrfs((B-tree,ButterFS ,Better FS通常念成Butter FS),由Oracle于2007年宣布并进行中的COW(copy-on-write式)文件系统。继ext3/4文件系统之后linux又有了比较强大的文件系统(btrfs文件系统),btrfs文件系统不仅可以将ex…

    Linux干货 2016-02-19
  • Linux初学笔记(markdown格式)

    Linux基础命令笔记

    Linux干货 2018-03-26
  • 马哥教育网络班21期+第2周作业

    1、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。     cp复制,mv移动,rm删除     1、cp:             1,用法: cp [OPTIO…

    Linux干货 2016-07-12
  • Linux基础知识

    一、描述计算机的组成及其功能 计算机由运算器、控制器、存储器、I/O设备五大部件组成。 运算器和控制器统称为中央处理器,俗称CPU。    1、运算器:实现算术运算和逻辑运算的部件;    2、控制器:计算机的指挥系统,控制计算机的其他部件,使得个部件有条不紊地协调工作;    3、存储器:存储数据…

    2017-07-08
  • 第7天:磁盘文件管理

    http://note.youdao.com/yws/public/redirect/share?id=57ab13d4749920de1fbb0d4953fcd21b&type=false

    Linux干货 2016-08-18

评论列表(1条)

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

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