馬哥教育第21期-第三周博客作業

1、列出當前系統上所有已經登錄的用戶的用戶名,注意:同一個用戶登錄多次,則只顯示一次即可。
[root@localhost ~]# who | cut -d' ' -f1 | uniq
lqy
root

2、取出最后登錄到當前系統的用戶的相關信息。
  [root@localhost scripts]# who |tail -1

3、取出當前系統上被用戶當作其默認shell的最多的那個shell。
cut -d':' -f7 /etc/passwd |sort|uniq -c | sort -nr | head -1

4、將/etc/passwd中的第三個字段數值最大的后10個用戶的信息全部改為大寫后保存至/tmp/maxusers.txt文件中。
 sort  -nr -t: -k3 /etc/passwd | head -n 10 | tr 'a-z' 'A-Z' > /tmp/maxusers.txt

5、取出當前主機的IP地址,提示:對ifconfig命令的結果進行切分。
ifconfig | head -2 | tail -1 | grep -o "[^[:space:]].*" | cut -d' ' -f2

6、列出/etc目錄下所有以.conf結尾的文件的文件名,并將其名字轉換為大寫后保存至/tmp/etc.conf文件中。
ls /etc/*.conf | tr 'a-z' 'A-Z' > /tmp/etc.conf

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

8、取出/etc/group文件中第三個字段數值最小的10個組的名字。
cat /etc/group | sort -t: -k3  -n | 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;
      [root@localhost scripts]# groupadd -g 2016 distro
   (2)、創建用戶mandriva, 其ID號為1005;基本組為distro;
         [root@localhost scripts]# useradd -u 1005 -g distro mandriva
         [root@localhost scripts]# id mandriva
         uid=1005(mandriva) gid=2016(distro) groups=2016(distro)

   (3)、創建用戶mageia,其ID號為1100,家目錄為/home/linux;
      [root@localhost scripts]# useradd mageia -u 1100 -d /home/linux
      [root@localhost scripts]# tail -1 /etc/passwd
      mageia:x:1100:1100::/home/linux:/bin/bash

   (4)、給用戶mageia添加密碼,密碼為mageedu;
      [root@localhost scripts]# passwd mageia
   (5)、刪除mandriva,但保留其家目錄;
      [root@localhost scripts]# userdel mandriva
   (6)、創建用戶slackware,其ID號為2002,基本組為distro,附加組peguin;
      [root@localhost scripts]# groupadd peguin
      [root@localhost scripts]# useradd slackware -u 2002 -g distro -G peguin
      [root@localhost scripts]# id slackware
      uid=2002(slackware) gid=2016(distro) groups=2016(distro),2017(peguin)

   (7)、修改slackware的默認shell為/bin/tcsh;
      [root@localhost scripts]# usermod -s /bin/tcsh slackware
      [root@localhost scripts]# cat /etc/passwd | grep "slackware"
      slackware:x:2002:2016::/home/slackware:/bin/tcsh
      [root@localhost scripts]# chsh -s /bin/tcsh slackware

   (8)、為用戶slackware新增附加組admins;
      [root@localhost scripts]# usermod -G admins slackware
      [root@localhost scripts]# id slackware
      uid=2002(slackware) gid=2016(distro) groups=2016(distro),2020(admins)

   (9)、為slackware添加密碼,且要求密碼最短使用期限為3天,最長為180天,警告為3天;
      [root@localhost scripts]# passwd slackware -n 3 -x 108 -w 3
   (10)、添加用戶openstack,其ID號為3003, 基本組為clouds,附加組為peguin和nova;
      [root@localhost scripts]# useradd openstack -u 3003 -g clouds -G peguin,nova
      [root@localhost scripts]# id openstack
      uid=3003(openstack) gid=2018(clouds) groups=2018(clouds),2017(peguin),2019(nova)

   (11)、添加系統用戶mysql,要求其shell為/sbin/nologin;
      [root@localhost scripts]# useradd -s /bin/nologin mysql
   (12)、使用echo命令,非交互式為openstack添加密碼。
      [root@localhost scripts]# echo "passwd" | passwd –stdin openstack

原創文章,作者:21期-揚州-藍,如若轉載,請注明出處:http://www.www58058.com/24253

(0)
21期-揚州-藍21期-揚州-藍
上一篇 2016-07-16 22:28
下一篇 2016-07-16 22:28

相關推薦

  • linux用戶管理

    linux用戶:       linux用戶大體分為兩種:一是:管理員用戶;二是普通用戶,普通用戶又可以分為系統用戶和登錄用戶。因為linux是一個多用戶多任務的系統,所以每一個要使用系統資源的用戶,都要向管理員申請一個賬號,使用這個賬號登錄到系統。每個用戶都擁有一個自己的名字和密碼,以登錄到用戶。 每個用戶都有唯一的用戶標識(…

    Linux干貨 2016-08-04
  • CentOS系統啟動

    Linux組成 Linux: kernel+rootfs kernel:  進程管理、內存管理、網絡管理、驅動程序、文件系統、安全功能 rootfs: 程序和glibc 庫:函數集合, function,  調用接口(頭文件負責描述) 過程調用:procedure ,無返回值 函數調用:function 程序:二進制執行文件 內核設計流派…

    2017-05-15
  • 一次簡單的內核編譯(二)

      前言:     此次編譯是繼一次簡單的內核編譯(一)進行操作編譯的,請先查看第一篇再來看此片文章 一、使用busybox代替自己制作的init腳本,實現內核啟動;  1、在這里我們使用靜態編譯busybox,所以需要先安裝glibc-static依賴包,如果不安裝會報錯     2、解…

    Linux干貨 2015-06-01
  • linux bash環境變量簡單總結

    一.環境變量簡介Linux是一個多用戶的操作系統。每個用戶登錄系統后,都會有一個專用的運行環境。通常每個用戶默認的環境都 是相同的,這個默認環境實際上就是一組環境變量的定義。 環境變量是全局的,設置好的環境變量可以被所有當前用戶所運行的程序所使用。 用戶可以對自己的運行環境進行定制,其方法就是修改相應的系統環境變量。 …

    Linux干貨 2015-09-14
  • 說明Linux系統上命令的使用格式;詳細介紹ifconfig、echo、tty、startx、export、pwd、history、shutdown、poweroff、reboot、hwclock、date命令的使用,并配合相應的示例來闡述。

    #COMMAND:一個可執行的二進制程序文件。 #OPTIONS:指定命令運行的特性,通常由兩種表現形式:短選項-d,長選項–help。如果同一命令在運行時使用多個短選項,可將多個短選項合并,如:-l -d -> -ld。 #ARGUEMENTS:命令的作用對象;不同的命令的作用對象不同,可以是文件,目錄,硬件設備等等。 #ifconfig…

    Linux筆記 2018-05-13
  • iptables

    一、前言 什么是iptables?當我們啟動iptables時,使用service命令可以啟動iptables。但是并非使用service啟動的iptables就能說明其是一個服務。Iptables是一個便以我們寫規則的工具,真正起作用的是內核中的netfilter一個框架。Netfilter內置了5個hook函數,當一個數據包交由此機器時,經過這5個hoo…

    Linux干貨 2015-10-27

評論列表(1條)

  • 馬哥教育
    馬哥教育 2016-07-17 20:13

    寫的很好,排版還可以在改進一下,加油

欧美性久久久久