[筆記] Linux管理、Shell script 簡易範例


1.防火牆管理

http的URL預設使用埠為80,而https(s是加密的意思)的URL預設使用埠為 443

  • firewall-cmd 指令
    firewall-cmd --list-all

    firewall-cmd --add-service=http

    firewall-cmd --add-port=25565/tcp (Minecraft port)

    使用port加入httpd
    [root@localhost ~]# firewall-cmd --add-port=80/tcp

  • ufw 指令
    (1)下載ufw套件
    [root@localhost ~]# yum install epel-release (給yum新增支援庫)
    [root@localhost ~]# yum install ufw
    [root@localhost ~]# systemctl start ufw

    (2)ufw指令介紹
    ufw allow http

    ufw allow 443 & ufw deny443

2.Shell script

1.echo 介紹
[root@localhost ~]# steven=hi
[root@localhost ~]# echo $steven

[root@localhost ~]# steven="hi alice"
[root@localhost ~]# echo $steven

2.read 介紹
在終端機輸入read,read將讀取從鍵盤輸入之變數的值
[root@localhost ~]# read steven
(輸入hi bob)
[root@localhost ~]# echo $steven

3.範例:shell腳本
(1)
[root@localhost ~]# vim ping.sh
在文件中打入

ping 8.8.8.8 -c 1 > ping.txt


(2)給予ping.sh執行的權限
[root@localhost ~]# chmod +x ping.sh
(3)執行
[root@localhost ~]# ./ping.sh

(4)結合read運用
[root@localhost ~]# vim ping.sh
在文件中打入

read iping
ping $iping -c 1 > ping.txt

(意思為讀取輸入的iping,ping一次後存回ping.txt)


4.for 迴圈介紹

for 變數 in 文字1 文字2 文字3
do
程式區塊
done

範例:使用for迴圈連續建立帳號
[root@localhost ~]# vim test.sh

#seq=sequence
for UserAccount in $(seq 1 10)
do
    AccountName="RD"
    useradd $AccountName$UserAccount
    echo $AccountName$UserAccount | passwd --stdin $AccountName$UserAccount
    chage -d 0 $AccountName$UserAccount #強制每次登入都更改密碼
done


#linux #shell script






你可能感興趣的文章

滲透測試重新打底(2.1)--論Enumeration(枚舉)之DNS Enumeration

滲透測試重新打底(2.1)--論Enumeration(枚舉)之DNS Enumeration

Donut Maze 1

Donut Maze 1

深入探討 JavaScript 中的參數傳遞:call by value 還是 reference?

深入探討 JavaScript 中的參數傳遞:call by value 還是 reference?






留言討論