#1、列出當前系統上所有已經登錄的用戶的用戶名,注意:同一個用戶登錄多次,則只顯示一次即可。
[xujie@localhost ~]$ who | cut -d " " -f1 | sort -u
#2、取出最后登錄到當前系統的用戶的相關信息。
[root@localhost xujie]# last -x | head -1
#3、取出當前系統上被用戶當作其默認shell的最多的那個shell。
[root@localhost xujie]# cut /etc/passwd -d ':' -f7 | uniq -c | sort -n | tail -1
#4、將/etc/passwd中的第三個字段數值最大的后10個用戶的信息全部改為大寫后保存至/tmp/maxusers.txt文件中。
[xujie@localhost ~]$ sort -t ':' -k 3 -n /etc/passwd | tail -10 | tr [[:lower:]] [[:upper:]] > /tmp/maxusers.txt
#5、取出當前主機的IP地址,提示:對ifconfig命令的結果進行切分。
[root@localhost network-scripts]# ifconfig | grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'
#6、列出/etc目錄下所有以.conf結尾的文件的文件名,并將其名字轉換為大寫后保存至/tmp/etc.conf文件中。
[root@localhost mylinux]# ls -a /etc/ | grep -E *'.conf'$ | tr [a-z] [A-Z] > /tmp/etc.conf
#7、顯示/var目錄下一級子目錄或文件的總個數。
[root@localhost lib]# find /var -type f | wc -l
#8、取出/etc/group文件中第三個字段數值最小的10個組的名字。
[root@localhost lib]# sort -n -t ":" -k 3 /etc/group | head -10 | cut -d ":" -f 1
#9、將/etc/fstab和/etc/issue文件的內容合并為同一個內容后保存至/tmp/etc.test文件中。
[root@localhost tmp]# cat /etc/{fstab,issue} > /tmp/etc.test
#10、請總結描述用戶和組管理類命令的使用方法并完成以下練習:
# (1)、創建組distro,其GID為2016;
[root@localhost tmp]# groupadd -g 2016 distro
[root@localhost tmp]# cat /etc/group | grep distro
distro:x:2016:
# (2)、創建用戶mandriva, 其ID號為1005;基本組為distro;
[root@localhost tmp]# useradd -u 1005 -g 2016 mandriva
[root@localhost tmp]# cat /etc/passwd | grep mandriva
mandriva:x:1100:2016::/home/mandriva:/bin/bash
# (3)、創建用戶mageia,其ID號為1100,家目錄為/home/linux;
[root@localhost tmp]# useradd -u 1100 -d /home/linux mageia
[root@localhost tmp]# cat /etc/passwd | grep mageia
mageia:x:1100:1100::/home/linux:/bin/bas
# (4)、給用戶mageia添加密碼,密碼為mageedu;
[root@localhost tmp]# 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@localhost xujie]# userdel mandriva
[root@localhost xujie]# cd ..
[root@localhost home]# ls
arch asdf centos gentoo linux mandriva xujie
# (6)、創建用戶slackware,其ID號為2002,基本組為distro,附加組peguin;
[root@localhost home]# groupadd peguin
[root@localhost home]# useradd -u 2002 -g distro -G peguin slackware
[root@localhost home]# cat /etc/passwd | grep slackware
slackware:x:2002:2016::/home/slackware:/bin/bash
[root@localhost home]# id slackware
uid=2002(slackware) gid=2016(distro) groups=2016(distro),2017(peguin)
# (7)、修改slackware的默認shell為/bin/tcsh;
[root@localhost home]# usermod -s /bin/tcsh slackware
[root@localhost home]# cat /etc/passwd | grep slackware
slackware:x:2002:2016::/home/slackware:/bin/tcsh
[root@localhost home]#
# (8)、為用戶slackware新增附加組admins;
[root@localhost home]# usermod -G admins slackware
usermod: group 'admins' does not exist
[root@localhost home]# groupadd admins
[root@localhost home]# usermod -G admins slackware
[root@localhost home]# id slackware
uid=2002(slackware) gid=2016(distro) groups=2016(distro),2018(admins)
[root@localhost home]#
# (9)、為slackware添加密碼,且要求密碼最短使用期限為3天,最長為180天,警告為3天;
[root@localhost home]# passwd slackware
Changing password for user slackware.
New password:
BAD PASSWORD: The password fails the dictionary check – it is too simplistic/systematic
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost home]# passwd -n 3 -x 180 -w 3 slackware
Adjusting aging data for user slackware.
passwd: Success
[root@localhost home]# cat /etc/shadow | grep slackware
slackware:$6$gk2px/TP$bOxfKmZYQs0g15JyJ2elalp8lfQaAioXWb3F96sBUrfH0NQMitSu1H3COZ7dzIXltpuKt0.88TNuCWk9EIu7F.:17056:3:180:3:::
[root@localhost home]#
# (10)、添加用戶openstack,其ID號為3003, 基本組為clouds,附加組為peguin和nova;
[root@localhost home]# useradd -u 3003 -g clouds -G peguin,nova openstack
useradd: group 'clouds' does not exist
[root@localhost home]# groupadd clouds
[root@localhost home]# useradd -u 3003 -g clouds -G peguin,nova openstack
[root@localhost home]# groupadd nova
[root@localhost home]# useradd -u 3003 -g clouds -G peguin,nova openstack
[root@localhost home]# id openstack
uid=3003(openstack) gid=2019(clouds) groups=2019(clouds),2017(peguin),2020(nova)
[root@localhost home]#
# (11)、添加系統用戶mysql,要求其shell為/sbin/nologin;
[root@localhost home]# useradd -r mysql -s /sbin/nologin
useradd: group mysql exists – if you want to add this user to that group, use -g.
[root@localhost home]# id centos
uid=1001(centos) gid=1005(mysql) groups=1005(mysql)
[root@localhost home]# groupdel mysql
groupdel: cannot remove the primary group of user 'centos'
[root@localhost home]# userdel -r centos
userdel: group centos not removed because it is not the primary group of user centos.
[root@localhost home]# groupdel mysql
[root@localhost home]# useradd -r mysql -s /sbin/nologin
[root@localhost home]# id mysql
uid=996(mysql) gid=994(mysql) groups=994(mysql)
[root@localhost home]#
# (12)、使用echo命令,非交互式為openstack添加密碼。
[root@localhost xujie]# echo "1234" | passwd –stdin "openstack"
Changing password for user openstack.
passwd: all authentication tokens updated successfully.
[root@localhost ~]# su -l xujie
Last login: Mon Sep 12 07:23:37 EDT 2016 on pts/0
[xujie@localhost ~]$ su -l openstack
Password:
Last failed login: Mon Sep 12 07:24:02 EDT 2016 on pts/0
There were 5 failed login attempts since the last successful login.
[openstack@localhost ~]$
原創文章,作者:N22-南京-修,如若轉載,請注明出處:http://www.www58058.com/45780
ip地址匹配不正確,沒有好好聽咱們的分享課吧,那里面講過ip地址怎么匹配