亚洲免费在线视频-亚洲啊v-久久免费精品视频-国产精品va-看片地址-成人在线视频网

您的位置:首頁技術(shù)文章
文章詳情頁

如何保證Linux服務(wù)器的安全

瀏覽:133日期:2024-07-27 08:17:49

很少見有人馬上為一臺新安裝的服務(wù)器做安全措施,然而我們生活所在的這個社會使得這件事情是必要的。不過為什么仍舊這么多人把它拖在最后?我已經(jīng)做了相同的事情,它常常可以歸結(jié)為想要馬上進入有趣的東西。希望這篇文章將向大家展示,確保服務(wù)器安全沒有你想得那樣難。在攻擊開始后,俯瞰你的“堡壘”會相當(dāng)享受的。

如何保證Linux服務(wù)器的安全

這篇文章為Ubuntu 12.04.2 LTS而寫,你也可以在任何其他Linux分發(fā)版上做相同的事情。

我從哪兒開始?

如果服務(wù)器已經(jīng)有了一個公有IP,你會希望立即鎖定 root 訪問。事實上,你得鎖定整個ssh訪問,并確保只有你可以訪問。增加一個新用戶,把它加入admin組(在/etc/sudoers預(yù)配置以擁有sudo訪問權(quán)限)。

$ sudo addgroup adminAdding group ’admin’ (GID 1001)Done.$ sudo adduser spenserjAdding user `spenserj’ ...Adding new group `spenserj’ (1002) ...Adding new user `spenserj’ (1001) with group `spenserj’ ...Creating home directory `/home/spenserj’ ...Copying files from `/etc/skel’ ...Enter new UNIX password:Retype new UNIX password:passwd: password updated successfullyChanging the user information for spenserjEnter the new value, or press ENTER for the default Full Name []: Spenser Jones Room Number []: Work Phone []: Home Phone []: Other []:Is the information correct? [Y/n] y$ sudo usermod -a -G admin spenserj

你也將希望在你電腦上創(chuàng)建一個私有key,并且在服務(wù)器上禁用討厭的密碼驗證。

$ mkdir ~/.ssh$ echo 'ssh-rsa [your public key]' > ~/.ssh/authorized_keys

/etc/ssh/sshd_config

PermitRootLogin noPermitEmptyPasswords noPasswordAuthentication noAllowUsers spenserj

重新加載SSH,使用修改生效,之后嘗試在一個新會話中登陸來確保所有事情正常工作。如果你不能登陸,你將仍然擁有你的原始會話來做修改。

$ sudo service ssh restartssh stop/waitingssh start/running, process 1599更新服務(wù)器

既然你是訪問服務(wù)器的唯一用戶,你就不用擔(dān)心黑客鬼鬼祟祟進入,再次正常呼吸。當(dāng)有一些針對你服務(wù)器的更新時,正是修補的機會,所以動手吧,就現(xiàn)在。

$ sudo apt-get update...Hit http://ca.archive.ubuntu.com precise-updates/universe Translation-en_CAHit http://ca.archive.ubuntu.com precise-updates/universe Translation-enHit http://ca.archive.ubuntu.com precise-backports/main Translation-enHit http://ca.archive.ubuntu.com precise-backports/multiverse Translation-enHit http://ca.archive.ubuntu.com precise-backports/restricted Translation-enHit http://ca.archive.ubuntu.com precise-backports/universe Translation-enFetched 3,285 kB in 5s (573 kB/s)Reading package lists... Done$ sudo apt-get upgradeReading package lists... DoneBuilding dependency treeReading state information... DoneThe following packages have been kept back: linux-headers-generic-lts-quantal linux-image-generic-lts-quantalThe following packages will be upgraded: accountsservice apport apt apt-transport-https apt-utils aptitude bash ...73 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.Need to get 61.0 MB of archives.After this operation, 151 kB of additional disk space will be used.Do you want to continue [Y/n]? Y...Setting up libisc83 (1:9.8.1.dfsg.P1-4ubuntu0.6) ...Setting up libdns81 (1:9.8.1.dfsg.P1-4ubuntu0.6) ...Setting up libisccc80 (1:9.8.1.dfsg.P1-4ubuntu0.6) ...Setting up libisccfg82 (1:9.8.1.dfsg.P1-4ubuntu0.6) ...Setting up libbind9-80 (1:9.8.1.dfsg.P1-4ubuntu0.6) ...Setting up liblwres80 (1:9.8.1.dfsg.P1-4ubuntu0.6) ...Setting up bind9-host (1:9.8.1.dfsg.P1-4ubuntu0.6) ...Setting up dnsutils (1:9.8.1.dfsg.P1-4ubuntu0.6) ...Setting up iptables (1.4.12-1ubuntu5) ......安裝防火墻

安裝現(xiàn)在正最流行的防火墻軟件?好,行動吧。那就配置一個防火墻。之后你總是可以增加另一個異常,幾分鐘額外的工作并不會折騰死你。Iptables在Ubuntu里預(yù)裝了,所以去設(shè)置一些規(guī)則吧。

$ sudo mkdir /etc/iptables

/etc/iptables/rules

*filter:INPUT DROP [0:0]:FORWARD DROP [0:0]:OUTPUT DROP [0:0]# Accept any related or established connections-I INPUT 1 -m state --state RELATED,ESTABLISHED -j ACCEPT-I OUTPUT 1 -m state --state RELATED,ESTABLISHED -j ACCEPT# Allow all traffic on the loopback interface-A INPUT -i lo -j ACCEPT-A OUTPUT -o lo -j ACCEPT# Allow outbound DHCP request - Some hosts (Linode) automatically assign the primary IP#-A OUTPUT -p udp --dport 67:68 --sport 67:68 -j ACCEPT# Outbound DNS lookups-A OUTPUT -o eth0 -p udp -m udp --dport 53 -j ACCEPT# Outbound PING requests-A OUTPUT -p icmp -j ACCEPT# Outbound Network Time Protocol (NTP) request-A OUTPUT -p udp --dport 123 --sport 123 -j ACCEPT# SSH-A INPUT -i eth0 -p tcp -m tcp --dport 22 -m state --state NEW -j ACCEPT# Outbound HTTP-A OUTPUT -o eth0 -p tcp -m tcp --dport 80 -m state --state NEW -j ACCEPT-A OUTPUT -o eth0 -p tcp -m tcp --dport 443 -m state --state NEW -j ACCEPTCOMMIT

通過 iptables-apply 命令為規(guī)則集生效。如果你丟失連接,修補你的規(guī)則,在繼續(xù)之前再試一下

$ sudo iptables-apply /etc/iptables/rulesApplying new ruleset... done.Can you establish NEW connections to the machine? (y/N) y... then my job is done. See you next time.

創(chuàng)建文件 /etc/network/if-pre-up.d/iptables,然后寫入下面內(nèi)容。當(dāng)你啟動服務(wù)器的時候,將自動載入你的iptables規(guī)則。

/etc/network/if-pre-up.d/iptables

#!/bin/shiptables-restore < /etc/iptables/rules

現(xiàn)在給它執(zhí)行權(quán)限,執(zhí)行文件,以確保它正常載入

$ sudo chmod +x /etc/network/if-pre-up.d/iptables$ sudo /etc/network/if-pre-up.d/iptables用 Fail2ban 處理潛在黑客

當(dāng)談到安全的時,F(xiàn)ail2ban 是我最喜歡的工具之一,它將監(jiān)控你的日志文件,并且可以臨時禁止那些正在濫用你資源,或者正在強制肆虐你的SSH連接,或者正在dos攻擊你web服務(wù)器的用戶。

Install Fail2ban

$ sudo apt-get install fail2ban[sudo] password for sjones:Reading package lists... DoneBuilding dependency treeReading state information... DoneThe following extra packages will be installed: gamin libgamin0 python-central python-gamin python-support whoisSuggested packages: mailxThe following NEW packages will be installed: fail2ban gamin libgamin0 python-central python-gamin python-support whois0 upgraded, 7 newly installed, 0 to remove and 2 not upgraded.Need to get 254 kB of archives.After this operation, 1,381 kB of additional disk space will be used.Do you want to continue [Y/n]? y...

雖然 Fail2ban 安裝一個默認(rèn)配置(/etc/fail2ban/jail.conf),但我們希望在 /etc/fail2ban/jail.local 寫配置,所以把它拷貝到那兒。

sudo cp /etc/fail2ban/jail.{conf,local}配置

把 ignoreip 行修改為你的ip,并且可以設(shè)置禁止惡意用戶的時間量(默認(rèn)是10分鐘)。你也將希望設(shè)置一個destemail,這里我通常輸入我自已的email地址,再在后面加上 ,fail2ban@blocklist.de 。BlockList.de 是一個跟蹤并且自動報告黑客IP的系統(tǒng)。

/etc/fail2ban/jail.local

[DEFAULT]# 'ignoreip' can be an IP address, a CIDR mask or a DNS hostignoreip = 127.0.0.1/8bantime = 600maxretry = 3# 'backend' specifies the backend used to get files modification. Available# options are 'gamin', 'polling' and 'auto'.# yoh: For some reason Debian shipped python-gamin didn’t work as expected# This issue left ToDo, so polling is default backend for nowbackend = auto## Destination email address used solely for the interpolations in# jail.{conf,local} configuration files.destemail = root@localhost,fail2ban@blocklist.de

這有一些其他的你想檢查的配置,盡管缺省配置已經(jīng)相當(dāng)不錯了,所以,快速瀏覽這些,直到你讀到Actions章節(jié)。

Actions

Actions 允許你對惡意行為作出反應(yīng),然而當(dāng)我們想要它禁止和發(fā)郵件的時候,默認(rèn)是禁用了 iptables。值得感謝的是,有一個預(yù)配置文件 action_wml,它恰恰是做這個的。

/etc/fail2ban/jail.local

# Choose default action. To change, just override value of ’action’ with the# interpolation to the chosen action shortcut (e.g. action_mw, action_mwl, etc) in jail.local# globally (section [DEFAULT]) or per specific sectionaction = %(action_mwl)sJails 監(jiān)控

為了讓Fail2ban工作,需要了解要監(jiān)控哪些東西。這些已在Jails部分的配置文件,并且這有一些預(yù)載入而未啟用的例子。既然到目前為止,你僅僅在服務(wù)器上啟用了SSH訪問,那我們就只啟用SSH和SSH-DDos 監(jiān)控,然而你還是會想給安裝在這臺服務(wù)器上的公共訪問服務(wù)增加新的監(jiān)控。

/etc/fail2ban/jail.local

[ssh]enabled = trueport = sshfilter = sshdlogpath = /var/log/auth.logmaxretry = 6[ssh-ddos]enabled = trueport = sshfilter = sshd-ddoslogpath = /var/log/auth.logmaxretry = 6應(yīng)用改變

既然我們已經(jīng)配置了Fail2ban,你將希望重新載入它,并且確保向iptables增加了合適的規(guī)則。

$ sudo service fail2ban restart * Restarting authentication failure monitor fail2ban ...done.$ sudo iptables -LChain INPUT (policy DROP)target prot opt source destinationfail2ban-ssh-ddos tcp -- anywhere anywhere multiport dports sshfail2ban-ssh tcp -- anywhere anywhere multiport dports ssh...Chain fail2ban-ssh (1 references)target prot opt source destinationRETURN all -- anywhere anywhereChain fail2ban-ssh-ddos (1 references)target prot opt source destinationRETURN all -- anywhere anywhere

在任何時間,你都可以使用sudo iptables -L 來列出你的規(guī)則,隨后列出所有當(dāng)前禁止的 IP。此時,F(xiàn)ail2ban正在處理兩個惡意的用戶。

Banned IPs

DROP all -- 204.50.33.22 anywhereDROP all -- 195.128.126.114 anywhere保持最新更新

你可能現(xiàn)在擁有一個已經(jīng)鎖定并且準(zhǔn)備投入使用的服務(wù)器,然而這并不是你安全之旅的終點。保持最新更新(并且總是首先在非產(chǎn)品環(huán)境下測試),總是關(guān)閉你不需要的端口,定期檢查你的日志,并且由內(nèi)而外了解你的服務(wù)器。

HackerNews 上的討論

我的這篇文章,在 HackerNews 上有一些很好的評論,如果你對不同觀點和更好的安全性感興趣的話,我建議你去看看。這篇文章目的是作為服務(wù)器安全的新手指南,在這篇文章結(jié)束的時候,并不意味著你的服務(wù)器是無懈可擊的。用本文來快速鎖定一個新服務(wù)器,在它之上為你特有的情況建立其他措施。你可能希望查詢 IPV6 安全,改變你的SSH端口(通過隱藏達到安全目的),安全內(nèi)核(SELinux和GRSecurity),跟蹤系統(tǒng)改變,并且如果你的服務(wù)器曾經(jīng)不安全或已經(jīng)在線相當(dāng)長時間了的話,全面檢查一番。一臺服務(wù)器有好幾百個入口點,并且每一個你安裝的應(yīng)用都帶來了額外的潛在漏洞,但是通過合適的工具,你可以免去困擾,直接去睡大覺了。

原文鏈接: Spenser Jones 翻譯: 伯樂在線 - 伯樂在線讀者

標(biāo)簽: Linux系統(tǒng)
相關(guān)文章:
主站蜘蛛池模板: 欧美在线黄 | 久久成人亚洲 | 国产成人亚洲精品久久 | 久久久久国产精品美女毛片 | 国产成人久久精品激情91 | 毛片免费全部播放一级 | 日本特黄特色免费大片 | 中文字幕亚洲精品 | 美女黄频免费观看 | 在线观看国内自拍 | 狠色狠狠色狠狠狠色综合久久 | 国产成人亚洲精品无广告 | 国产日产欧产精品精品推荐在线 | 免费五级在线观看日本片 | 一区二区三区网站在线免费线观看 | 久久99九九99九九精品 | 高清一区二区在线观看 | 日日摸天天摸狠狠摸视频 | 在线看片欧美 | 永久网站色视频在线观看免费 | 极品丝袜高跟91白沙发在线 | 欧美69色| 成人国产网站v片免费观看 成人国产午夜在线视频 | 一区二区三区成人 | 国产在线精品一区二区夜色 | 国产一级小视频 | 国产高清无专砖区2021 | 久草福利资源 | 免费国产a理论片 | 一级毛片不收费 | 久久精品国产一区二区三区 | 国产亚洲一区二区三区在线 | 国产午夜小视频 | 久久精品国产欧美日韩亚洲 | 欧美亚洲影院 | 中国精品自拍 | 国产成人免费视频精品一区二区 | 中国美女一级黄色片 | 国产三级小视频在线观看 | 亚洲国产欧美自拍 | 日韩一级a毛片欧美区 |