Shell Basics Exercise Notes

Source: Internet
Author: User

1. Turn off unnecessary services
NTSYSV Chkconfig
Services that must be turned on are: CROND/MESSAGEBUS/NETWORK/IPTABLES/SSHD/SYSLOG/SYSSTAT/SNMPD
To close unnecessary service scripts:
For i in ' chkconfig--list |awk '/3:on/{print '} ' |grep-v ' crond\|messagebus\|sshd\|iptables\|network\|syslog\|snmpd\| Sysstat "';
Do chkconfig--level 345 ${i} off;
Done
To open the required service script:
For i in "Crond" "Messagebus" "Iptables" "Network" "SNMPD" "sshd" "Syslog" "Sysstat";
Do chkconfig--level 345 ${i} on;
Done
3. Check the basic configuration of the service
Dmidecode | grep "Product" | Head-n 1 Check Server model
Cat/proc/cpuinfo | grep name | cut-f2-d: |uniq-c Check cup signal
free-m | grep Mem | awk ' {print $} '
Ifconfig | grep "inet addr" | Awk-f: ' {print $} ' | awk ' {print '} '
4. System optimization to modify the/etc/sysctl.conf file, Sysctl-p is modified to take effect;
Turn off unnecessary services using NTSYSV; View self-starting service chkconfig;
5. Modify the system's file handle book/etc/security/limits.conf confirm handle allows data ulimit-n
6. Modify the sshd listener port and disable password Authentication login profile/etc/ssh/sshd_config

7. Account security, clear the login rights of users other than the root user

#!/bin/bash

For k in ' cat/etc/passwd | Grep-i "\/bin\/bash" | Grep-v "Root" | cut-d:-f1 ';

Do

Usermod-s/sbin/nologin ${k};

Done

To change the root user password:

echo "xxxxxxxx" >/root/tmp.txt "xxxxxxxx" for the Set password

passwd root--stdin </root/tmp.txt;rm–f/root/tmp.txt

8. View the system's basic information script

#!/bin/bash

Dmidecode | grep "Product" | Head-n 1

Cat/proc/cpuinfo | grep name | Cut-f2-d: | Uniq-c

free-m | grep Mem | awk ' {print $} '

Ifconfig | grep "inet addr" | Awk-f: ' {print $} ' | awk ' {print '} '

Route-n

Cat/etc/issue | Head-n 1

Uname-a

df-h | awk ' {print $1,$2} '

9. Load the EXT4 module

Modprobe EXT4

Lsmod | grep EXT4

Yum-y Install E4fsprogs

10. Statistics of logged-in users

Uptime | Cut-d ', '-F 2 | Sed ' s/^[[:space:]]*//g '

W.H.O. | Wc-l

11. Add User Scripts

#!/bin/bash

ID $ >/dev/null 2>&1

If [$?-eq 0];then

echo "is exsit!"

Else

Useradd $

echo "123456" | passwd--stdin "$" >/dev/null 2>&1

If [$?-eq 0];then

echo "Create seccuss!"

Fi

Fi

12.sed Delete empty lines

Sed '/^$/d ' file

13.sed Delete Spaces at the beginning of a line

Sed-i ' s/^[[:space:]]*//' filename
Sed-i ' s/[[:space:]]*//g ' filename # #删除所有空格
sed s/[[:space:]]//g filename
#sed ' s/^[]*//g ' file
#sed ' s/^ *//g ' file
#sed ' s/^[[:space:]]*//g ' file

#删除所有行尾空字符

Sed-i ' s/[[:blank:]]+$//' filename

15. Delete the first number of rows

Sed-i ' s/^[0-9]*//g ' filename
Sed ' s#^[0-9]{1,} # #g ' filename
Sed ' s#^[0-9]* # #g ' filename






This article from "Banging blog" blog, declined reprint!

Shell Basics Exercise Notes

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.