Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change environment variables send to server #371

Open
pendulm opened this issue Oct 9, 2020 · 2 comments
Open

How to change environment variables send to server #371

pendulm opened this issue Oct 9, 2020 · 2 comments

Comments

@pendulm
Copy link

pendulm commented Oct 9, 2020

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
Copy link

I would like this as well, specifically for this option:
SetEnv: "TERM=xterm"

@stillwaxin
Copy link

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)
                }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants