我想通过SSH初始login时运行脚本,该脚本向用户login显示一些有用的信息。但是,我不希望此脚本在每个login中都运行。 也就是说,如果用户在login后启动screen ,则不应该再次运行自定义的“motd”(也不会创build后续屏幕)。 特别要注意的是,脚本将需要用户的最终ENV才能正常工作。 这可能吗? 如果是这样,我该如何去做呢?
在Match块中不允许使用PrintMotd指令。 如果您只想在login时显示特定用户的一些有用信息,那么Banner指令可以执行此操作:
Match User <special_user> Banner /etc/ssh/banner.txt
正如在这个ALE线程中所概述的,为了这个目的,可以使用用户的${HOME}/.ssh/rc文件。 SSHRC部分的联机帮助页明确指出, 不应通过此rc文件写入标准输出,但以下脚本将起作用:
#!/bin/bash if [ ! -t 1 ]; then # This is scp, sftp, a port forward, or something else exit fi # Use stderr like the manpage tells you to do exec 1>&2 echo -e "This is output to stdout via the ${HOME}/.ssh/rc file.\n"