• 博客設置
  • 編輯管理
  • 返回首頁
焚花祭秋
Wordpress Typecho 以及周邊知識的一個筆記,成長的過程中相互學習,共同進步!
首頁 歸檔 關於 友鏈 留言
分類
  • 博客.技巧
  • 網絡.主機
  • HOME
  • 網絡.主機
  • LinuxVPS 初級教程P3 常用安全設置相關內容

LinuxVPS 初級教程P3 常用安全設置相關內容

作者:焚花祭秋  /   发布时间:February 6, 2012  /   分类:網絡.主機  /   2 Comments

字體大小選擇: [ 超大字體 中型字體 默認字體 ]

接觸VPS的朋友們看一下,主要是關於VPS安全方面相關內容的,陸續更新:

禁止ROOT登陸 保證安全性
使用DDoS deflate簡單防攻擊
iftop Linux流量監控工具
每日自動備份VPS到FTP空間
升級LNMP的NGINX到最新版

一、修改SSH端口

vi /etc/ssh/sshd_config

找到其中的#Port 22(第13行),去掉#,修改成Port 3333

使用如下命令,重啟SSH服務,註:以後用新端口登陸。

service sshd restart

二、禁止ROOT登陸

先添加一個新帳號vpsmm,可以自定義:

useradd vpsmm

給vpsmm帳號設置密碼:

passwd vpsmm

仍舊是修改/etc/ssh/sshd_config文件,第39行:#PermitRootLogin yes,去掉前面的#,並把yes改成no,然後,重啟SSH服務。以後,先使用vpsmm登陸,再su root即可得到ROOT管理權限。

login as: vpsmm
vpsmm@ip password:*****
Last login: Tue Nov 22 14:39:58 2010 from 1.2.3.4
su root
Password:*********** #註這裏輸入ROOT的密碼

三、使用DDos deflate簡單防落CC和DDOS攻擊

使用netstat命令,查看VPS當前鏈接確認是否受到攻擊:

netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

IP前面的數字,即為連接數,如果說正常網站,幾十到一百都屬於正常連接,但出現幾百,或上千的就可以墾定這個IP與你的VPS之間可能存在可疑連接現象。

可以使用iptables直接BAN了這個IP的永久訪問:

iptables -A INPUT -s 12.34.56.78 -j DROP

今天介紹給大家一種方法,是使用軟件DDos deflate來自動檢測並直接BAN掉的方法,首先我們要確認一下iptables服務狀態,默認CENTOS就安裝的,不看也行。

service iptables status

安裝DDos deflat:

wget http://www.inetbase.com/scripts/ddos/install.sh
chmod +x install.sh
./install.sh

安裝後需要修改/usr/local/ddos/ddos.conf,主要是APF_BAN=1要設置成0,因為要使用iptables來封某些可疑連接,註意EMAIL_TO="root",這樣BAN哪個IP會有郵件提示:

##### Paths of the script and other files
PROGDIR="/usr/local/ddos"
PROG="/usr/local/ddos/ddos.sh"
IGNORE_IP_LIST="/usr/local/ddos/ignore.ip.list"  //IP地址白名單
CRON="/etc/cron.d/ddos.cron"    //定時執行程序
APF="/etc/apf/apf"
IPT="/sbin/iptables"
##### frequency in minutes for running the script
##### Caution: Every time this setting is changed, run the script with --cron
#####          option so that the new frequency takes effect
FREQ=1   //檢查時間間隔,默認1分鐘
##### How many connections define a bad IP? Indicate that below.
NO_OF_CONNECTIONS=150     //最大連接數,超過這個數IP就會被屏蔽,一般默認即可
##### APF_BAN=1 (Make sure your APF version is atleast 0.96)
##### APF_BAN=0 (Uses iptables for banning ips instead of APF)
APF_BAN=1        //使用APF還是iptables。推薦使用iptables,將APF_BAN的值改為0即可。
##### KILL=0 (Bad IPs are'nt banned, good for interactive execution of script)
##### KILL=1 (Recommended setting)
KILL=1   //是否屏蔽IP,默認即可
##### An email is sent to the following address when an IP is banned.
##### Blank would suppress sending of mails
EMAIL_TO="root"   //當IP被屏蔽時給指定郵箱發送郵件,推薦使用,換成自己的郵箱即可
##### Number of seconds the banned ip should remain in blacklist.
BAN_PERIOD=600    //禁用IP時間,默認600秒,可根據情況調整

四、使用iftop查看詳細網絡狀況

安裝IFTOP軟件:

yum -y install flex byacc  libpcap ncurses ncurses-devel libpcap-devel
wget http://www.ex-parrot.com/pdw/iftop/download/iftop-0.17.tar.gz
tar zxvf iftop-0.17.tar.gz
cd iftop-0.17
./configure
make && make install

安裝後,使用iftop運行,查看網絡情況。TX,發送流量;RX,接收流量;TOTAL,總流量;Cumm,運行iftop期間流量;peak,流量峰值;rates,分別代表2秒、10秒、40秒的平均流量。

快捷鍵:h幫助,n切換顯示IP主機名,s是否顯示本機信息,d是否顯示遠端信息,N切換端口服務名稱,b切換是否時數流量圖形條。

五、每日備份你的VPS上傳到FTP空間

腳本:http://www.vpsmm.com/soft/AutoBackupToFtp.sh

六、升級LNMP中的NGINX到最新版

現在最新版是0.8.53,如果以後出新版,只要更新版本號就可以,在SSH裏運行:

wget http://www.nginx.org/download/nginx-0.8.53.tar.gz
tar zxvf nginx-0.8.53.tar.gz
cd nginx-0.8.53
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module  --with-http_sub_module
make
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
cd objs/
cp nginx /usr/local/nginx/sbin/
/usr/local/nginx/sbin/nginx -t
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
/usr/local/nginx/sbin/nginx -v
cd ..
cd ..
rm -rf nginx-0.8.53
rm -rf nginx-0.8.53.tar.gz

七、常用netstat命令:

1.查看所有80端口的連接數

netstat -nat|grep -i "80"|wc -l

2.對連接的IP按連接數量進行排序

netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

3.查看TCP連接狀態

netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn
netstat -n | awk '/^tcp/ {++S[$NF]};END {for(a in S) print a, S[a]}'
netstat -n | awk '/^tcp/ {++state[$NF]}; END {for(key in state) print key,"\t",state[key]}'
netstat -n | awk '/^tcp/ {++arr[$NF]};END {for(k in arr) print k,"\t",arr[k]}'
netstat -n |awk '/^tcp/ {print $NF}'|sort|uniq -c|sort -rn
netstat -ant | awk '{print $NF}' | grep -v '[a-z]' | sort | uniq -c

4.查看80端口連接數最多的20個IP

netstat -anlp|grep 80|grep tcp|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -n20
netstat -ant |awk '/:80/{split($5,ip,":");++A[ip[1]]}END{for(i in A) print A,i}' |sort -rn|head -n20

5.用tcpdump嗅探80端口的訪問看看誰最高

tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr |head -20

6.查找較多time_wait連接

netstat -n|grep TIME_WAIT|awk '{print $5}'|sort|uniq -c|sort -rn|head -n20

7.找查較多的SYN連接

netstat -an | grep SYN | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr | more

上一篇: LinuxVPS 初級教程P2 LNMP安裝 常規設置 SFTP管理指南 下一篇: LinuxVPS 初級教程P4 LinuxVPS遠程桌面的安裝教程
    分享到: QQ空間 新浪微博 騰訊微博 開心網 人人網 淘江湖 百度空間
訂閱本站:焚花祭秋
文本標籤:linuxvps, vps安全設置, vps初級教程
友情聲明:本站所有文章皆為原創,圖文皆為網絡搜索傳播,轉載請以鏈接形式標明原文出處地址,謝謝合作!
本文鏈接:http://tc.muo.me/linux-vps-Security-Settings.html [复制]

   哇!已經有2枚讓人不淡定的評論! »

  1. 小七 小七
    March 21st, 2012 At Wednesday 07:03 PM    ReplyTa

    這個主題速度給力啊,程序不錯

  2. Demon Demon
    March 20th, 2012 At Tuesday 09:35 AM    ReplyTa

    我勒個去。你Y的幾個站呀。


取消回复
My WeChat

簡繁切換

    • WordPress,側欄等地方非插件實現Tab切換的效果代碼分享
    • WodPress 利用Jquery實現圖片顯隱,標題加載中提示等特效
    • Wamp 環境下安裝Phpcms 如何添加GD庫
    • WordPress,非插件實現側欄彩色標簽雲的代碼分享
    • Android 安卓下獲取WIFI萬能鑰匙所破解的密碼
    • Wordpress Smile評論表情免費分享 奶瓶仔,悠嘻猴等五套

  • YueTing.Org
    悦听有声,路过看看
  • 自由草
    简繁转换功能在也没刷新下会失效
  • 天地华宇
    好东西 谢谢分享先收藏一下下 ...
  • flippy
    主题蛮好看的,好像轻博客一样
  • flippy
    不错呀
  • qkwu
    不错哦 收藏了
文章 RSS And 评论 RSS
焚花祭秋 Is Powered By Wordpress Theme Desgin By 沫(Muo.me)