N23-第三周博客作業

1、列出當前系統上所有已經登錄的用戶的用戶名,注意:同一個用戶登錄多次,則只顯示一次即可。

[root@localhost ~]# who | cut -d' ' -f1 | sort -u

1475223694827370.jpg

2、取出最后登錄到當前系統的用戶的相關信息。

[root@localhost ~]# last -1 | head -1

1475226743367296.jpg

3、取出當前系統上被用戶當作其默認shell的最多的那個shell。

[root@localhost ~]# cat /etc/passwd | cut -d: -f7 | sort | uniq -c | sort -n | tail -1

1475225099423319.jpg

4、將/etc/passwd中的第三個字段數值最大的后10個用戶的信息全部改為大寫后保存至/tmp/maxusers.txt文件中。

[root@localhost ~]# cat /etc/passwd | sort -t: -k3 -n | tail | tr [a-z] [A-Z] > /tmp/maxusers.text

1475226465308214.jpg

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

[root@localhost ~]# ifconfig | egrep -o "([0-9]{3}\.[0-9]{3}\.[0-9]+\.[0-9]+)" | sort -u | head -1

1475226536651954.jpg

6、列出/etc目錄下所有以.conf結尾的文件的文件名,并將其名字轉換為大寫后保存至/tmp/etc.conf文件中。

[root@localhost ~]# ls -a /etc/*.conf | tr [a-z] [A-Z] > /tmp/etc.conf

1474874896249480.jpg

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

~]# ll /var | wc -l

1475992593760170.jpg

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

[root@localhost ~]# cat /etc/group | sort -t: -k3 -n | head -10 | cut -d: -f1

1475227173762005.jpg

9、將/etc/fstab和/etc/issue文件的內容合并為同一個內容后保存至/tmp/etc.test文件中。

[root@localhost ~]# cat /etc/{fstab,issue} > /tmp/etc.test

1474875151404454.jpg

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

10.(1)、創建組distro,其GID為2016;

[root@localhost ~]# groupadd -g 2016 distro

1474876281409590.jpg


10.(2)、創建用戶mandriva, 其ID號為1005;基本組為distro;

[root@localhost ~]# useradd -u 1005 -g distro mandriva

1474878401978040.jpg

1474878414475467.jpg

1474878432367825.jpg


10.(3)、創建用戶mageia,其ID號為1100,家目錄為/home/linux;

[root@localhost ~]# useradd -u 1100 -d /home/linux mageia

1474878951474750.jpg


10.(4)、給用戶mageia添加密碼,密碼為mageedu;

[root@localhost ~]# echo "mageedu" | passwd –stdin mageia

1474879555657901.jpg


10.(5)、刪除mandriva,但保留其家目錄;

[root@localhost ~]# userdel mandriva

1474879709237702.jpg

使用userdel不加-r選項,默認保留其家目錄


10.(6)、創建用戶slackware,其ID號為2002,基本組為distro,附加組peguin;

[root@localhost ~]# useradd -u 2002 -g distro -G peguin slackware

1474880242933875.jpg

1474880345147070.jpg


10.(7)、修改slackware的默認shell為/bin/tcsh;

[root@localhost ~]# usermod -s /bin/tcsh slackware

1474880657148741.jpg

10.(8)、為用戶slackware新增附加組admins;

[root@localhost ~]# usermod -a -G admins slackware

1474880945790681.jpg


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

[root@localhost ~]# passwd -n 3 -x 180 -w 3 slackware

1474881852373187.jpg



10.(10)、添加用戶openstack,其ID號為3003, 基本組為clouds,附加組為peguin和nova;

[root@localhost ~]# useradd -u 3003 -g clouds -G peguin,nova openstack

1474942777675523.jpg

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

[root@localhost ~]# useradd -r -s /sbin/nologin mysql

1474942798914853.jpg


10.(12)、使用echo命令,非交互式為openstack添加密碼。

[root@localhost ~]# echo "JA-94%skd" | passwd –stdin openstack &> /dev/null

1474942819805829.jpg


原創文章,作者:hotpoint,如若轉載,請注明出處:http://www.www58058.com/49317

(0)
hotpointhotpoint
上一篇 2016-12-05 17:03
下一篇 2016-12-05 17:03

相關推薦

  • 文件查找(find)

                                  …

    2017-04-11
  • Linux計劃任務

    Linux計劃任務

    Linux干貨 2017-10-27
  • nfs 共享實驗

    nfs全稱為:network file system    網絡文件系統 在Linux里可以理解為將一個文件夾變成共享文件夾,讓其他用戶都可以訪問。而訪問的主機其本地磁盤是沒有存儲文件的 創建方法如下 :     準備兩臺機器,一臺當 client  另一臺當server    &nbsp…

    Linux干貨 2017-06-07
  • iptables

    Evernote Export   基于本機服務器的iptables: 創建、重命名、刪除自定義chain ~]# iptables -N testchain ~]# iptables -nL Chain INPUT (policy ACCEPT) target     prot opt source    …

    Linux干貨 2016-11-20
  • N25_第二周作業

      1、Linux上的文件管理命令都有哪些,其常用的使用方法及其相關示例演示。  cp命令:                                  &nbsp…

    Linux干貨 2016-12-13
  • linux系統啟動詳解

    主要內容: 系統啟動過程 init啟動過程 chkconfig的增,刪,查 Linux組成 Linux: kernel+rootfs  kernel: 進程管理、內存管理、網絡管理、驅動程序、文件系統、安全功能  rootfs:程序和glibc 庫:函數集合, function, 調用接口…

    Linux干貨 2016-09-08
欧美性久久久久