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

相关推荐

  • vim编辑器-练习题

    1 、复制/etc/profile至/tmp/目录,用查找替换命令删除/tmp/profile文件中的行首的空白字符 #cp /etc/profile /tmp #vim /tmp/profile :%s/^[[:space:]]\+// 2 、复制/etc/rc.d/init.d/functions 文件至/tmp 目录,用查找替换命令为/tmp/func…

    Linux干货 2016-08-15
  • Net-25第5周作业

    1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行; grep -E "^[[:space:]]+" /boot/grub/grub.conf 2、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行; grep&nbsp…

    Linux干货 2017-01-03
  • tomcat

    tomcat 简述 tomcat的结构 tomcat配置 总结与问题 简述 什么是tomcat? tomcat是一个java2ee的web容器的残缺实现,提供了serverlet,asp转换等组件。 tomcat的功能? tomcat能够将asp文件通过转换,转换为serverlet格式,这样子就可以被java识别运行并将结果转为asp响应,并且tomcat…

    2016-06-24
  • chmod命令详细用法

    指令名称 : chmod 使用权限 : 所有使用者 使用方式 : chmod [-cfvR] [–help] [–version] mode file… 说明 : …

    Linux干货 2016-10-17
  • 网络管理

    网络管理 本章内容 网络概念 OSI模型 网络设备 TCP/IP IP地址 配置网络 实现网络组 测试网络 网络工具 为linux网卡配置ip地址,不是给网卡配置地址,是给内核的网络功能配置,地址是属于内核。为内核配置即时生效,修改配置文件,是永久生效。ifconfig 配置信息,会立即生效,但是重启网络服务或主机,都失效。网络服务/etc/init.d/n…

    Linux干货 2016-09-05
  • vim的总结、练习和周期性任务

    vim:VI的增强版,是一款可视化功能非常强大的文本编辑器,属于全屏编辑器。 vim:使用方法: 命令格式:    ~]#vim [options] [file ..]      选项:        +#:打开文件后,直接让光标处于第#行首;   …

    Linux干货 2017-08-14

评论列表(1条)

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

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