Third Week work content:
1. List the user name of all logged-in users on the current system, note: The same user logged in multiple times, only once.
[email protected] ~]# who | Cut-d '-f1 | Sort-u CentOS Liu Root
2. Remove the information about the user who last logged in to the current system.
The first way: [[email protected] ~]# Last | Head-n1 Liu Tty8:2 Sun 10:26 still logged in the second way: [Email Protec Ted] ~]# who | Tail-n1 Liu Tty8 2016-08-21 10:26 (: 2)
3. Remove the shell that is the user's default shell on the current system.
[Email protected] ljohn]# cut-d:-f7/etc/passwd | uniq-c | Sort-n | Tail-n1 25/sbin/nologin
NOTE:/ETC/PASSWD Name:password:UID:GID:GECOS:directory:shell
4, the third field in the/etc/passwd the value of the largest 10 users of the information is changed to uppercase and saved to the/tmp/maxusers.txt file.
[[email protected] ljohn]# sort -t: -k3 -n /etc/passwd | tail -10 | tr ' A-Z ' ' A-Z ' > /tmp/maxusers.txt [[ Email protected] ljohn]# cat /tmp/maxusers.txt rtkit:x : 499:497:realtimekit:/proc:/sbin/nologin liu:x:500:500:liujian:/home/liu:/bin/bash bash:x:501:501::/home/bash:/bin/bash basher:x:502:502::/home/ basher:/bin/bash testbash:x:503:503::/home/testbash:/bin/bash Nologin:x:504:504::/home/nologin:/sbin/nologin user1:x:505:505::/home/user1:/bin/bash centos:x:506:506::/home/centos:/bin/bash useradd1:x:507:507::/ home/useradd1:/bin/bash nfsnobody:x:65534:65534:anonymous nfs user:/var/lib/ Nfs:/sbin/nologin
5. Remove the IP address of the current host, and tip: Slice the results of the ifconfig command.
[[email protected] ljohn]# ifconfig eth1 eth1 Link encap:Ethernet HWaddr 00:0C:29:45:CC:5E inet addr:192.168.188.21 Bcast:192.168.188.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe45:cc5e/64 Scope:Link up broadcast running MULTICAST MTU:1500 Metric:1 rx packets:5871 errors:0 dropped:0 overruns:0 frame:0 TX packets:2355 Errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:486015 (474.6 kib) TX bytes:259218 (253.1 KiB) interrupt:19 base address:0x2000 [[email protected] ljohn]# ifconfig eth1 | head - n2 | tail -n1 | cut -d: -f2 | cut -d ' ' -f1 192.168.188.21
6. List the file names of all files ending with. conf in/etc directory and convert their names to uppercase and save them to the/tmp/etc.conf file.
[Email protected] ljohn]# ls/etc/*.conf | Tr ' A-Z ' A-Z ' >/tmp/etc.test [[email protected] ljohn]# Cat/tmp/etc.test/etc/asound. Conf/etc/autofs_ldap_auth. Conf/etc/cas. CONF/ETC/DNSMASQ. Conf/etc/dracut. Conf/etc/fprintd. Conf/etc/gai. Conf/etc/grub. Conf/etc/gssapi_mech. CONF. . .
7. Displays the total number of sub-directories or files in the/var directory.
[Email protected] ljohn]# Ls/var | Wc-l 21
8. Remove the names of the 10 groups with the smallest number of the third field in the/etc/group file.
[Email protected] ljohn]# sort-t:-k3-n/etc/group | head-10 | cut-d:-f1 root bin daemon sys ADM TTY disk LP MEM Kmem
9, the contents of the/etc/fstab and/etc/issue files are merged into the same content and saved to the/tmp/etc.test file.
[[email protected] ljohn]# cat /etc/fstab /etc/issue > /tmp/etc.test [[email protected] ljohn]# cat /tmp/ etc.test # # /etc/fstab # Created by anaconda on Thu Feb 12 05:17:12 2015 # # accessible filesystems, by reference, are maintained under '/dev/disk ' # see man pages fstab ( 5), findfs (8), mount (8) and/or blkid (8) for more info # UUID=3fcabd0f-e9fb-4618-918d-c9e004fe6a59 / ext4 defaults 1 1 uuid= 234cc62b-7746-477d-ad58-8fb2448b9788 /boot ext3 defaults 1 2 UUID=b2c5da64-87b4-44c0-8864-f4a006b824fc swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc / proc proc defaults 0 0 centos release 6.5 (Final) kernel \r on an \m
10. Summarize the methods used to describe the user and group management commands and complete the following exercises:
(1), create group distro, its GID is 2016;
[Email protected] ljohn]# groupadd-g distro [[email protected] ljohn]# tail-1/etc/group distro:x:2 016:
(2), create user Mandriva, whose ID number is 1005; basic group is distro;
[Email protected] ljohn]# useradd-u 1005-g mandirva [[email protected] ljohn]# ID Mandirva uid=1005 ( Mandirva) gid=2016 (distro) group =2016 (distro)
(3), create user Mageia, whose ID number is 1100, home directory is/home/linux;
[Email protected] ljohn]# useradd-u 1100-d/home/linux mageia [[email protected] ljohn]# ID Mageia uid=11 XX (Mageia) gid=1100 (Mageia) group =1100 (Mageia) [[email protected] ljohn]# tail-1/etc/passwd mageia:x:1100:1100 ::/home/linux:/bin/bash
(4), to the user mageia add password, password for mageedu;
[Email protected] ljohn]# echo "mageedu" | passwd--stdin Mageia Change the password for the user Mageia. PASSWD: All the authentication tokens have been successfully updated.
(5), delete Mandriva, but retain their home directory;
[Email protected] ljohn]# Userdel mandirva [[email protected] ljohn]# Ls/home/bash basher CentOS Linu X Liu Mandirva nologin testbash user1 useradd1 [[email protected] ljohn]# ID Mandirva id:mandirva: No such use Households
(6), create user Slackware, its ID number is 2002, the basic group is distro, additional group Peguin;
[Email protected] ljohn]# groupadd Peguin [[email protected] ljohn]# useradd-u 2002-g distro-g Peguin Slackware [[email protected] ljohn]# tail-1/etc/passwd slackware:x:2002:2016::/home/slackware:/bin/bash [[em AIL protected] ljohn]# ID slackware uid=2002 (slackware) gid=2016 (distro) group =2016 (distro) (Peguin)
(7), modify the Slackware default shell for/BIN/TCSH;
[Email protected] ljohn]# usermod-s/bin/tcsh slackware [[email protected] ljohn]# TAIL-1/etc/passwd s Lackware:x:2002:2016::/home/slackware:/bin/tcsh
(8), add additional Group admins for user Slackware;
[Email protected] ljohn]# sort-t:-k3-n/etc/group | head-10 | cut-d:-f1 root bin daemon sys ADM TTY disk LP MEM Kmem
(9), add password for Slackware, and require the minimum password age of 3 days, the maximum is 180 days, warning for 3 days;
[[email protected] ljohn]# passwd-n 3-x 180-w 3 slackware Adjust user password aging data slackware. PASSWD: Operation successful [[email protected] ljohn]# tail-1/etc/shadow slackware:!! : 17034:3:180:3:::
(10), add user OpenStack, whose ID number is 3003, the basic group is clouds, the additional group is Peguin and Nova;
[Email protected] ljohn]# groupadd clouds [[email protected] ljohn]# groupadd Nova [[email protected] Ljo hn]# useradd-u 3003-g clouds-g Peguin,nova openstack [[email protected] ljohn]# ID openstack uid=3003 (o Penstack) gid=2019 (clouds) group =2019 (Clouds), Peguin (Nova)
(11), add the system user MySQL, request its shell for/sbin/nologin;
[[email protected] ljohn]# useradd-s/sbin/nologin MySQL [[email protected] ljohn]# tail-1/etc/passwd Mys Ql:x:3004:3004::/home/mysql:/sbin/nologin
(12), use the echo command, non-interactive add a password for OpenStack.
[Email protected] ljohn]# echo "OpenStack" | passwd--stdin OpenStack Changes the password for user OpenStack. PASSWD: All the authentication tokens have been successfully updated. [Email protected] ljohn]#
This article is from the "Ljohn" blog, make sure to keep this source http://ljohn.blog.51cto.com/11932290/1840868
Marco 2016 new Linux+python high-end operation Viban-linux user creation and rights management