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

相关推荐

  • 文件的查找

    文件的查找 使用locate命令 默认从根开始搜索 非实时查找(数据库查找) locate 文件名 查询系统上预建的的文件索引数据库    /var/lib/mlocate/mlocate.db 依赖于事先构建的索引 索引的构建是在系统较为空闲时自动进行(周期性任务),管理员手动更新数据库(updatedb)。注意工作中不能轻易…

    Linux干货 2016-08-18
  • bash功能特性四 文件名通配符

    文件名通配(globbing)     通配符在bash中是一个非常有用的功能,它可以使我们更加方便的查找符合特定条件的文件。     文件通配符的包括以下几种:          *:任意长度的任意…

    Linux干货 2015-04-21
  • LNMP的虚拟主机配置http和https

    项目实战:    搭建LNMP环境:Linux+Nginx+Mysql(MariaDB)+php(php-fpm),创建多个虚拟主机:    主机1提供正常的http服务,用于安装wordpress博客;    主机2提供正常的https服…

    Linux干货 2016-10-30
  • 加密通讯过程

    一次加密通讯的过程 1、client_hello   客户端发起请求,以明文传输请求信息,包含版本信息,加密套件候选列表,压缩算法候选列表,随机数,扩展字段等信息,相关信息如下: 支持的最高TSL协议版本version,从低到高依次 SSLv2 SSLv3 TLSv1 TLSv1.1 TLSv1.2,当前基本不再使用低于 TLSv1 的版本 客户端支持的加密…

    Linux干货 2017-02-07
  • N25-第一周 总结

    一、描述计算机的组成及其功能     CPU:包括运算器、控制器、寄存器、缓存,计算枢纽,网络的包处理、磁盘读写、数学计算等。     内存:加载数据,提高计算速度,程序被加载到内存成为进程运行。     输入:键盘、鼠标     输出:打印机、显示器 二、按系列罗列linux的…

    Linux干货 2016-12-05
  • linux发行版说明和哲学思想,以及常用命令说明

    Linux发行版主要流行的版本有3种:debian,slackware,red 其说明和特点如下图。 Linux哲学思想: 1、一切皆文件;所有的一切都变成了文件!不光是软件方面的比如传统文件、目录、字符设备、还包括硬件或者接口。如鼠标/mouse、打印机/lp、还有接口比如/usb. 2、单一目的的小程序;一个程序只负责干一件事,而且要把这个任务做好。 3…

    Linux干货 2016-10-30

评论列表(1条)

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

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