Linux OPS-3rd week jobs

Source: Internet
Author: User
Tags echo command stdin uuid



Content of this week's job:

1. List the user name of all logged-in users on the current system, note: The same user logged in multiple times, only once.


#who | tr-s [[: Space:]] | Cut-d ""-f1 | Sort-u



[email protected] bin]# who | tr-s [[: Space:]] | Cut-d ""-f1 | Sort-u

Kzxjwb

Root


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

#last | Head-1


[Email protected] bin]# Last | Head-1

Root PTS/4 223.72.80.48 Mon Oct 23:07 still logged in


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


#cat/etc/passwd | Cut-d ":"-f7 | uniq-c | Sort-n | Tail-1 | tr-s [[: Space:]] | Cut-d ""-f3


[Email protected] webapps]# CAT/ETC/PASSWD | Cut-d ":"-f7 | uniq-c | Sort-n | Tail-1 | tr-s [[: Space:]] | Cut-d ""-f3

/sbin/nologin


4, the information of the third field in/ETC/PASSW D with the largest number of the first 10 users is changed to uppercase and then saved to the/tmp/maxusers.txt file.


[Email protected]/]# CAT/ETC/PASSWD | Sort-t ":"-nk3 | tail-10 | tr [A-z] [a-z] >/tmp/maxusers.txt

[Email protected]/]# Cat/tmp/maxusers.txt

User2:x:1024:1026::/home/user2:/bin/bash

User3:x:1025:1027::/home/user3:/bin/bash

User4:x:1026:1028::/home/user4:/bin/bash

User5:x:1027:1029::/home/user5:/bin/bash

User6:x:1028:1030::/home/user6:/bin/bash

User7:x:1029:1031::/home/user7:/bin/bash

User8:x:1030:1032::/home/user8:/bin/bash

User9:x:1031:1033::/home/user9:/bin/bash

User10:x:1032:1034::/home/user10:/bin/bash

User11:x:1033:1035::/home/user11:/bin/bash



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


#ifconfig | Grep-e "inet addr" | Cut-d ":"-f2 | Cut-d ""-f1


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] >/tmp/etc.conf

[Email protected]/]# cat/tmp/etc.conf

/etc/asound. CONF

/ETC/DNSMASQ. CONF

/etc/dracut. CONF

/etc/e2fsck. CONF

/etc/host. CONF

/etc/kdump. CONF

/etc/krb5. CONF

/etc/ld. So. CONF

/etc/libaudit. CONF

/etc/libuser. CONF

/etc/locale. CONF

/etc/logrotate. CONF

/etc/man_db. CONF

/etc/mke2fs. CONF

/etc/nsswitch. CONF

/ETC/NTP. CONF

/etc/resolv. CONF

/etc/rsyslog. CONF

/etc/sestatus. CONF

/etc/sudo. CONF

/etc/sudo-ldap. CONF

/etc/sysctl. CONF

/ETC/TCSD. CONF

/etc/vconsole. CONF

/etc/yum. CONF



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


[Email protected]/]# Ll/var | Wc-l

22



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


[Email protected]/]# Cat/etc/group | Sort-t ":"-nk3 | head-10 | Cut-d ":"-f1


Root

Bin

Daemon

Sys

cd/

Tty

Disk

Lp



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/etc/issue >/tmp/etc.test

[Email protected]/]# cat/tmp/etc.test


#

#/etc/fstab

# Created by Anaconda on Fri Mar 11 01:59:10 2016

#

# Accessible filesystems, by reference, is maintained under '/dev/disk '

# See mans Pages Fstab (5), Findfs (8), mount (8) and/or Blkid (8) for more info

#

UUID=E7EDF137-5D28-407F-98B9-804EAD7732B2/XFS Defaults 0 0

Uuid=6d3d5767-9a65-4f80-ae84-87d2c324edbd/boot XFS Defaults 0 0

Uuid=63a207f4-e7ae-4b27-87c5-f56054d49206/data XFS Defaults 0 0

Uuid=d0e6dd42-8f9c-4fba-b450-d068475fbb14/tmp XFS Defaults 0 0

UUID=9015AA16-40BD-46DB-8C6B-B019513A8111/USR XFS Defaults 0 0

UUID=DCBBA68B-953B-4CD5-9B92-88801EF89C0A swap swap defaults 0 0

\s

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] ~]# groupadd-g distro

[Email protected] ~]# Cat/etc/group |tail-1

DISTRO:X:2016:


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


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

Useradd:uid 1005 is not unique

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

[[email protected] ~]# ID Mandriva

uid=1105 (Mandriva) gid=2016 (distro) groups=2016 (distro)



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


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

[Email protected] ~]# CAT/ETC/PASSWD | Tail-1

Mageia:x:1100:1100::/home/linux:/bin/bash



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


[Email protected] ~]# echo "mageedu" | Passwd–stdin Mageia

Passwd:only one user name may specified.




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


[Email protected] ~]# CAT/ETC/PASSWD | grep Mandriva

Mandriva:x:1105:2016::/home/mandriva:/bin/bash

[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

[[email protected] ~]# ID Slackware

uid=2002 (Slackware) gid=2016 (distro) groups=2016 (distro) (Peguin)


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

[Email protected] ~]# CAT/ETC//PASSWD | Tail-1

Slackware:x:2002:2016::/home/slackware:/bin/bash

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

[Email protected] ~]# CAT/ETC/PASSWD | Tail-1

Slackware:x:2002:2016::/home/slackware:/bin/tcsh

[Email protected] ~]#



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

[Email protected] ~]# groupadd Admins

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

[[email protected] ~]# ID Slackware

uid=2002 (Slackware) gid=2016 (distro) groups=2016 (distro), (Peguin), 2018 (admins)



(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 Slackware | PASSWD–STDIN-N3-X180-W3 Slackware

Passwd:only one user name may specified.

[Email protected] ~]# Cat/etc/shadow | Tail-1

slackware:!! : 17098:0:99999:7:::



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


Useradd-u 3003-g clouds-g Peguin OpenStack


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


#useradd-R-s/sbin/nologin MySQL



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

echo OpenStack | Passwd–stdin OpenStack &>/dev/null


This article is from the "9099360" blog, please be sure to keep this source http://9109360.blog.51cto.com/9099360/1865243

Linux OPS-3rd week jobs

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.