前言
本文主要給大家介紹了關(guān)于linux系統(tǒng)用戶(hù)管理與grep正則表達(dá)式的相關(guān)內(nèi)容,分享出來(lái)供大家參考學(xué)習(xí),下面話(huà)不多說(shuō)了,來(lái)一起看看詳細(xì)的介紹吧。
linux系統(tǒng)用戶(hù)管理與grep正則表達(dá)式
1、復(fù)制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內(nèi)部文件的屬組和其它用戶(hù)均沒(méi)有任何訪(fǎng)問(wèn)權(quán)限。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
[root@suywien ~] # cp -rpv /etc/skel/ /home/tuser1/ ‘ /etc/skel/ ' -> ‘/home/tuser1/' ‘ /etc/skel/ .mozilla ' -> ‘/home/tuser1/.mozilla' ‘ /etc/skel/ .mozilla /extensions ' -> ‘/home/tuser1/.mozilla/extensions' ‘ /etc/skel/ .mozilla /plugins ' -> ‘/home/tuser1/.mozilla/plugins' ‘ /etc/skel/ .bash_logout ' -> ‘/home/tuser1/.bash_logout' ‘ /etc/skel/ .bash_profile ' -> ‘/home/tuser1/.bash_profile' ‘ /etc/skel/ .bashrc ' -> ‘/home/tuser1/.bashrc' [root@suywien ~] # useradd tuser -d /home/tuser1/ useradd : warning: the home directory already exists. Not copying any file from skel directory into it. [root@suywien ~] # chmod -R go-rwx /home/tuser1/ [root@suywien ~] # ll -d /home/tuser1/ drwx------ 3 root root 74 Feb 12 03:04 /home/tuser1/ |
2、編輯/etc/group文件,添加組hadoop。
1
2
3
|
[root@suywien ~] # vim /etc/group [root@suywien ~] # tail -1 /etc/group hadoop:x:1029 |
3、手動(dòng)編輯/etc/passwd文件新增一行,添加用戶(hù)hadoop,其基本組ID為hadoop組的id號(hào);其家目錄為/home/hadoop。
1
2
3
|
[root@suywien ~] # vim /etc/passwd [root@suywien ~] # tail -1 /etc/passwd hadoop:x:1029:1029:: /home/hodoop/ : /bin/bash |
4、復(fù)制/etc/skel目錄為/home/hadoop,要求修改hadoop目錄的屬組和其它用戶(hù)沒(méi)有任何訪(fǎng)問(wèn)權(quán)限。
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@suywien ~] # cp -fpv /etc/skel/ /home/hadoop cp : omitting directory ‘ /etc/skel/ ' [root@suywien ~] # cp -fpvR /etc/skel/ /home/hadoop ‘ /etc/skel/ ' -> ‘/home/hadoop' ‘ /etc/skel/ .mozilla ' -> ‘/home/hadoop/.mozilla' ‘ /etc/skel/ .mozilla /extensions ' -> ‘/home/hadoop/.mozilla/extensions' ‘ /etc/skel/ .mozilla /plugins ' -> ‘/home/hadoop/.mozilla/plugins' ‘ /etc/skel/ .bash_logout ' -> ‘/home/hadoop/.bash_logout' ‘ /etc/skel/ .bash_profile ' -> ‘/home/hadoop/.bash_profile' ‘ /etc/skel/ .bashrc ' -> ‘/home/hadoop/.bashrc' [root@suywien ~] # chmod go-rwx /home/hadoop/ [root@suywien ~] # ls -ld /home/hadoop/ drwx------ 3 root root 74 Feb 12 03:04 /home/hadoop/ |
5、修改/home/hadoop目錄及其內(nèi)部所有文件的屬主為hadoop,屬組為hadoop。
1
2
3
4
5
6
7
8
9
|
[root@suywien ~] # chown -R hadoop:hadoop /home/hadoop/ [root@suywien ~] # ll -al /home/hadoop/ total 16 drwx------ 3 hadoop hadoop 74 Feb 12 03:04 . drwxr-xr-x. 10 root root 4096 Mar 25 10:14 .. -rw-r--r-- 1 hadoop hadoop 18 Nov 20 2015 .bash_logout -rw-r--r-- 1 hadoop hadoop 193 Nov 20 2015 .bash_profile -rw-r--r-- 1 hadoop hadoop 231 Nov 20 2015 .bashrc drwxr-xr-x 4 hadoop hadoop 37 Feb 12 03:03 .mozilla |
6、顯示/proc/meminfo文件中以大寫(xiě)或小寫(xiě)S開(kāi)頭的行;用兩種方式;
1、
1
2
3
4
5
6
7
8
|
[root@suywien ~] # grep ^[S,s] /proc/meminfo SwapCached: 0 kB SwapTotal: 2097148 kB SwapFree: 2097148 kB Shmem: 9100 kB Slab: 89476 kB SReclaimable: 53176 kB SUnreclaim: 36300 kB |
2、
1
2
3
4
5
|
[root@suywien ~] # grep -i "^s" /proc/meminfo SwapCached: 0 kB SwapTotal: 2097148 kB SwapFree: 2097148 kB Shmem: 9100 kB |
7、顯示/etc/passwd文件中其默認(rèn)shell為非/sbin/nologin的用戶(hù);
1
2
3
4
5
6
7
|
[root@suywien ~] # grep \/sbin\/nologin$ /etc/passwd bin:x:1:1:bin: /bin : /sbin/nologin daemon:x:2:2:daemon: /sbin : /sbin/nologin adm:x:3:4:adm: /var/adm : /sbin/nologin lp:x:4:7:lp: /var/spool/lpd : /sbin/nologin mail:x:8:12:mail: /var/spool/mail : /sbin/nologin ...... |
8、顯示/etc/passwd文件中其默認(rèn)shell為/bin/bash的用戶(hù);
1
2
3
4
5
6
7
|
[root@suywien ~] # grep \/bin\/bash /etc/passwd root:x:0:0:root: /root : /bin/bash roo:x:1000:1000:root: /home/roo : /bin/bash gentoo:x:4001:4001:: /home/gentoo : /bin/bash mageia:x:1100:1100:: /home/linux : /bin/bash tuser:x:4003:4003:: /home/tuser1/ : /bin/bash hadoop:x:1029:1029:: /home/hodoop/ : /bin/bash |
9、找出/etc/passwd文件中的一位數(shù)或兩位數(shù);
1
2
3
4
5
6
|
[root@suywien ~] # grep "\<[0-9]\{2,3\}\>" /etc/passwd mail:x:8:12:mail: /var/spool/mail : /sbin/nologin operator:x:11:0:operator: /root : /sbin/nologin games:x:12:100:games: /usr/games : /sbin/nologin ftp :x:14:50:FTP User: /var/ftp : /sbin/nologin ...... |
10、顯示/boot/grub/grub.conf中以至少一個(gè)空白字符開(kāi)頭的行;
1
2
3
4
5
6
7
|
[root@suywien ~] # grep "^[[:space:]]\+" /boot/grub2/grub.cfg load_env set default= "${next_entry}" set next_entry= save_env next_entry set boot_once= true ...... |
11、顯示/etc/rc.d/rc.sysinit文件中以#開(kāi)頭,后面跟至少一個(gè)空白字符,而后又有至少一個(gè)非空白字符的行;
1
2
3
4
5
6
7
8
|
[root@suywien ~] # grep "^#[[:space:]]\+[^[:space:]]\+" /etc/rc.d/rc.local # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES # It is highly advisable to create own systemd services or udev rules # to run scripts during boot instead of using this file. # In contrast to previous versions due to parallel execution during boot # this script will NOT be run after all other services. # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure # that this script will be executed during boot. |
12、打出netstat -tan命令執(zhí)行結(jié)果中以‘LISTEN',后或跟空白字符結(jié)尾的行;
1
2
3
4
5
6
7
8
|
[root@suywien ~] # netstat -tan | grep "LISTEN[[:space:]]*$" tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp6 0 0 :::22 :::* LISTEN tcp6 0 0 ::1:631 :::* LISTEN tcp6 0 0 ::1:25 :::* LISTEN |
13、添加用戶(hù)bash, testbash, basher, nologin (此一個(gè)用戶(hù)的shell為/sbin/nologin),而后找出當(dāng)前系統(tǒng)上其用戶(hù)名和默認(rèn)shell相同的用戶(hù)的信息;
1
2
3
4
5
6
7
8
9
10
|
[root@suywien ~] # useradd bash [root@suywien ~] # useradd basher [root@suywien ~] # useradd -s /sbin/nologin nologin [root@suywien ~] # grep -E "^([^:]+\>).*\1$" /etc/passwd sync :x:5:0: sync : /sbin : /bin/sync shutdown :x:6:0: shutdown : /sbin : /sbin/shutdown halt:x:7:0:halt: /sbin : /sbin/halt bash :x:4004:4004:: /home/bash : /bin/bash nologin:x:4006:4006:: /home/nologin : /sbin/nologin |
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)服務(wù)器之家的支持。
原文鏈接:http://www.178linux.com/92876