天天看點

馬哥2016全新Linux+Python高端運維班第三周作業

1、列出目前系統上所有已經登入的使用者的使用者名,注意:同一個使用者登入多次,則隻顯示一次即可。

who | cut -d' ' -f1 | sort | uniq

w -h | cut -d' ' -f1 | sort|uniq

2、取出最後登入到目前系統的使用者的相關資訊。

last | head -1

3、取出目前系統上被使用者當作其預設shell的最多的那個shell。

cat /etc/passwd | cut -d: -f7 | sort | uniq -c | sort -n | tail -1

4、将/etc/passwd中的第三個字段數值最大的後10個使用者的資訊全部改為大寫後儲存至/tmp/maxusers.txt檔案中。

cat /etc/passwd | sort -t: -k3 -n | tail -10 | tr 'a-z' 'A-Z' >/tmp/maxusers.txt(直接儲存)

cat /etc/passwd | sort -t: -k3 -n | tail -10 | tr 'a-z' 'A-Z' | tee /tmp/maxusers.txt(輸出并儲存)

5、取出目前主機的IP位址,提示:對ifconfig指令的結果進行切分。

ifconfig | head -2 | tail -1|cut -d: -f2| cut -d' ' -f1

ifconfig | grep 'inet addr'|cut -d: -f2|cut -d' ' -f1|head -1

6、列出/etc目錄下所有以.conf結尾的檔案的檔案名,并将其名字轉換為大寫後儲存至/tmp/etc.conf檔案中。

ls /etc/*.conf | tr 'a-z' 'A-Z' >/tmp/etc.conf

7、顯示/var目錄下一級子目錄或檔案的總個數。

ll -a /var | wc -l (包含隐藏)

ll /var | wc -l (不包含隐藏)

8、取出/etc/group檔案中第三個字段數值最小的10個組的名字。

cat /etc/group |sort -t: -k3 -n | head -10 | cut -d: -f1(新手一步一步更安全)

sort -t: -k3 -n /etc/group | head -10 | cut -d: -f1

9、将/etc/fstab和/etc/issue檔案的内容合并為同一個内容後儲存至/tmp/etc.test檔案中。

cat /etc/fstab /etc/issue >>/tmp/etc.test

10、請總結描述使用者群組管理類指令的使用方法并完成以下練習:

   (1)、建立組distro,其GID為2016;

groupadd -g 2016 distro

   (2)、建立使用者mandriva, 其ID号為1005;基本組為distro;

useradd -u 1005 -g distro mandriva

   (3)、建立使用者mageia,其ID号為1100,家目錄為/home/linux;

useradd -u 1100 -d /home/linux

   (4)、給使用者mageia添加密碼,密碼為mageedu;

passwd mageia

   (5)、删除mandriva,但保留其家目錄;

userdel mandriva

   (6)、建立使用者slackware,其ID号為2002,基本組為distro,附加組peguin;

useradd -u 2002 -g distro -G peguin slackware

   (7)、修改slackware的預設shell為/bin/tcsh;

usermod -s /bin/tcsh slackware

   (8)、為使用者slackware新增附加組admins;

usermod -G admins -a slackware

id slackware檢視

   (9)、為slackware添加密碼,且要求密碼最短使用期限為3天,最長為180天,警告為3天;

passwd -n3 -x180 -w3 slackware

cat /etc/shadow檢視

   (10)、添加使用者openstack,其ID号為3003, 基本組為clouds,附加組為peguin和nova;

useradd -u 3003 -g clouds -G peguin,nova openstack

   (11)、添加系統使用者mysql,要求其shell為/sbin/nologin;

useradd -r -s /sbin/nologin mysql

cat /etc/passwd 或id mysql      檢視uid,gid群組id

   (12)、使用echo指令,非互動式為openstack添加密碼。

echo 'magedu123' | passwd --stdin mysql

繼續閱讀