我使用一個由 Solaris 10 伺服器組成的伺服器場,在顯示橫幅/motd 方面存在一些不一致的行為。
這次,我嘗試從一台伺服器到另一台伺服器進行 scp。在某些伺服器之間我沒有收到橫幅,而有些則收到。
我已經嘗試過:
- 建立 .hushlogin 文件
- scp-q
- scp -o LogLevel=錯誤
- /etc/ssh/sshd_config 中沒有 PrintMotd
- /etc/ssh/ssh_config 中的日誌等級 QUIET
我在使用 ssh 時已經沒有收到橫幅,但帶有 scp 的橫幅仍然存在於某些伺服器中,我想找到一種方法將其關閉。
我沒有管理員權限,但可以要求更改特定配置。
scp 會話範例:
usera@server20$ scp a.sh server43:/tmp
###################################################################
# This system is for the use of authorized users only. #
# Individuals using this computer system without authority, or in #
# excess of their authority, are subject to having all of their #
# activities on this system monitored and recorded by system #
# personnel. #
# #
# Anyone using this system expressly consents to such monitoring #
# and is advised that if such monitoring reveals possible #
# evidence of criminal activity, system personnel may provide the #
# evidence of such monitoring to law enforcement officials. #
###################################################################
WARNING: Access to this computer system is limited to authorised users only.
Unauthorised users may be subject to prosecution under the Crimes
Act or State legislation.
a.sh 100% |***********************************************************************************************************| 602 00:00
usera@server20$
來自場中伺服器的 ssh 會話範例:
usera@server20$ ssh server43
LI002: usera is allowed 2 concurrent logins
Last login: Tue Jun 16 2015 17:30:05 from pts/2
server43:usera>
來自場外的 ssh 會話範例:
login as: usera
###################################################################
# This system is for the use of authorized users only. #
# Individuals using this computer system without authority, or in #
# excess of their authority, are subject to having all of their #
# activities on this system monitored and recorded by system #
# personnel. #
# #
# Anyone using this system expressly consents to such monitoring #
# and is advised that if such monitoring reveals possible #
# evidence of criminal activity, system personnel may provide the #
# evidence of such monitoring to law enforcement officials. #
###################################################################
WARNING: Access to this computer system is limited to authorised users only.
Unauthorised users may be subject to prosecution under the Crimes
Act or State legislation.
Using keyboard-interactive authentication.
Password:
LI002: usera is allowed 2 concurrent logins
Last login: Tue Jun 16 2015 18:40:41 from pts/1
server43:usera>
答案1
您已經指出該 SSH 伺服器也按照您想要的sftp
方法執行常規 SSH shell 會話。另外,以下答案適用於可能的最舊的 OpenSSH 版本:(v4.0.0p1
除非另有說明)。此答案適用於最新的 Solaris 10 和 11,因為它們使用 OpenSSH v6.6p1,REV=2014.03.20
我的解決方案提供常規 SSH 和scp
/ sftp
。
設定
訣竅是Match User sftp
在 SSH 伺服器配置中使用以下幾個設定:
Banner
PrintMotd
Banner
Banner
設定是在允許身份驗證之前將指定檔案的內容傳送到遠端使用者的檔案名稱。如果參數為,none
則不顯示橫幅。預設情況下,不顯示橫幅。
根據OP,您Banner yes
的文件中可能有某個地方,這沒關係,因為我們可以限制該行為而不修改該配置行(稍後會詳細介紹)。
PrintMotd
PrintMotd
指定當使用者互動登入時是否sshd(8)
應該列印。 /etc/motd
(在某些系統上,它也由 shell、/etc/profile 或等效程式列印。)預設值為yes
.
PrintMotd <anything>
您的設定檔中可能沒有,sshd_config
因此預設設定是始終顯示當天的訊息。
設定區塊
為了解決您的問題,我們假設此 SFTP/SCP 活動的使用者名稱是sftp
。
sftp
用於使任何和所有用戶看不到任何橫幅或任何每日訊息 (MotD)的貼上和使用的設定區塊是:
Match User sftp
Banner none
PrintMotd no
設定的位置
我們上面的設定區塊可能會進入以下檔案名稱之一:
/etc/ssh/sshd_config
(使用 OpenSSH v7.3 或更早版本的舊發行版,最高可達macOS
12 蒙特利版本)/etc/ssh/sshd_config.d/900-custom-match-sftp.conf
(自 2016 年後的 OpenSSH v7.3 起)
罕見:雖然不太可能(除非系統管理很複雜或其是企業環境),但上述設定區塊必須在任何、或區塊Match user sftp
之前放置和讀取。Match all
Match canonical
Match final
注意:多檔案 SSH 伺服器設定/etc/ssh/sshd_config.d
以 ASCII 順序載入。在多檔案設定方法中,通常使用 2 或 3 位數字作為起始檔名,以確保其正確的讀取順序。我們的Match user
設定區塊需要放置在任何Match all
、Match canonical
、 或之前Match final
,因此我們的數字將位於它們之前970-*
或97-*
假設9[7-9]-*
和被其他//設定區塊9[7-9][0-9]-*
佔用。canonical
final
all
重新載入/重新啟動 SSH 伺服器
然後重新載入/重新啟動 SSH 伺服器。
下次scp
或sftp
登入嘗試將不再顯示當天的任何橫幅或訊息。
答案2
您是否嘗試過此選項:-o LogLevel=quiet