大网数据广告活动
服务器运维问答

Setting a variable for a given SSH host

· 52CE 我爱测

In ssh_config , one can choose to export some environment variables to the host using SendEnv . Is there also a way to force a given value for this variable, per host? For example, would it be possible to export variable $FOO wit…

问题原文

原帖链接 · raphink · CC BY-SA 3.0

In ssh_config, one can choose to export some environment variables to the host using SendEnv.

Is there also a way to force a given value for this variable, per host? For example, would it be possible to export variable $FOO with value bar only when connecting to host example.com?

社区高分解答

原帖链接 · kenorb · CC BY-SA 4.0

You can give a specific value by using SetEnv in your ~/.ssh/config, e.g.

Host *
  SetEnv FOO=bar

As per man ssh_config:

Directly specify one or more environment variables and their contents to be sent to the server. Similarly to SendEnv, the server must be prepared to accept the environment variable.

Assuming your server got the following line in /etc/ssh/sshd_config:

AcceptEnv LANG LC_* FOO

Check also: man ssh_config and man sshd_config.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-02-27)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。