Linux third week

Source: Internet
Author: User
Tags echo command stdin

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 | Uniqrootsihua

2. Remove the information about the user who last logged in to the current system.

[[Email protected] ~]$ W | Tail-1 | awk ' {print '} ' | iduid=500 (Sihua) gid=500 (Sihua) groups=500 (Sihua)

3. Remove the shell that is the user's default shell on the current system.

[Email protected] ~]$ CAT/ETC/PASSWD | Cut-d:-f7 | Sort | uniq-c | Sort-t '-k1-n | tail-1| awk ' {print $} '/sbin/nologin

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] ~]$ sort-t:-k3-n-r/etc/passwd | head-10 | Tr ' A-Z ' A-Z ' | Tee/tmp/maxuser.txtnfsnobody:x:4294967294:4294967294:anonymous NFS user:/var/lib/nfs:/sbin/nologinsihua:x : 500:500::/home/sihua:/bin/bashavahi-autoipd:x:100:101:avahi-autoipd:/var/lib/avahi-autoipd:/sbin/ Nologinnobody:x:99:99:nobody:/:/sbin/nologinhsqldb:x:96:96::/var/lib/hsqldb:/sbin/nologindbus:x:81:81:system MESSAGE bus:/:/sbin/nologinpcap:x:77:77::/var/arpwatch:/sbin/nologinsshd:x:74:74:privilege-separated SSH:/VAR/ Empty/sshd:/sbin/nologinavahi:x:70:70:avahi daemon:/:/sbin/nologinvcsa:x:69:69:virtual CONSOLE MEMORY OWNER:/DEV:/ Sbin/nologin

5, take out the IP address of the current host, hint: The result of ifconfig command is sliced.

centos6.x and previous [[email protected] ~]# Ifconfig | grep ' inet\b ' | awk ' {print $} ' | Cut-d:-f2192.168.1.67127.0.0.1centos7.x[[email protected] ~]# ifconfig | grep ' inet\b ' | awk ' {print $} ' 172.17.0.1192.168.1.63127.0.0.1192.168.122.1

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] ~]# ls /etc/*.conf | tr   ' A-Z '   ' A-Z '  | tee  /tmp/etc.conf/etc/autofs_ldap_auth. Conf/etc/capi. Conf/etc/cdrecord. Conf/etc/conman. CONF/ETC/DHCP6C. CONF/ETC/DNSMASQ. Conf/etc/esd. Conf/etc/gpm-root. Conf/etc/grub. Conf/etc/gssapi_mech. Conf/etc/host. CONF/ETC/IDMAPD. Conf/etc/initlog. Conf/etc/jwhois. Conf/etc/krb5. Conf/etc/ldap. Conf/etc/ld. So. Conf/etc/lftp. Conf/etc/libaudit. Conf/etc/libuser. Conf/etc/logrotate. Conf/etc/mke2fs. Conf/etc/modprobe. Conf/etc/mtools. Conf/etc/multipath. Conf/etc/nscd. Conf/etc/nsswitch. CONF/ETC/NTP. CONF/ETC/ODDJOBD. CONF/ETC/PAM_SMB. Conf/etc/prelink. Conf/etc/reader. Conf/etc/resolv. Conf/etc/scrollkeeper. Conf/etc/sestatus. Conf/etc/smartd. Conf/etc/sysctl. Conf/etc/syslog. Conf/etc/updatedb. Conf/etc/warnquota. Conf/etc/wvdial. Conf/etc/yp. Conf/etc/yum. CONF 

7. Displays the total number of sub-directories or files in the/var directory.

[Email protected] ~]$ ls/var/| Wc-l20

8. Remove the names of the 10 groups with the smallest number of the third field in the/etc/group file.

[Email protected] ~]# sort-t:-k3-n/etc/group | head-10 | Cut-d:-f1rootbindaemonsysadmttydisklpmemkmem

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] ~]# cat /etc/{fstab,issue} | tee /tmp/etc.testlabel=/                  /                         ext3    defaults        1  1LABEL=/boot             /boot                     ext3    defaults        1 2tmpfs                    /dev/shm                 tmpfs    defaults        0 0devpts                   /dev/pts                 devpts  gid=5,mode=620  0 0sysfs                     /sys                     sysfs   defaults        0  0proc                     /proc                    proc    defaults         0 0label=swap-sda2         swap                     swap    defaults         0 0CentOS release 5.3  (Final) kernel \ R on an \m

10. Summarize the methods used to describe the user and group management commands and complete the following exercises:

There are 4 groups of Linux users associated with the configuration file:

/ETC/PASSWD: Saving users and their property information

Meaning of each field Root:x:0:0:root:/root:/bin/bash user name: Password dot: uid:gid: Comment Information: Home directory: User default Shell

/etc/group: Group and its attribute information

What each field means: Root:x:0:root group name: group password dot: GID: comma-delimited list of users belonging to this group

/etc/shadow: User passwords and their associated properties

The meaning of each field: Root:$1$mq0q9ij0$mjtq5cavkibpd5pvbflnp0:16521:0:99999:7::: Username: encrypted Password: the date of the most recent password change: Minimum password Age: Maximum password Age: Password Disable period: Account expiration Date: Reserved field

/etc/gshadow: group password and its related properties


User and group-related administrative commands:

Useradd: Create User

-U: Specify uid-g: Specify gid-c: User's comment-d: Specify user's home directory-S: Specify user's default shell program-G: Specify user's additional group-r: Create System User

Groupadd: Creating Groups

-G: Indicates GID

-R: Creating a System Group

Usermod: User Property modification

-U: New UID

-G: New GID

-G: The new Add-on group, the original additional group will be overwritten, if the original, you want to use the-a option, indicating append

-S: New default shell

-C: New annotation information

-D: New home directory, files in the original home directory are not moved to the new home directory at the same time, to move, use the-M option

-L: New name

-L: Lock the specified user

-U: Unlock the specified user

passwd: Change Password

--stdin: Don't change passwords interactively

Userdel: Deleting users

-r: Delete User home directory

Groupmod: Group Property Modification

-N: New group name

-G: New GID

Groupdel: Group Delete

GPASSWD: Group Password

-A User: Add user to the specified group

-D User: Removes additional groups of users with the current group as the group name

-A User1,user2,... : Set up a list of users with administrative rights

(1), create group distro, its GID is 2016;

[Email protected] ~]# groupadd-g distro

(2), create user Mandriva, whose ID number is 1005; basic group is distro;

[Email protected] ~]# useradd-u 1005-g distro Mandriva

(3), create user Mageia, whose ID number is 1100, home directory is/home/linux;

[Email protected] ~]# useradd-u 1100-d/home/linux Mageia

(4), to the user mageia add password, password for mageedu;

[Email protected] ~]# echo mageedu | passwd--stdin mageiachanging password for user Mageia.passwd:all authentication tokens updated successfully.

(5), delete Mandriva, but retain their home directory;

[Email protected] ~]# Userdel Mandriva

(6), create user Slackware, its ID number is 2002, the basic group is distro, additional group Peguin;

[Email protected] ~]# groupadd peguin[[email protected] ~]# useradd-u 2002-g distro-g Peguin Slackware

(7), modify the Slackware default shell for/BIN/TCSH;

[Email protected] ~]# usermod-s/bin/tcsh Slackware

(8), add additional Group admins for user Slackware;

[Email protected] ~]# groupadd admins[[email protected] ~]# usermod-ag admins Slackware

(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] ~]# echo slack123 | Passwd-n 3-x 180-w 3--stdin slackwareadjusting Aging data for user slackware.passwd:Success

(10), add user OpenStack, whose ID number is 3003, the basic group is clouds, the additional group is Peguin and Nova;

[[email protected] ~]# groupadd clouds[[email protected] ~]# groupadd nova[[email protected] ~]# useradd-u 3003-g clouds -G Peguin,nova OpenStack

(11), add the system user MySQL, request its shell for/sbin/nologin;

[[email protected] ~]# useradd-s/sbin/nologin-r MySQL

(12), use the echo command, non-interactive add a password for OpenStack.

[Email protected] ~]# echo 123456 | passwd--stdin openstackchanging password for user Openstack.passwd:all authentication tokens updated successfully.




This article is from the "Chase Dream" blog, please be sure to keep this source http://387227.blog.51cto.com/377227/1796092

Linux third week

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.