How to change environment variables send to server
pendulm opened this issue · 2 comments
pendulm commented
ssh_config has a option SetEnv
to modify environment variable before connect.
my config is something like this
defaults:
UserKnownHostsFile: /dev/null
StrictHostKeyChecking: no
LogLevel: QUIET
ControlMaster: auto
ControlPath: ~/.ssh/controlmasters/%C.sock
ControlPersist: 600
SetEnv: LANG en_US.UTF-8
but it dosn't works. I found there isn't SetEnv
option in pkg/config/host.go.
Is there any way to configure this?
stillwaxin commented
I would like this as well, specifically for this option:
SetEnv: "TERM=xterm"
stillwaxin commented
This looks to do it:
diff --git a/pkg/config/host.go b/pkg/config/host.go
index 8852decb..72d440fd 100644
--- a/pkg/config/host.go
+++ b/pkg/config/host.go
@@ -94,6 +94,7 @@ type Host struct {
RevokedHostKeys string `yaml:"revokedhostkeys,omitempty,flow" json:"RevokedHostKeys,omitempty"`
RhostsRSAAuthentication string `yaml:"rhostsrsaauthentication,omitempty,flow" json:"RhostsRSAAuthentication,omitempty"`
RSAAuthentication string `yaml:"rsaauthentication,omitempty,flow" json:"RSAAuthentication,omitempty"`
+ SetEnv string `yaml:"setenv,omitempty,flow" json:"SetEnv,omitempty"`
SendEnv composeyaml.Stringorslice `yaml:"sendenv,omitempty,flow" json:"SendEnv,omitempty"`
ServerAliveCountMax int `yaml:"serveralivecountmax,omitempty,flow" json:"ServerAliveCountMax,omitempty"`
ServerAliveInterval int `yaml:"serveraliveinterval,omitempty,flow" json:"ServerAliveInterval,omitempty"`
@@ -476,6 +477,9 @@ func (h *Host) Options() OptionsList {
if h.RSAAuthentication != "" {
options = append(options, Option{Name: "RSAAuthentication", Value: h.RSAAuthentication})
}
+ if h.SetEnv != "" {
+ options = append(options, Option{Name: "SetEnv", Value: h.SetEnv})
+ }
for _, entry := range h.SendEnv {
options = append(options, Option{Name: "SendEnv", Value: entry})
}
@@ -977,6 +981,11 @@ func (h *Host) ApplyDefaults(defaults *Host) {
}
h.RSAAuthentication = utils.ExpandField(h.RSAAuthentication)
+ if h.SetEnv == "" {
+ h.SetEnv = defaults.SetEnv
+ }
+ h.SetEnv = utils.ExpandField(h.SetEnv)
+
if len(h.SendEnv) == 0 {
h.SendEnv = defaults.SendEnv
}
@@ -1391,6 +1400,9 @@ func (h *Host) WriteSSHConfigTo(w io.Writer) error {
if h.RSAAuthentication != "" {
_, _ = fmt.Fprintf(w, " RSAAuthentication %s\n", h.RSAAuthentication)
}
+ if h.SetEnv != "" {
+ _, _ = fmt.Fprintf(w, " SetEnv %s\n", h.SetEnv)
+ }
for _, entry := range h.SendEnv {
_, _ = fmt.Fprintf(w, " SendEnv %s\n", entry)
}