解決SSH登錄太慢的問題

簡單小記

換了騰訊雲國內的主機後,最近發現每次 SSH 上去都很艱難,一開始使用 fabric 自動部署博客上去還行,到後來直接超時。於是簡單搜索了下,發現問題所在。

從搜索引擎上能得到的中文相關的博客就是兩點:

  • 關閉 UseDNS —— UseDNS no
  • 關閉 GSSAPIAuthentication —— 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

主機的安全性

通過看上面的答案能瞭解到,總是有人在嘗試登陸你的主機。這個情況似乎比之前用的香港主機和國外主機要嚴重。

所以拿到新主機之後,很有必要對常用端口做一些調整,避免有人對你做暴力破解嘗試。初始化的網絡安全組策略也是需要關注的。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章