3rd work

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

[root@localhost ~]# w

11:50:45 up 24 min, ?3 users, ?load average: 0.04, 0.04, 0.10

USER ? ? TTY ? ? ?FROM ? ? ? ? ? ? LOGIN@ ? IDLE ? JCPU ? PCPU WHAT

root ? ? :0 ? ? ? :0 ? ? ? ? ? ? ? 11:27 ? ?xdm? ? 1:47 ? 0.33s gdm-session-worker [pam/gdm-password]

root ? ? pts/0 ? ?:0 ? ? ? ? ? ? ? 11:27 ? ?5.00s ?0.09s ?0.00s w

root ? ? pts/1 ? ?:0 ? ? ? ? ? ? ? 11:32 ? 53.00s ?0.06s ?0.00s less -s

[root@localhost ~]# w -h

root ? ? :0 ? ? ? :0 ? ? ? ? ? ? ? 11:27 ? ?xdm? ? 1:47 ? 0.33s gdm-session-worker [pam/gdm-password]

root ? ? pts/0 ? ?:0 ? ? ? ? ? ? ? 11:27 ? ?0.00s ?0.09s ?0.00s w -h

root ? ? pts/1 ? ?:0 ? ? ? ? ? ? ? 11:32 ? 56.00s ?0.06s ?0.00s less -s

[root@localhost ~]# w -h | cut -d” ” -f1

root

root

root

[root@localhost ~]# w -h | cut -d” ” -f1 ?| uniq

root

[root@localhost ~]#

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

[root@localhost ~]# w

11:59:01 up 33 min, ?4 users, ?load average: 0.02, 0.06, 0.09

USER ? ? TTY ? ? ?FROM ? ? ? ? ? ? LOGIN@ ? IDLE ? JCPU ? PCPU WHAT

root ? ? :0 ? ? ? :0 ? ? ? ? ? ? ? 11:27 ? ?xdm? ? 2:12 ? 0.34s gdm-session-worker [pam/gdm-password]

root ? ? pts/0 ? ?:0 ? ? ? ? ? ? ? 11:27 ? ?5.00s ?0.14s ?0.00s w

root ? ? pts/1 ? ?:0 ? ? ? ? ? ? ? 11:32 ? ?9:09 ? 0.06s ?0.00s less -s

root ? ? pts/2 ? ?:0 ? ? ? ? ? ? ? 11:57 ? ?1:25 ? 0.05s ?0.05s bash

[root@localhost ~]# w -h | sort -t” ” -k4 | tail -1

root ? ? pts/2 ? ?:0 ? ? ? ? ? ? ? 11:57 ? ?1:31 ? 0.05s ?0.05s bash

[root@localhost ~]#

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

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

4 /bin/bash

1 /bin/sync

1 /sbin/halt

53 /sbin/nologin

1 /sbin/shutdown

[root@localhost ~]#

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

~]# sort -t: -k3 -n ?/etc/passwd | tail -10 | tr ‘a-z’ ‘A-Z’ >/tmp/maxusers.txt

~]# cat /tmp/maxusers.txt

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

方法1:

~]# ifconfig | cut -d” ” -f10,13,16 | sort -n -u

方法2:由于ifconfig地址x.x.x.x中的x不可能大于255,也不會出現這種格式有大于255的數值,因此這是模糊匹配,如果有300.400.500.600,也會被匹配出來

~]# ifconfig | grep -o “\<[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}”

192.168.5.128

255.255.255.0

192.168.5.255

127.0.0.1

255.0.0.0

192.168.122.1

255.255.255.0

192.168.122.255

[root@localhost ~]#

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

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

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

[root@localhost ~]# ls /var/ | wc -w

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

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

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

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

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

新增用戶:useradd

useradd [options] LOGIN

useradd -D????//顯示創建用戶的默認設置

useradd -D [options]????//修改創建用戶的默認選項,修改的結果保存于/etc/default/useradd文件中,也可以通過修改此文件實現。

option:

-u:指定用戶UID;

-g:指定用戶基本組GID,此組需事先存在

-c:注釋信息

-G:指定用戶所屬附加組,多個組之間用逗號分隔

-d:指定用戶家目錄路徑,通過復制/etc/skel目錄并重命名實現,如果指定路徑存在,則不會初始化用戶環境配置。

-s:指定用戶的默認登陸shell,可用的shell列表/etc/shells

-r:創建系統用戶,

-M:不為用戶創建家目錄

-f:密碼過期后,賬戶被徹底禁用之前的天數

-D:顯示用戶創建時的默認參數設置。

修改用戶信息:

usermod [options] LOGIN

options:

-u:修改用戶的UID

-g:修改用戶基本組GID,組需事先存在

-G:修改用戶所屬附加組,會從原來的附加組中脫離,增加到新的附加組中

-a:只能和-G一起使用,用于追加新的附加組,原來的附加組和現在的附加組同時存在

-c:修改注釋信息

-s:修改用戶的shell

-d:修改用戶的家目錄,原家目錄中的文件不會被轉移至新的位置,

-m:只能和-d一起使用,轉移家目錄路徑時,將原來家目錄中的文件一起轉移至新的家目錄位置。

-l:修改用戶名

-L:鎖定用戶密碼,禁止用戶登陸,即在原來的密碼字符串之前添加!

-u:解鎖用戶的密碼。

刪除用戶:

userdel [options] LOGIN

-f:強制刪除,即使用戶已經登陸。

-r:刪除用戶時,一并刪除其家目錄。

新增組:

groupadd [options] group

options:

-r:創建系統組

-g:指定新建組的GID。

修改組:

groupmod [options] GROUP

options:

-g:修改組的GID

-n:修改組名

-p:修改組密碼

刪除組:

groupdel [options] GROUP

10.1、創建組distro,其GID為為2016;

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

[root@localhost home]# tail -1 /etc/group

distro:x:2016:

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

[root@localhost home]# useradd -u 1005 -g 2016 mandriva

[root@localhost home]# tail -1 /etc/passwd

mandriva:x:1005:2016::/home/mandriva:/bin/bash

[root@localhost home]#

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

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

[root@localhost home]# ls

123 ?linux ?mandriva ?user ?user1 ?zhang2

[root@localhost home]# tail -1 /etc/passwd

mageia:x:1100:1100::/home/linux:/bin/bash

[root@localhost home]#

10.4、給用戶mageia添加密碼,密碼為mageedu;

[root@localhost home]# 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.

[root@localhost home]#

10.5、刪除mandriva,但保留其家目錄

[root@localhost home]# userdel mandriva

[root@localhost home]# ls

123 ?linux ?mandriva ?user ?user1 ?zhang2

[root@localhost home]#

10.6、創建用戶slackware,其ID號為2002,基本組為distro,附加組peguin

[root@localhost home]# groupadd peguin

[root@localhost home]# tail -1 /etc/group

peguin:x:2017:

[root@localhost home]# useradd -u 2002 -g 2016 -G 2017 slackware

[root@localhost home]# tail -1 /etc/group

peguin:x:2017:slackware

[root@localhost home]#

10.7、修改slackware的默認shell為/bin/tcsh;

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

[root@localhost home]# tail -1 /etc/passwd

slackware:x:2002:2016::/home/slackware:/bin/tcsh

[root@localhost home]#

10.8、為用戶slackware新增附加組admins;

[root@localhost home]# usermod -aG admins slackware

[root@localhost home]# tail -5 /etc/group

user:x:1000:

distro:x:2016:

mageia:x:1100:

peguin:x:2017:slackware

admins:x:2018:slackware

[root@localhost home]#

本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/87670

(0)
N27_zhangweitaoN27_zhangweitao
上一篇 2017-10-08 15:18
下一篇 2017-10-09

相關推薦

  • 20160810作業

    1、編寫腳本/root/bin/systeminfo.sh,顯示當前主機系統信息,包括主機名,IPv4地址,操作系統版本,內核版本,CPU型號,內存大小,硬盤大小。           2、編寫腳本/root/bin/backup.sh,可實現每日將/etc/目錄備份到/root…

    Linux干貨 2016-08-12
  • 目錄,inode學習筆記

    目錄,inode學習筆記 1. 關于目錄,文件,數據塊 對于使用計算機的人而言,經常有一種 錯誤的認知:目錄(或者說,文件夾)里面存放著文件。實際上,目錄里面并不存放文件,以及文件數據。 實際上,目錄是一個特殊的文件,針對這個特殊的文件也存在一些特殊的規則,比如利用命令cp /dev/null <your directory>…

    Linux干貨 2017-04-01
  • 管道和用戶管理權限

           一周的時間又過去了,感覺過得太快了,但是過得很充實,這就夠啦!把在平時的學習中覺得重要有意義的地方記錄下來,希望可以對自己以后的學習有所幫助! 1.把/etc/issue轉化為大寫,并重定向到issue.out. 管道的作用很強大,|將正確的結果重定向給下一條命令;連接命令;一頁一頁地…

    2017-07-22
  • NoSQL理論基礎及安裝、基本操作

    30分鐘開始 分布式系統理論: CAP: 一致性 可用性 分區容錯性     MongoDB: 安裝 crud 索引 副本集 分片   NoSQL:非關系型、分布式、不提供ACID功能 技術特點: 1、簡單數據模型 2、元數據和應用數據分離(分不同服務器存儲) 3、弱一致性   優勢: 1、避免不必要的復雜性 2、高吞…

    2016-11-27
  • 馬哥教育網絡班21期+第四周博客作業

    1、復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限。 [root@C67-X64-A0 ~]# cp -a /etc/skel/ /home/tuser1 [root@C67-X64-A0 ~]# ls&nb…

    Linux干貨 2016-07-29
  • LINUX課堂筆記(第二周)

    2018.03.12 rpm httpd*** service httpd start ab 模仿用戶訪問 cat /var/log/httpd/access_log curl 訪問web服務 rev 字符顛倒顯示 sort ? -r 執行反方向(由上至下)整理 ? -R 隨機排序 ? -n 執行按數字大小整理 ? -f 選項忽略(fold)字符串中的字符大…

    Linux干貨 2018-03-17
欧美性久久久久