本周的blog开始使用了代码语言格式,我原本以为自然的才是最好的,orginal的才是最美的,但是我错了。。。我发现同学们都在各种markdown,各种排版。我说过我早已过了care这些的年纪,但是我不能脱离群体单独存在,所以我底下了傲娇的头。
本周开始blog标题改为英文,逼格满满,麦满分~
下面开始第$wk_num周的作业
[root@dhcp-10-129-6-166 ~]# wk_num=$[$(date -d 2016-12-12 +%U) - $(date -d 2016-11-21 +%U)]
-
列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可
[root@dhcp-10-129-6-166 ~]# w -s -h | cut -f 1 -d ' ' | sort -u root slackwar [root@dhcp-10-129-6-166 ~]#
2. 取出最后登录到当前系统的用户的相关信息
[slackware@dhcp-10-129-6-166 ~]$ last | head -1 openstac pts/3 cnbjsl-jm0jtz1.d Mon Dec 19 11:53 - 17:00 (05:07)
3. 取出当前系统上被用户当作其默认shell的最多的那个shell
[root@dhcp-10-129-6-166 ~]# cat /etc/passwd | cut -f 7 -d : | uniq -c 1 /bin/bash 4 /sbin/nologin 1 /bin/sync 1 /sbin/shutdown 1 /sbin/halt 13 /sbin/nologin 3 /bin/bash 1 /bin/nologin [root@dhcp-10-129-6-166 ~]# cat /etc/passwd | cut -f 7 -d : | uniq -c | sort 1 /bin/bash 1 /bin/nologin 1 /bin/sync 1 /sbin/halt 1 /sbin/shutdown 3 /bin/bash 4 /sbin/nologin 13 /sbin/nologin [root@dhcp-10-129-6-166 ~]# cat /etc/passwd | cut -f 7 -d : | uniq -c | sort | tail -1 13 /sbin/nologin [root@dhcp-10-129-6-166 ~]# cat /etc/passwd | cut -f 7 -d : | uniq -c | sort | tail -1 | tr -s ' ' | cut -f 3 -d ' ' /sbin/nologin [root@dhcp-10-129-6-166 ~]#
4. 将/etc/passwd中第三个字段数值最大的后10个用户的信息全部改为大写后保存至/tmp/maxusers.txt文件中
[root@dhcp-10-129-6-166 ~]# touch /tmp/maxusers.txt [root@dhcp-10-129-6-166 ~]# cat /etc/passwd | cut -f 3 -d : | sort -n | tail | tee /tmp/maxusers.txt 89 99 170 996 997 998 999 1100 2002 2003 [root@dhcp-10-129-6-166 ~]# cat /tmp/maxusers.txt 89 99 170 996 997 998 999 1100 2002 2003 [root@dhcp-10-129-6-166 ~]#
5. 取出当前主机的IP地址,提示:对ifconfig命令的结果进行切分
[root@dhcp-10-129-6-166 ~]# ifconfig | tr -s ' ' | cut -f 3 -d ' ' | head -2 | tail -1 10.129.6.166 [root@dhcp-10-12
6. 列出/etc目录下所有以.conf结尾的文件的文件名,并将其名字转换为大写后保存至/tmp/etc.conf文件中
[root@dhcp-10-129-6-166 ~]# ls /etc/*.conf | tr [a-z] [A-Z] >> /tmp/etc. etc.conf etc.test [root@dhcp-10-129-6-166 ~]# ls /etc/*.conf | tr [a-z] [A-Z] >> /tmp/etc.conf [root@dhcp-10-129-6-166 ~]# ls /etc/*.conf /etc/asound.conf /etc/krb5.conf /etc/man_db.conf /etc/sudo-ldap.conf /etc/dnsmasq.conf /etc/ld.so.conf /etc/mke2fs.conf /etc/sudo.conf /etc/dracut.conf /etc/libaudit.conf /etc/nsswitch.conf /etc/sysctl.conf /etc/e2fsck.conf /etc/libuser.conf /etc/resolv.conf /etc/tcsd.conf /etc/host.conf /etc/locale.conf /etc/rsyslog.conf /etc/vconsole.conf /etc/kdump.conf /etc/logrotate.conf /etc/sestatus.conf /etc/yum.conf [root@dhcp-10-129-6-166 ~]# cat /tmp/etc.conf /ETC/ASOUND.CONF /ETC/DNSMASQ.CONF /ETC/DRACUT.CONF /ETC/E2FSCK.CONF /ETC/HOST.CONF /ETC/KDUMP.CONF /ETC/KRB5.CONF /ETC/LD.SO.CONF /ETC/LIBAUDIT.CONF /ETC/LIBUSER.CONF /ETC/LOCALE.CONF /ETC/LOGROTATE.CONF /ETC/MAN_DB.CONF /ETC/MKE2FS.CONF /ETC/NSSWITCH.CONF /ETC/RESOLV.CONF /ETC/RSYSLOG.CONF /ETC/SESTATUS.CONF /ETC/SUDO-LDAP.CONF /ETC/SUDO.CONF /ETC/SYSCTL.CONF /ETC/TCSD.CONF /ETC/VCONSOLE.CONF /ETC/YUM.CONF [root@dhcp-10-129-6-166 ~]#
7. 显示/var目录下一级子目录或文件的总个数
[root@dhcp-10-129-6-166 ~]# ll -a /var | wc -l 42 [root@dhcp-10-129-6-166 ~]#
8. 取出/etc/group文件中第三个字段数值最小的10个组的名字
[root@dhcp-10-129-6-166 ~]# cat /etc/passwd | sort -n -k 3 -t : | cut -f 1 -d : | head root bin daemon adm lp sync shutdown halt mail operator [root@dhcp-10-129-6-166 ~]#
9. 将/etc/fstab和/etc/issue文件的内容合并为同一个内容后保存至/tmp/etc.test文件中
[root@dhcp-10-129-6-166 ~]# touch /tmp/etc.test [root@dhcp-10-129-6-166 ~]# cat -s /etc/{fstab,issue} >> /tmp/etc.test [root@dhcp-10-129-6-166 ~]# cat /tmp/etc.test # # /etc/fstab # Created by anaconda on Thu Dec 1 21:51:31 2016 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/centos-root / xfs defaults 0 0 UUID=6f4ecd86-4eea-468b-81ba-2f3e7b3a59c4 /boot xfs defaults 0 0 /dev/mapper/centos-swap swap swap defaults 0 0 \S Kernel \r on an \m
10. 请总结描述用户和组管理类命令的使用方法并完成以下练习:
a.创建组distro,其GIDwei 2016
[root@dhcp-10-129-6-166 ~]# groupadd distro -g 2016 [root@dhcp-10-129-6-166 ~]# tail -1 /etc/group distro:x:2016:
b.创建用户mandriva,其UID为1005,基本组为distro.
[root@dhcp-10-129-6-166 ~]# useradd mandriva -u 1005 -g distro [root@dhcp-10-129-6-166 ~]# tail1 -1 /etc/passwd -bash: tail1: 未找到命令 [root@dhcp-10-129-6-166 ~]# tail -1 /etc/passwd mandriva:x:1005:2016::/home/mandriva:/bin/bash
c.创建用户megeia, 其UID为1100,家目录为/home/linux
[root@dhcp-10-129-6-166 ~]# mkdir /home/linux [root@dhcp-10-129-6-166 ~]# ll /home total 0 drwxr-xr-x. 2 root root 6 Dec 19 09:57 linux drwx------. 2 mandriva distro 59 Dec 19 09:55 mandriva drwx------. 2 slackware slackware 59 Dec 2 00:41 slackware [root@dhcp-10-129-6-166 ~]# useradd mageia -u 1100 -d /home/linux useradd: warning: the home directory already exists. Not copying any file from skel directory into it. [root@dhcp-10-129-6-166 ~]# !t ail -1 /etc/passwd mageia:x:1100:1100::/home/linux:/bin/bash [root@dhcp-10-129-6-166 ~]# man chown man: can't set the locale; make sure $LC_* and $LANG are correct [root@dhcp-10-129-6-166 ~]# chown mageia:mageia /home/linux [root@dhcp-10-129-6-166 ~]# ll /home total 0 drwxr-xr-x. 2 mageia mageia 6 Dec 19 09:57 linux drwx------. 2 mandriva distro 59 Dec 19 09:55 mandriva drwx------. 2 slackware slackware 59 Dec 2 00:41 slackware
d.给用户megeia添加密码,密码为mageedu
[root@dhcp-10-129-6-166 ~]# 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.
e.删除mandriva,但保留其家目录
[root@dhcp-10-129-6-166 ~]# userdel mandriva [root@dhcp-10-129-6-166 ~]# ll /home total 0 drwxr-xr-x. 2 mageia mageia 6 Dec 19 09:57 linux drwx------. 2 1005 distro 59 Dec 19 09:55 mandriva drwx------. 2 slackware slackware 59 Dec 2 00:41 slackware
f.创建用户slackware,其ID号为2002,基本组为distro, 附加组为peguin
[root@dhcp-10-129-6-166 ~]# useradd slackware -u 2002 -g distro -G peguin useradd: user 'slackware' already exists [root@dhcp-10-129-6-166 ~]# userdel -r slackware [root@dhcp-10-129-6-166 ~]# useradd slackware -u 2002 -g distro -G peguin [root@dhcp-10-129-6-166 ~]# tail -1 /etc/passwd slackware:x:2002:2016::/home/slackware:/bin/bash [root@dhcp-10-129-6-166 ~]# tail /etc/group dbus:x:81: polkitd:x:995: dip:x:40: tss:x:59: postdrop:x:90: postfix:x:89: sshd:x:74: distro:x:2016: mageia:x:1100: peguin:x:2017:slackware
g.修改slackware的默认shell为/bin/tcsh
[root@dhcp-10-129-6-166 ~]# usermod slackware -s /bin/tcsh [root@dhcp-10-129-6-166 ~]# cat /etc/passwd | grep slackware slackware:x:2002:2016::/home/slackware:/bin/tcsh
h.为用户slackware新增附件组admins
[root@dhcp-10-129-6-166 ~]# cat /etc/group | grep admins [root@dhcp-10-129-6-166 ~]# groupadd admins [root@dhcp-10-129-6-166 ~]# usermod slackware -G admins [root@dhcp-10-129-6-166 ~]# tail /etc/group polkitd:x:995: dip:x:40: tss:x:59: postdrop:x:90: postfix:x:89: sshd:x:74: distro:x:2016: mageia:x:1100: peguin:x:2017: admins:x:2018:slackware [root@dhcp-10-129-6-166 ~]# ^C
i.为用户slackware添加密码,且要求密码最短使用期限为3天,最长为180天,警告3天
[root@dhcp-10-129-6-166 ~]# passwd slackware -n 3 -x 180 -w 3 Adjusting aging data for user slackware. passwd: Success [root@dhcp-10-129-6-166 ~]# cat /etc/shadow | grep slackware slackware:!!:17154:3:180:3::: [root@dhcp-10-129-6-166 ~]# ^C
j.添加用户openstack, 其ID号为3003,基本组为clouds, 附加组为peguin和nova
[root@dhcp-10-129-6-166 ~]# useradd openstack -g clouds -G peguin,nova [root@dhcp-10-129-6-166 ~]# tail /etc/group tss:x:59: postdrop:x:90: postfix:x:89: sshd:x:74: distro:x:2016: mageia:x:1100: peguin:x:2017:openstack admins:x:2018:slackware nova:x:2019:openstack clouds:x:2020: [root@dhcp-10-129-6-166 ~]# tail /etc/passwd | grep openstack openstack:x:2003:2020::/home/openstack:/bin/bash [root@dhcp-10-129-6-166 ~]#
k.添加系统用户mysql, 要求其shell为/bin/nologin
[root@dhcp-10-129-6-166 ~]# useradd mysql -r -s /bin/nologin [root@dhcp-10-129-6-166 ~]# cat /etc/passwd | grep mysql ysql:x:996:994::/home/mysql:/bin/nologin
l.使用echo命令,非交互式为openstack添加密码
[root@dhcp-10-129-6-166 ~]# echo openstack | passwd openstack --stdin Changing password for user openstack. passwd: all authentication tokens updated successfully. [root@dhcp-10-129-6-166 ~]#
原创文章,作者:JL,如若转载,请注明出处:http://www.178linux.com/64184