[服務架設][系統][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」,觀察看看錯誤訊息,以知道是上述的哪一種問題。

[服務架設][系統][PHP] Fatal error: Call to undefined function exif_read_data()

[服務架設][系統][PHP] Fatal error: Call to undefined function exif_read_data()

If you got a ‘Fatal error: Call to undefined function exif_read_data(): …..’ error during executing your PHP program, you may:

case1: (Using PHP in Microsoft Windows environment)

Edit your php.ini and move the ‘extension=php_mbstring.dll’ prior to ‘extension=php_exif.dll’. Re-start your web-server (apache).

case2: (Linux)

Re-compile and re-install your PHP with configuration parameters –enable-exif and –enable-mbstring (compiling both exif and mbstring statically, don’t use mbstring compiled as a DSO module).

Reference:
[1] http://uk2.php.net/exif_read_data

如何移除並取消 MySQL 的 binary log 檔案

o MySQL 的 binary log 檔案佔了磁碟很多的空間

在例如 /var/lib/mysql/ 目錄可能會發現不少 MySQL 的 binary log 檔案:
-rw-rw—- 1 mysql mysql 29662 Aug 6 23:53 mysql-bin.000001
-rw-rw—- 1 mysql mysql 1055243 Aug 6 23:53 mysql-bin.000002
-rw-rw—- 1 mysql mysql 1073790447 Aug 7 00:42 mysql-bin.000003
-rw-rw—- 1 mysql mysql 1074547174 Aug 7 01:30 mysql-bin.000004
-rw-rw—- 1 mysql mysql 1074351847 Aug 7 01:54 mysql-bin.000005
-rw-rw—- 1 mysql mysql 1074535688 Aug 7 02:01 mysql-bin.000006
-rw-rw—- 1 mysql mysql 1074495922 Aug 7 02:07 mysql-bin.000007
-rw-rw—- 1 mysql mysql 1074497579 Aug 7 02:13 mysql-bin.000008
-rw-rw—- 1 mysql mysql 147849819 Aug 7 17:21 mysql-bin.000009

這些檔案可以佔住了磁碟很多的空間。

這一篇要說明如何正規方式移除這些檔案,並改寫 my.cnf 設定組態不去記錄這些二進位日誌檔案。 Continue reading “如何移除並取消 MySQL 的 binary log 檔案”

PHP中如何對輸出的資源檔案使用 Last-Modified 或 ETag

說明:
網頁頁面本身和頁面中的圖片、外部 CSS 檔案、外部 JavaScript 檔案等資源檔案最好在輸出給 client 端 (一般是指瀏覽器) 時明確地在 HTTP 回應的標頭中寫明 Last-Modified 或 ETag 這類快取驗證資訊,讓 client 端可以明確地知道手邊的快取檔案是否已經過期、是否已經改變而需要重新抓取。不需要抓取者則直接使用快取資料以加速網頁的呈現速度。 Last-Modified 和 ETag 是從 HTTP 1.0 到 HTTP 1.1 後才有的新 HTTP 標頭欄位。
這一篇文章是要說明在 PHP 語言中如何對輸出的資源檔案使用 Last-Modified 或 ETag。 Continue reading “PHP中如何對輸出的資源檔案使用 Last-Modified 或 ETag”

隨記: MySQL 預設的字集是不分大小寫,所以…

o MySQL 預設的字集是不分大小寫 (not case sensitive)
. 所以 jjdai 和 JJDai 不可能同時加到一被設定成 primary key 的欄位。
. 要故意做大小寫比較的話可用:
SELECT * FROM ub WHERE nickname LIKE ‘JJDai’ COLLATE big5_bin;
SELECT * FROM ub WHERE nickname LIKE binary ‘jjdai’ LIMIT 0 , 30
. 將字集設定成 binary 即可區分出大小寫。