linux - 有没有办法在任何 SSH 连接/断开连接上运行脚本?

标签 linux ssh

我想根据 ssh 连接的 HOSTNAME 更改我的终端颜色。

我知道如何修改终端,但我如何使用 ssh 来添加 Hook ?

我可以用 shell 函数包装 ssh 命令,或者替换二进制文件,但它被其他应用程序用作依赖项,我宁愿不这样做。

最佳答案

当连接到远程服务器时,您可以使用 OpenSSHLocalCommand 功能:

 LocalCommand
         Specifies a command to execute on the local machine after successfully connecting to the server.  The command string extends to the end of the line, and is executed
         with the user's shell.  The following escape character substitutions will be performed: ‘%d’ (local user's home directory), ‘%h’ (remote host name), ‘%l’ (local host
         name), ‘%n’ (host name as provided on the command line), ‘%p’ (remote port), ‘%r’ (remote user name) or ‘%u’ (local user name).

         The command is run synchronously and does not have access to the session of the ssh(1) that spawned it.  It should not be used for interactive commands.

         This directive is ignored unless PermitLocalCommand has been enabled.

除了编写 ssh 包装器之外,在结束与远程服务器的连接时可能没有简单的方法来执行命令。

关于linux - 有没有办法在任何 SSH 连接/断开连接上运行脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30105852/

相关文章:

linux - 如何在 GCP 上的 Ubuntu 18.04 上的/etc/ssh/sshd_config 中添加 MAC 和 KEX 算法

python - 有没有办法通过 ssh 将 Python psutil 模块发送到没有互联网访问权限的计算机?

ssh - 无法使用 key 对登录 Amazon EC2 实例

linux - 我的容器找不到 package.json 来在 docker-compose 上执行 npm install

linux - 如何删除具有特定名称的所有子目录

linux - ssh/scp - 权限被拒绝(公钥、密码)

linux - 运行命令多个linux服务器

linux - 将 grep 的结果作为命令执行

c# - 我如何通过单声道从 CPython 调用 C#?

C++/C : Move Directory to Another Location