我希望在 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 中有此文件,则会在其中显示一条消息。