SSH登入慢問題解決
簡單小記
換了騰訊雲國內的主機後,最近發現每次 SSH 上去都很艱難,一開始使用 fabric 自動部署部落格上去還行,到後來直接超時。於是簡單搜尋了下,發現問題所在。
從搜尋引擎上能得到的中文相關的部落格就是兩點:
UseDNS no GSSAPIAuthentication no
從結果來看大家都是相互參考,很難確定是否解決了問題。對我來說這些方法沒用,依然登入緩慢。探索中發現可能因為 btmp 檔案過大導致。
見:https://serverfault.com/a/855071/292356
於是查了下關於 btmp 找到這個問題:
https://serverfault.com/questions/119299/my-var-log-btmp-file-is-huge-what-should-i-do, 摘部分答案:
This means people are trying to brute-force your passwords (common on any public-facing server). It shouldn't cause any harm to clear out this file. One way to reduce this is to change the port for SSH from 22 to something arbitrary. For some additional security, DenyHosts can block login attempts after a certain number of failures. I'd highly recommend installing and configuring it.
所以解決方案就是:
echo '' > /var/log/btmp
主機的安全性
通過看上面的答案能瞭解到,總是有人在嘗試登陸你的主機。這個情況似乎比之前用的香港主機和國外主機要嚴重。
所以拿到新主機之後,很有必要對常用埠做一些調整,避免有人對你做暴力破解嘗試。初始化的網路安全組策略也是需要關注的。
- from the5fire.com