29 linux ssh terminal environment-variables
在我的本地终端上,我有 TERM=konsole-256color,但并非所有我连接的远程机器都有这个定义。
是否可以让 ssh 在远程机器上更改 TERM?无需更改远程计算机上的 .bash* 脚本,只需更改本地桌面上的配置?
Joh*_*han 16
我已将以下别名添加到我的 .bashrc 文件中。它使用 OG 的答案,但将其包装在别名中。奇迹般有效 ;)
# Force xterm-color on ssh sessions
alias ssh='TERM=xterm-color ssh'
Run Code Online (Sandbox Code Playgroud)
dse*_*vec 16
2021 年 6 月 4 日,“允许 ssh_config SetEnv 覆盖 $TERM”已提交给 openssh-portable,这听起来像是可以让您在指令中进行SetEnv TERM设置。(或者大概是,一旦发布了此补丁,它就会让您这样做。)~/.ssh/configHost
人 ssh:
ssh reads ~/.ssh/environment, and adds lines of the format
“VARNAME=value” to the environment if the file exists and users are
allowed to change their environment. For more information, see the
PermitUserEnvironment option in sshd_config(5).
Run Code Online (Sandbox Code Playgroud)
编辑:
老鼠,我希望它可以在本地,但是,如果有意愿,就有办法。人 ssh_conf:
SendEnv
Specifies what variables from the local environ(7) should be sent
to the server. Note that environment passing is only supported
for protocol 2. The server must also support it, and the server
must be configured to accept these environment variables. Refer
to AcceptEnv in sshd_config(5) for how to configure the server.
Variables are specified by name, which may contain wildcard char-
acters. Multiple environment variables may be separated by
whitespace or spread across multiple SendEnv directives. The
default is not to send any environment variables.
Run Code Online (Sandbox Code Playgroud)
根据接收端 sshd 的配置,这可能满足也可能不满足“无远程文件修改”的要求。
TERM=vt100 ssh some.host.name
Run Code Online (Sandbox Code Playgroud)
在远程,执行echo $TERM。
这是我刚刚拼凑起来的快速而肮脏的解决方案。我更喜欢更好的东西。我想我可以改用 shell 脚本。调整TERM值留给读者作为练习。
# To move into a separate plugin...
function ssh {
if [[ "${TERM}" = screen* || konsole* ]]; then
env TERM=screen ssh "$@"
else
ssh "$@"
fi
}
Run Code Online (Sandbox Code Playgroud)
理想情况下,它会做一些事情,比如检查另一端的 TERM,使用这些ControlPersist东西来防止多个连接的长时间延迟。
| 归档时间: |
|
| 查看次数: |
23248 次 |
| 最近记录: |