gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:36:25 24 4
gpt4 key购买 nike

我想根据 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com