ssh 啟動登入工作階段後列印文件內容?

ssh 啟動登入工作階段後列印文件內容?

我希望在 ssh 登入 unix 系統時列印文件的內容(如果該文件存在)。 MOTD 已列印以及設定的橫幅sshd_config。我還想列印另一個文件。我該怎麼做呢?我正在嘗試使用 rc 文件,但尚未使其正常工作,我可以將文件的內容設置為環境中的變數並通過 rc 列印它,您有何建議?

答案1

您可以使用部隊指揮部(sshd 配置選項)

強制執行由 ForceCommand 指定的命令,忽略客戶端和 ~/.ssh/rc(如果存在)提供的任何命令。該命令是透過使用使用者的登入 shell 和 -c 選項來呼叫的。這適用於 shell、命令或子系統執行。它在 Match 區塊內最有用。用戶端最初提供的命令可在 SSH_ORIGINAL_COMMAND 環境變數中找到。指定「internal-sftp」指令將強制使用進程內 sftp 伺服器,該伺服器在與 ChrootDirectory 一起使用時不需要支援檔案。預設值為“無”。

只需使其指向將顯示訊息的包裝器腳本,然後執行 shell 即可。

sshd_config 範例 (OpenSSH_7.2p2):

Port 22
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
UsePrivilegeSeparation yes

KeyRegenerationInterval 3600
ServerKeyBits 1024

SyslogFacility AUTH
LogLevel INFO

LoginGraceTime 120
PermitRootLogin prohibit-password
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes

IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no

PermitEmptyPasswords no

ChallengeResponseAuthentication no

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes

AcceptEnv LANG LC_*

Subsystem sftp /usr/lib/openssh/sftp-server

UsePAM yes

ForceCommand /usr/local/bin/ssh-wrapper

/usr/local/bin/ssh-wrapper

#!/bin/sh
[ -r "/etc/ssh_banner" ] && cat /etc/ssh_banner
CMD=${SSH_ORIGINAL_COMMAND:+-c $SSH_ORIGINAL_COMMAND} 
exec $SHELL -l $CMD

如果 /etc/ssh_banner 中有此文件,則會在其中顯示一則訊息。

相關內容