脚本在SSH连接上执行

有一个远程主机,我希望每次通过ssh连接到它时运行一个特定的脚本。 我应该在哪里把文件自动运行?

从ssh手册页:

~/.ssh/rc Commands in this file are executed by ssh when the user logs in, just before the user's shell (or command) is started. See the sshd(8) manual page for more information. 

将它添加到你正在连接的密钥的授权密钥文件(设置一个私人密钥authentication),并使用该文件中的命令字段,更多信息做一个“人授权的钥匙”,看看你还能build立。

在远程服务器?

ssh my-remote-host / usr / local / bin / my-remote-script

您可以限制ssh只使用特定的密钥运行一个命令,从而限制密钥的使用。 有关示例,请参见http://pkeck.myweb.uga.edu/ssh/