shell基礎練習筆記

來源:互聯網
上載者:User

標籤:shell

1.關閉不必要的服務
ntsysv chkconfig
必須開啟的服務有:crond/messagebus/network/iptables/sshd/syslog/sysstat/snmpd
關閉不必要的服務指令碼:
for i in `chkconfig --list |awk ‘/3:on/ {print $1}‘|grep -v "crond\|messagebus\|sshd\|iptables\|network\|syslog\|snmpd\|sysstat"`; 
do  chkconfig --level 345 ${i} off; 
done
開啟需要的服務指令碼:
for i in "crond" "messagebus" "iptables" "network" "snmpd" "sshd" "syslog" "sysstat";
do  chkconfig --level 345 ${i} on; 
done
3.檢查服務的基本配置
dmidecode | grep "Product" | head -n 1  檢查伺服器型號
cat /proc/cpuinfo | grep name | cut -f2 -d: |uniq -c 檢查CUP訊號
free -m | grep Mem | awk ‘{print $2}‘
ifconfig | grep "inet addr" | awk -F: ‘{print $2}‘| awk ‘{print $1}‘
4.系統最佳化修改/etc/sysctl.conf檔案,sysctl -p 是修改生效;
關閉不必要的服務使用ntsysv;查看自啟動服務chkconfig;
5.修改系統的檔案控制代碼書/etc/security/limits.conf   確認控制代碼允許資料ulimit -n
6.修改sshd監聽連接埠,並禁止密碼驗證登入設定檔/etc/ssh/sshd_config

7.帳號安全,清除除root使用者之外的其他使用者的登入許可權

     #!/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

    更改root使用者密碼:

    echo "xxxxxxxx" >/root/tmp.txt   “xxxxxxxx”為設定的密碼

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

8.查看系統的基本資料指令碼

    #!/bin/bash

    dmidecode | grep "Product" | head -n 1

    cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c

    free -m | grep Mem | awk ‘{print $2}‘

    ifconfig | grep "inet addr" | awk -F: ‘{print $2}‘| awk ‘{print $1}‘

    route -n 

    cat /etc/issue | head -n 1

    uname -a

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

9.載入ext4模組

    modprobe ext4

    lsmod | grep ext4

    yum -y install e4fsprogs

10.統計登陸使用者數

uptime | cut -d‘,‘ -f 2 | sed ‘s/^[[:space:]]*//g‘

who | wc -l 

11.添加使用者指令碼

#!/bin/bash

id $1 >/dev/null 2>&1

if [ $? -eq 0 ];then

        echo "$1 is exsit!"

else

        useradd $1

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

        if [ $? -eq 0 ];then

                echo "$1 create seccuss!"

        fi

fi

12.sed刪除空行  

    sed ‘/^$/d‘ file

13.sed刪除行首的空格

    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

14.#刪除所有行尾Null 字元

sed -i  ‘s/[[:blank:]]+$//‘ filename

15.刪除行的首數字

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






本文出自 “咚咚的部落格” 部落格,謝絕轉載!

shell基礎練習筆記

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.