linux运维-第3周作业
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux运维-第3周作业相关的知识,希望对你有一定的参考价值。
本周作业内容:
1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。
#who | tr -s [[:space:]] | cut -d" " -f1 | sort -u
[[email protected] bin]# who | tr -s [[:space:]] | cut -d" " -f1 | sort -u
kzxjwb
root
2、取出最后登录到当前系统的用户的相关信息。
#last | head -1
[[email protected] bin]# last | head -1
root pts/4 223.72.80.48 Mon Oct 24 23:07 still logged in
3、取出当前系统上被用户当作其默认shell的最多的那个shell。
#cat /etc/passwd | cut -d":" -f7 | uniq -c | sort -n | tail -1 | tr -s [[:space:]] | cut -d" " -f3
[[email protected] webapps]# cat /etc/passwd | cut -d":" -f7 | uniq -c | sort -n | tail -1 | tr -s [[:space:]] | cut -d" " -f3
/sbin/nologin
4、将/etc/passw d 中的第三个字段数值最大的后10个用户的信息全部改为大写后保存至/tmp/maxusers.txt文件中。
[[email protected] /]# cat /etc/passwd | sort -t":" -nk3 | tail -10 | tr [a-z] [A-Z] > /tmp/maxusers.txt
[[email protected] /]# cat /tmp/maxusers.txt
USER2:X:1024:1026::/HOME/USER2:/BIN/BASH
USER3:X:1025:1027::/HOME/USER3:/BIN/BASH
USER4:X:1026:1028::/HOME/USER4:/BIN/BASH
USER5:X:1027:1029::/HOME/USER5:/BIN/BASH
USER6:X:1028:1030::/HOME/USER6:/BIN/BASH
USER7:X:1029:1031::/HOME/USER7:/BIN/BASH
USER8:X:1030:1032::/HOME/USER8:/BIN/BASH
USER9:X:1031:1033::/HOME/USER9:/BIN/BASH
USER10:X:1032:1034::/HOME/USER10:/BIN/BASH
USER11:X:1033:1035::/HOME/USER11:/BIN/BASH
5、取出当前主机的IP地址,提示:对ifconfig命令的结果进行切分。
#ifconfig | grep -E "inet addr" | cut -d":" -f2 | cut -d" " -f1
6、列出/etc目录下所有以.conf结尾的文件的文件名,并将其名字转换为大写后保存至/tmp/etc.conf文件中。
[[email protected] /]# ls /etc/*.conf | tr [a-z] [A-Z] > /tmp/etc.conf
[[email protected] /]# 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/NTP.CONF
/ETC/RESOLV.CONF
/ETC/RSYSLOG.CONF
/ETC/SESTATUS.CONF
/ETC/SUDO.CONF
/ETC/SUDO-LDAP.CONF
/ETC/SYSCTL.CONF
/ETC/TCSD.CONF
/ETC/VCONSOLE.CONF
/ETC/YUM.CONF
7、显示/var目录下一级子目录或文件的总个数。
[[email protected] /]# ll /var | wc -l
22
8、取出/etc/group文件中第三个字段数值最小的10个组的名字。
[[email protected] /]# cat /etc/group | sort -t":" -nk3 | head -10 | cut -d":" -f1
root
bin
daemon
sys
adm
tty
disk
lp
9、将/etc/fstab和/etc/issue文件的内容合并为同一个内容后保存至/tmp/etc.test文件中。
[[email protected] /]# cat /etc/fstab /etc/issue > /tmp/etc.test
[[email protected] /]# cat /tmp/etc.test
#
# /etc/fstab
# Created by anaconda on Fri Mar 11 01:59:10 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
#
UUID=e7edf137-5d28-407f-98b9-804ead7732b2 / xfs defaults 0 0
UUID=6d3d5767-9a65-4f80-ae84-87d2c324edbd /boot xfs defaults 0 0
UUID=63a207f4-e7ae-4b27-87c5-f56054d49206 /data xfs defaults 0 0
UUID=d0e6dd42-8f9c-4fba-b450-d068475fbb14 /tmp xfs defaults 0 0
UUID=9015aa16-40bd-46db-8c6b-b019513a8111 /usr xfs defaults 0 0
UUID=dcbba68b-953b-4cd5-9b92-88801ef89c0a swap swap defaults 0 0
\S
Kernel \r on an \m
10、请总结描述用户和组管理类命令的使用方法并完成以下练习:
(1)、创建组distro,其GID为2016;
[[email protected] ~]# groupadd -g 2016 distro
[[email protected] ~]# cat /etc/group |tail -1
distro:x:2016:
(2)、创建用户mandriva, 其ID号为1005;基本组为distro;
[[email protected] ~]# useradd -u 1005 -g distro mandriva
useradd: UID 1005 is not unique
[[email protected] ~]# useradd -u 1105 -g distro mandriva
[[email protected] ~]# id mandriva
uid=1105(mandriva) gid=2016(distro) groups=2016(distro)
(3)、创建用户mageia,其ID号为1100,家目录为/home/linux;
[[email protected] ~]# useradd -u 1100 -d /home/linux mageia
[[email protected] ~]# cat /etc/passwd | tail -1
mageia:x:1100:1100::/home/linux:/bin/bash
(4)、给用户mageia添加密码,密码为mageedu;
[[email protected] ~]# echo "mageedu" | passwd –stdin mageia
passwd: Only one user name may be specified.
(5)、删除mandriva,但保留其家目录;
[[email protected] ~]# cat /etc/passwd | grep mandriva
mandriva:x:1105:2016::/home/mandriva:/bin/bash
[[email protected] ~]# userdel mandriva
(6)、创建用户slackware,其ID号为2002,基本组为distro,附加组peguin;
[[email protected] ~]# groupadd peguin
[[email protected] ~]# useradd -u 2002 -g distro -G peguin slackware
[[email protected] ~]# id slackware
uid=2002(slackware) gid=2016(distro) groups=2016(distro),2017(peguin)
(7)、修改slackware的默认shell为/bin/tcsh;
[[email protected] ~]# cat /etc//passwd | tail -1
slackware:x:2002:2016::/home/slackware:/bin/bash
[[email protected] ~]# usermod -s /bin/tcsh slackware
[[email protected] ~]# cat /etc/passwd | tail -1
slackware:x:2002:2016::/home/slackware:/bin/tcsh
[[email protected] ~]#
(8)、为用户slackware新增附加组admins;
[[email protected] ~]# groupadd admins
[[email protected] ~]# usermod -aG admins slackware
[[email protected] ~]# id slackware
uid=2002(slackware) gid=2016(distro) groups=2016(distro),2017(peguin),2018(admins)
(9)、为slackware添加密码,且要求密码最短使用期限为3天,最长为180天,警告为3天;
[[email protected] ~]# echo slackware | passwd –stdin -n3 -x180 -w3 slackware
passwd: Only one user name may be specified.
[[email protected] ~]# cat /etc/shadow | tail -1
slackware:!!:17098:0:99999:7:::
(10)、添加用户openstack,其ID号为3003, 基本组为clouds,附加组为peguin和nova;
useradd -u 3003 -g clouds -G peguin openstack
(11)、添加系统用户mysql,要求其shell为/sbin/nologin;
#useradd -r -s /sbin/nologin mysql
(12)、使用echo命令,非交互式为openstack添加密码。
echo openstack | passwd –stdin openstack &> /dev/null
本文出自 “9099360” 博客,请务必保留此出处http://9109360.blog.51cto.com/9099360/1865243
以上是关于linux运维-第3周作业的主要内容,如果未能解决你的问题,请参考以下文章
megeedu Linux+Python高级运维班 3期 第五周作业