[服務架設][系統][sshd] ssh_exchange_identification: Connection closed by remote host 解決

ssh_exchange_identification: Connection closed by remote host

以下討論 ssh client 連到 sshd 伺服器時遇到「ssh_exchange_identification: Connection closed by remote host」訊息的可能解決方法。

問題:

使用 ssh client 連到某台目標主機時可能會遇到以下錯誤訊息:

[aa@example ~]$ ssh -v aabbcc@1.2.3.4
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 1.2.3.4 [1.2.3.4] port 22.
debug1: Connection established.
debug1: identity file /home/aa/.ssh/identity type -1
debug1: identity file /home/aa/.ssh/identity-cert type -1
debug1: identity file /home/aa/.ssh/id_rsa type -1
debug1: identity file /home/aa/.ssh/id_rsa-cert type -1
debug1: identity file /home/aa/.ssh/id_dsa type -1
debug1: identity file /home/aa/.ssh/id_dsa-cert type -1
debug1: identity file /home/aa/.ssh/id_ecdsa type -1
debug1: identity file /home/aa/.ssh/id_ecdsa-cert type -1
ssh_exchange_identification: Connection closed by remote host
[aa@example ~]$

可能解法:

1. 可能被 hosts.allow / hosts.deny 擋了

檢查一下 /etc/hosts.deny 和 /etc/hosts.allow,用 root 權限的帳號去在 hosts.allow 中寫上「sshd: ALL」如下 :

root@example # grep sshd /etc/hosts.allow
sshd: ALL

2. 可能 sshd 所在的伺服器最近有更新 glibc 或 openssl libs

去嘗試重新跑一下 sshd,然後重試看看。

3. ~/.ssh/known_hosts

刪除 ~/.ssh/known_hosts 目標伺服器對應的那一行,然後重試看看。

4. 伺服器過於忙碌

在 sshd 伺服器端的 /etc/ssh/sshd_config 內將 MaxStartups 調大,如下:

# 舊樣式
MaxStartups 20
# 新樣式
MaxStartups 10:20:30

然後重跑 sshd。

5. 用 Snology NAS 的話,確認沒有被「自動封鎖」機制擋了

可在 Snology DSM 的 web GUI 登入後,開啟控制台應用程式,在 安全性 >> 帳號 >> 自動封鎖,找到「允許/封鎖 清單」按鈕,然後去看看有沒有被封鎖了。有的話則將想要解除封鎖的 IP 刪除即可。

6. 確認周邊的網路裝置,例如 router, switch, WiFi AP  等等的組態設定沒有去擋 ssh 連線。

除錯:

可在伺服器端用「sshd -d -p 2222」在 port 2222 跑起 debug 用的 sshd 。(不會和已經跑起的 port 22 的 sshd 衝突)

然後再用 ssh client 連連看「ssh -v -p 2222 aabbcc@1.2.3.4」,觀察看看錯誤訊息,以知道是上述的哪一種問題。

如何安裝 Mod_Security 和 Apache 網頁伺服器專用的 Mod_Evasive ?

說明
Mod_Security : Mod_Security 是一個網頁應用層的防火牆 (Web Application Firewall, WAF) 與網頁應用層的入侵偵測及防範系統。用來保護並監視即時的 HTTP 流量。

Mod_Evasive : 幫 Apache 網頁伺服器裝設 mod_evasive20 以免被 “暴力性攻擊”、DOS 或 DDOS。它也會在流量不正常時透過 email 或系統 log 送出異常報告資訊。 Continue reading “如何安裝 Mod_Security 和 Apache 網頁伺服器專用的 Mod_Evasive ?”

新版 PHP 預設啟用 APC 模組後造成 class 找不到的錯誤

假設環境:
PHP 5.3.20
Apache/2.2.23 (Unix)

aaa.php 檔案裡面有 AAA class,bbb.php 檔案裡面有 BBB class,bbb.php 中 include aaa.php。BBB class 的 b_func() 函式裡面用到 AAA class (即:$oA = new AAA())。

說明:
APC (Alternative PHP Cache) 是 PHP 的一個延伸模組套件,是 PHP 的另一種快取 (cache) 機制,可以直接拿既有的 OPCODE 執行、免去每次都直譯 php 程式產生 OPCODE 來跑,進而加快 php 程式的執行速度,號稱可以提昇 20% 到 30% 的速度。
筆者將手邊的 PHP 程式轉移到新版 PHP 環境下執行時,PHP 卻拋出「class 找不到」的錯誤訊息,類似以下 log 訊息:

[Tue Jan 29 04:04:46 2013] [error] [client 123.234.171.235] PHP Fatal error: Class ‘AAA’ not found in /sites/prj1/bbb.php on line 32

Continue reading “新版 PHP 預設啟用 APC 模組後造成 class 找不到的錯誤”

[LINUX]安裝 PHP 時出現undefined reference to `libiconv_open’ 之類的錯誤訊息

[服務架設][系統][LINUX]安裝 PHP 時出現undefined reference to `libiconv_open’ 之類的錯誤訊息

安裝環境: Linux Fedora Core 3 上安裝 php-5.2.0

在安裝 PHP 到系統中時要是發生「undefined reference to `libiconv_open’」之類的錯誤訊息,那表示在「./configure 」沒抓好一些環境變數值。錯誤發生點在建立「-o sapi/cli/php」時出錯,沒給到要 link 的 iconv 函式庫參數。

快速的解法是: Continue reading “[LINUX]安裝 PHP 時出現undefined reference to `libiconv_open’ 之類的錯誤訊息”