Linux Fundamentals 03

Source: Internet
Author: User


Reset three virtual machines in order before you start learning to avoid the impact of yesterday's input on today's learning

Rht-vmctl Reset Classroom #昨天的博客 Vmctl wrote the VMCLT

RHT-VMCTL Reset Server Correction ~

Rht-vmctl Reset Desktop

Configure the following static parameters for the virtual machine server

– Host Name: server0.example.com

– IP Address: 172.25.0.11

– Subnet Mask: 255.255.255.0

– Default gateway: 172.25.0.254

–dns Server: 172.25.254.254


Vim/etc/resolv.conf

====>vim in NameServer 172.25.254.254

Exit vim


Test DNS Resolution command

[email protected] ~]# nslookup server0.example.com

#####################################################


Building a yum Warehouse


[Email protected] ~]# rm-rf/etc/yum.repos.d/*


[Email protected] ~]# Vim/etc/yum.repos.d/abc.repo


http://172.25.254.254/content/rhel7.0/x86_64/dvd/



[email protected] ~]# Yum Clean all


[email protected] ~]# Yum repolist


#################################################



View Text file contents


Cat: Suitable for viewing files with less content

Less: Suitable for viewing files with more content


See the text file part of the content

Head-n: First few lines

Tail-n: A few lines in the tail


View Time

Date


Calculator

Bc


######################################################


Pipe: The output of the preceding command is processed by the following command as a parameter of the following command


Display/etc/passwd text content 8--12 line?


[Email protected]/]# HEAD-12/ETC/PASSWD | Tail-5

[Email protected]/]# Cat-n/etc/passwd | head-12 | Tail-5


[Email protected]/]# Cat-n/etc/passwd | Less


[Email protected]/]# echo | Bc

[Email protected]/]# echo 8*8 | Bc


[Email protected]/]# Ifconfig | Head-2


######################################################

grep: View the contents of a text file, displaying the line containing the specified string


–grep [option] ' Match string ' text file ...

[[email protected]/]# grep ' root '/etc/passwd


[[email protected]/]# grep ' man '/etc/man_db.conf


[[email protected]/]# grep ' Root '/etc/passwd

[Email protected]/]# grep-i ' Root '/etc/passwd #忽略大小写


[[email protected]/]# grep ' root '/etc/passwd

[[email protected]/]# grep-v ' root '/etc/passwd #取反, does not contain


#################################################



–^word Start with string word

–word$ End With string word


[[email protected]/]# grep ' ^root '/etc/passwd


[[email protected]/]# grep ' root$ '/etc/passwd

[[email protected]/]# grep ' bash$ '/etc/passwd


Match Blank Line

[[email protected]/]# grep ' ^$ '/etc/default/useradd


Remove blank lines, display

[Email protected]/]# grep-v ' ^$ '/etc/default/useradd



Regular expressions: To express what you think in a descriptive language


Remove comments and blank lines to show valid data:


# grep-v ' ^# '/etc/login.defs | Grep-v ' ^$ '


#####################################################



Find Files by criteria

Find the corresponding file recursively according to the preset conditions


–find [Catalogue] [condition 1]


– Common conditions indicate:

-type type (f file, D directory, L shortcut)

-name "Document Name"


-size +|-File Size (k, M, G)

-user User Name



[Email protected]/]# find/boot/-type l

[Email protected]/]# Ls/boot/grub/menu.lst

[Email protected]/]# ls-l/boot/grub/menu.lst


[Email protected]/]# find/boot/-type F

[Email protected]/]# find/boot/-type D


[Email protected]/]# find/etc/-name "passwd"

[Email protected]/]# find/etc/-name "*tab*"


[Email protected]/]# Mkdir/root/install

[Email protected]/]# Touch/root/install.log

[Email protected]/]# Touch/root/install.bak

[Email protected]/]# find/root-name "install*"


[Email protected]/]# find/root-name "install*"-type D

[Email protected]/]# find/root-name "install*"-type F



[Email protected]/]# find/boot/-size +10m

[Email protected]/]# find/boot/-size-10m



--exec operation using the Find command

–find. .. -exec processing command {} \;


# find/boot/-size +10m

# find/boot/-size +10m-exec cp-r {}/opt/\;

# ls/opt


# find/etc/-name "*tab"

# find/etc/-name "*tab"-exec cp-r {}/mnt/\;

# ls-a/mnt


##################################################


# Mkdir/root/findfiles


# Find/-user Student-type f-exec cp-r {}/root/findfiles/\;



###################################################

User and Group Management

User account:

1. Can log into the operating system

2. Access control is possible (different user rights are different)

Group accounts: Easy to manage user accounts (permissions)

User account and group account unique identifier: UID GID

The Administrator uid is: 0


Group accounts: Basic group additional groups (public group subordinate groups)


##################################################


Using the Useradd command

–useradd [Options] ... User name


Common Command Options

–-u User ID,-D home directory path,-s login shell

–-G Basic Group,-G additional Group



[[email protected]/]# ID NSD01


[[email protected]/]# grep ' nsd01 '/etc/passwd #用户基本信息

Nsd01:x:1002:1002::/home/nsd01:/bin/bash


User name: Password placeholder: uid:gid: User's description: Home directory: Interpreter


[Email protected]/]# Useradd nsd01

[[email protected]/]# ID NSD01

[[email protected]/]# grep ' NSD '/etc/passwd


[Email protected]/]# useradd-u 1100 nsd02 #指定UID

[[email protected]/]# grep ' NSD '/etc/passwd


[Email protected]/]# useradd-d/op/haha nsd03 #指定家目录

[[email protected]/]# grep ' NSD '/etc/passwd

Specify the Login interpreter program

[Email protected]/]# useradd-s/sbin/nologin nsd04

[[email protected]/]# grep ' NSD '/etc/passwd

Cannot log on to the operating system if the user's interpreter program is/sbin/nologin


[Email protected]/]# useradd-g nsd01 nsd09

[[email protected]/]# ID nsd09


[Email protected]/]# useradd-g nsd01 nsd10

[[email protected]/]# ID NSD10



#############################################


User password information stored in the/etc/shadow file


Using the passwd command

–passwd [user Name]

–echo ' Password ' | passwd--stdin User Name


Supplemental command: command to temporarily switch user identities

[[email protected]/]# Su-user name


[Email protected]/]# echo 123 | passwd--stdin NSD01

[Email protected]/]# echo 123 | passwd--stdin nsd02


[Email protected]/]# SU-NSD01

[Email protected] ~]$ passwd

[Email protected] ~]$ exit #退回到root


[Email protected]/]#


####################################################


Modify User Properties

Using the Usermod command

–usermod [Options] ... User name


Common Command Options

–-u User ID,-D home directory path,-s login shell

–-G Basic Group,

–-g additional Groups



[Email protected]/]# Useradd nsd11

[[email protected]/]# grep ' nsd11 '/etc/passwd


# usermod-u 1200-d/opt/test-s/sbin/nologin nsd11


[[email protected]/]# grep ' nsd11 '/etc/passwd


#####################################################

Delete User

Using the Userdel command

–userdel [-r] User name #并且删除家目录


Common tip: Insufficient permissions

Permission denied



#####################################################


Group account Management


Add Group

Group basic information is stored in the/etc/group file

[Email protected] ~]# head-1/etc/group

root:x:0:

Group name: Password placeholder: GID: Group member list


Using the Groupadd command

–groupadd [-G Group ID] Group name


[Email protected] ~]# Useradd Kenji

[Email protected] ~]# Useradd Tom

[Email protected] ~]# Useradd Kaka

[Email protected] ~]# Useradd Henter


[Email protected] ~]# Groupadd Tarena


[[email protected] ~]# grep ' Tarena '/etc/group

TARENA:X:1110:


Using the GPASSWD command


–GPASSWD-A User Name Group name

–GPASSWD-D User Name Group name

–gpasswd-m ' user name, user name ' group name #可以添加多个


[[email protected] ~]# grep ' Tarena '/etc/group #查看组信息

[Email protected] ~]# gpasswd-a Kenji Tarena #加入组成员

[[email protected] ~]# ID Kenji


[Email protected] ~]# gpasswd-a Tom Tarena

[[email protected] ~]# grep ' Tarena '/etc/group


[Email protected] ~]# gpasswd-a Kaka Tarena

[[email protected] ~]# grep ' Tarena '/etc/group


[Email protected] ~]# gpasswd-d Kenji Tarena #删除组成员

[[email protected] ~]# grep ' Tarena '/etc/group


[Email protected] ~]# gpasswd-m ' Kenji,henter ' Tarena

[[email protected] ~]# grep ' Tarena '/etc/group


[Email protected] ~]# gpasswd-m ' Kenji,kaka,tom,henter ' Tarena

[[email protected] ~]# grep ' Tarena '/etc/group

[Email protected] ~]# gpasswd-m ' Tarena

[[email protected] ~]# grep ' Tarena '/etc/group


Delete a group

Using the Groupdel command

–groupdel Group Name

#########################################################

Archiving and compression


1. Space saving

2. Facilitate the management of fragmented documents


Tar Integrated Backup tool

–-c: Creating an Archive

–-x: Release Archive

–-f: Specify the archive file name

–-z,-j,-j: Calling the. gz,. bz2,. xz Format tools for processing

–-c (UPPERCASE): Specify the release location


–-t: Displays a list of files in the archive

–-p (uppercase): Keep the absolute path to the file within the archive


[Email protected] ~]# rm-rf/opt/*

[Email protected] ~]# rm-rf/mnt/*


# tar-zcf/opt/file.tar.gz/boot//ETC/PASSWD


[Email protected] ~]# ls/opt


[Email protected] ~]# tar-xf/opt/file.tar.gz-c/mnt


[Email protected] ~]# ls/mnt


[Email protected] ~]# ls/mnt/etc

[Email protected] ~]# Ls/mnt/boot



Use tar-c ... Command

–TAR-ZCF backup files. tar.gz The document that was backed up ....

–TAR-JCF backup files. tar.bz2 The document that was backed up ....

–TAR-JCF backup files. Tar.xz The document that was backed up ....


[Email protected] ~]# tar-tf/opt/file.tar.gz


Use BZIP2 compression to package and compress in absolute path mode


# tar-pjcf/root/backup.tar.bz2/usr/local/

# ls/root/

# tar-tf/root/backup.tar.bz2 #查看包里面内容


-Z represents gzip compression format

-J represents bzip2 compression format

-j represents the XZ compression format

###################################################

NTP Network Time Protocol

Network Time Protocol

–NTP Server provides standard time for clients

–NTP client needs to maintain communication with NTP server


Packaging, configuration, service


One, the server, Linux system on a software


NTP time synchronization server, classroom


II. client server, installing client software

RHEL7 Client's School Time service

– Package: Chrony

– Configuration file:/etc/chrony.conf

– System Services: Chronyd


[Email protected] ~]# rpm-q chrony

Chrony-1.29.1-1.el7.x86_64


[Email protected] ~]# vim/etc/chrony.conf

#server 0.rhel.pool.ntp.org Iburst #注释

#server 1.rhel.pool.ntp.org Iburst #注释

#server 2.rhel.pool.ntp.org Iburst #注释

Server 172.25.254.254 Iburst #指定服务端IP地址

.......


[Email protected] ~]# systemctl restart Chronyd #重起服务

[Email protected] ~]# Systemctl enable Chronyd #设置开机自起


Verify:


[[Email protected] ~]# Date


[Email protected] ~]# date-s "2008-09-08 11:11:11" #修改时间


[[Email protected] ~]# Date

[[email protected] ~]# systemctl restart chronyd #重起服务, sync


[Email protected] ~]# date #此处大概需要10秒才会成功

[[Email protected] ~]# Date

[[Email protected] ~]# Date


Linux Fundamentals 03

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.