馬哥教育網絡班21期第3周課程練習

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

who | cut -d" " -f 1 |sort |uniq

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

last | head -1

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

cat /etc/passwd | cut -d":" -f 7 | sort | uniq -c | sort -rn | head -1

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

cat /etc/passwd | sort -t":" -k 3 -rn | cut -d":" -f 1 | tr "a-z" "A-Z" | head > /tmp/maxusers.txt

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

ifconfig | grep '\<inet\>' | sed 's/^[ \t]*//g' |cut -d" " -f 2

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

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

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

# ls -al /var | wc -l

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

# sort -n -t":" -k 3 /etc/group | head

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

# cat /etc/{fstab,issue} > /tmp/etc.test

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

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

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

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

[root@centos7study ~]# useradd -u 1005 -g 2016 mandriva

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

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

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

[root@centos7study ~]# 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.

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

[root@centos7study ~]# userdel mandriva

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

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

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

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

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

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

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

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

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

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

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

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

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

[root@centos7study ~]# echo "magedu" | passwd --stdin openstack
Changing password for user openstack.
passwd: all authentication tokens updated successfully.

原創文章,作者:N21-孟然,如若轉載,請注明出處:http://www.www58058.com/25354

(0)
N21-孟然N21-孟然
上一篇 2016-07-29
下一篇 2016-07-29

相關推薦

  • keepalived高可用haproxy配合varnish實現wordpress的動靜分離

    haproxy和nginx都可以作為七層和四層反代服務器對外提供服務,此文通過haproxy和keealived配置varnish搭建wordpress的動靜分離站點 一、實驗環境 五臺虛擬機: haproxy-1:搭建haproxy和keepalived服務,ip地址:192.168.11.176 haproxy-2:搭建haproxy和keepalive…

    2017-07-03
  • 邏輯卷實例

    1、創建一個至少有兩個PV組成的大小為20G的名為testvg的VG;要求PE大小為16MB, 而后在卷組中創建大小為5G的邏輯卷testlv;掛載至/users目錄 2、新建用戶archlinux,要求其家目錄為/users/archlinux,而后su切換至archlinux用戶,復制/etc/pam.d目錄至自己的家目錄 3、擴展testlv至7G,要…

    Linux干貨 2016-09-01
  • N28第五周

    1、簡述rpm與yum命令的常見選項,并舉例
    2、自建yum倉庫,分別為網絡源和本地源
    3、簡述at和crontab命令,制定 每周三凌晨三、五點10分執行某個腳本,輸出當前時間,時間格式為 2017-12-28 10:00:00
    4、簡述sed常用操作命令,并舉例

    Linux干貨 2018-01-03
  • 習題

    1.當用戶xiaoming對/testdir 目錄無執行權限時,意味著無法做哪些操作? 2.當用戶xiaoqiang對/testdir 目錄無讀權限時,意味著無法做哪些操作? 3.當用戶wangcai 對/testdir 目錄無寫權限時,該目錄下的只讀文件file1是否可修改和刪除? 4.復制/etc/fstab文件到/var/tmp下,設置文件所有者為wa…

    Linux干貨 2016-08-04
  • 馬哥教育網絡班21期第4周課程練習

    1、復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限。 # cp -r /etc/skel/ /home/tuser1 # chmod -R go= /home/tuser1/ 2、編輯/etc/gr…

    Linux干貨 2016-07-27
  • Linux的安全控制訪問模塊之SElinux

    SElinux   1、Selinux介紹:Linux的一個強制訪問控制安全模塊,2000年以GNU GPL發布,Linux內核2.6版本集成在內核中。 DAC:自由訪問控制,進程是無束縛的。 MAC:強制訪問控制,策略的規則決定控制的嚴格程度(策略被用來定義被限制的進程能夠使用那些資源[文件和端口]);進程的可以被限制的;默認情況下,沒有允許的行…

    Linux干貨 2016-09-19

評論列表(1條)

  • 馬哥教育
    馬哥教育 2016-07-29 16:01

    寫的很好,排版也很棒,加油

欧美性久久久久