linux系统用户管理与grep正则表达式的示例分析
这篇文章主要介绍了linux系统用户管理与grep正则表达式的示例分析,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
linux系统用户管理与grep正则表达式
1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。
[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~]#useraddtuser-d/home/tuser1/useradd:warning:thehomedirectoryalreadyexists.Notcopyinganyfilefromskeldirectoryintoit.[root@suywien~]#chmod-Rgo-rwx/home/tuser1/[root@suywien~]#ll-d/home/tuser1/drwx------3rootroot74Feb1203:04/home/tuser1/
2、编辑/etc/group文件,添加组hadoop。
[root@suywien~]#vim/etc/group[root@suywien~]#tail-1/etc/grouphadoop:x:1029
3、手动编辑/etc/passwd文件新增一行,添加用户hadoop,其基本组ID为hadoop组的id号;其家目录为/home/hadoop。
[root@suywien~]#vim/etc/passwd[root@suywien~]#tail-1/etc/passwdhadoop:x:1029:1029::/home/hodoop/:/bin/bash
4、复制/etc/skel目录为/home/hadoop,要求修改hadoop目录的属组和其它用户没有任何访问权限。
[root@suywien~]#cp-fpv/etc/skel//home/hadoopcp:omittingdirectory‘/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~]#chmodgo-rwx/home/hadoop/[root@suywien~]#ls-ld/home/hadoop/drwx------3rootroot74Feb1203:04/home/hadoop/
5、修改/home/hadoop目录及其内部所有文件的属主为hadoop,属组为hadoop。
[root@suywien~]#chown-Rhadoop:hadoop/home/hadoop/[root@suywien~]#ll-al/home/hadoop/total16drwx------3hadoophadoop74Feb1203:04.drwxr-xr-x.10rootroot4096Mar2510:14..-rw-r--r--1hadoophadoop18Nov202015.bash_logout-rw-r--r--1hadoophadoop193Nov202015.bash_profile-rw-r--r--1hadoophadoop231Nov202015.bashrcdrwxr-xr-x4hadoophadoop37Feb1203:03.mozilla
6、显示/proc/meminfo文件中以大写或小写S开头的行;用两种方式;
[root@suywien~]#grep^[S,s]/proc/meminfoSwapCached:0kBSwapTotal:2097148kBSwapFree:2097148kBShmem:9100kBSlab:89476kBSReclaimable:53176kBSUnreclaim:36300kB
[root@suywien~]#grep-i"^s"/proc/meminfoSwapCached:0kBSwapTotal:2097148kBSwapFree:2097148kBShmem:9100kB
7、显示/etc/passwd文件中其默认shell为非/sbin/nologin的用户;
[root@suywien~]#grep\/sbin\/nologin$/etc/passwdbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinmail:x:8:12:mail:/var/spool/mail:/sbin/nologin......
8、显示/etc/passwd文件中其默认shell为/bin/bash的用户;
[root@suywien~]#grep\/bin\/bash/etc/passwdroot:x:0:0:root:/root:/bin/bashroo:x:1000:1000:root:/home/roo:/bin/bashgentoo:x:4001:4001::/home/gentoo:/bin/bashmageia:x:1100:1100::/home/linux:/bin/bashtuser:x:4003:4003::/home/tuser1/:/bin/bashhadoop:x:1029:1029::/home/hodoop/:/bin/bash
9、找出/etc/passwd文件中的一位数或两位数;
[root@suywien~]#grep"\<[0-9]\{2,3\}\>"/etc/passwdmail:x:8:12:mail:/var/spool/mail:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologingames:x:12:100:games:/usr/games:/sbin/nologinftp:x:14:50:FTPUser:/var/ftp:/sbin/nologin......
10、显示/boot/grub/grub.conf中以至少一个空白字符开头的行;
[root@suywien~]#grep"^[[:space:]]\+"/boot/grub2/grub.cfgload_envsetdefault="${next_entry}"setnext_entry=save_envnext_entrysetboot_once=true......
11、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行;
[root@suywien~]#grep"^#[[:space:]]\+[^[:space:]]\+"/etc/rc.d/rc.local#THISFILEISADDEDFORCOMPATIBILITYPURPOSES#Itishighlyadvisabletocreateownsystemdservicesorudevrules#torunscriptsduringbootinsteadofusingthisfile.#Incontrasttopreviousversionsduetoparallelexecutionduringboot#thisscriptwillNOTberunafterallotherservices.#Pleasenotethatyoumustrun'chmod+x/etc/rc.d/rc.local'toensure#thatthisscriptwillbeexecutedduringboot.
12、打出netstat -tan命令执行结果中以‘LISTEN',后或跟空白字符结尾的行;
[root@suywien~]#netstat-tan|grep"LISTEN[[:space:]]*$"tcp00192.168.122.1:530.0.0.0:*LISTENtcp000.0.0.0:220.0.0.0:*LISTENtcp00127.0.0.1:6310.0.0.0:*LISTENtcp00127.0.0.1:250.0.0.0:*LISTENtcp600:::22:::*LISTENtcp600::1:631:::*LISTENtcp600::1:25:::*LISTEN
13、添加用户bash, testbash, basher, nologin (此一个用户的shell为/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户的信息;
[root@suywien~]#useraddbash[root@suywien~]#useraddbasher[root@suywien~]#useradd-s/sbin/nologinnologin[root@suywien~]#grep-E"^([^:]+\>).*\1$"/etc/passwdsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltbash:x:4004:4004::/home/bash:/bin/bashnologin:x:4006:4006::/home/nologin:/sbin/nologin
感谢你能够认真阅读完这篇文章,希望小编分享的“linux系统用户管理与grep正则表达式的示例分析”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。