Answers:
您可以通过将以下参数添加到配置文件(/ etc / ssh / sshd_config)中来实现。
ForceCommand Forces the execution of the command specified by ForceCommand, ignoring any command supplied by the client and ~/.ssh/rc if present. The command is invoked by using the user's login shell with the -c option. This applies to shell, command, or subsystem execution. It is most useful inside a Match block. The command originally supplied by the client is available in the SSH_ORIGINAL_COMMAND environment variable. Specifying a command of “internal-sftp” will force the use of an in-process sftp server that requires no support files when used with ChrootDirectory.
另一种选择是按每个用户使用.ssh / rc文件。
要使用ForceCommand方法,只需ForceCommand /usr/bin/ownscript
在文件底部添加/etc/ssh/sshd_config
(在服务器上)。
该脚本如下所示:
#!/bin/bash
#Script file for ssh
#
#put your commands here
echo "test" > /tmp/test.txt
#
#exit by calling a shell to open for the ssh session
/bin/bash
别忘了修改脚本 sudo chmod +x /usr/bin/ownscript
要在登录期间执行脚本,请将其添加为/ etc / profile脚本中的调用。这不仅对ssh登录,而且对每次登录都执行。