SSH session.Setenv usage

1.490 de afișări
Accesați primul mesaj necitit

dan.so...@gmail.com

necitită,
18 iun. 2014, 22:04:3118.06.2014
– golan...@googlegroups.com
Hi there,

I've been playing with Go's ssh package recently and trying to figure out how to

Documentation states that each assigned env variable will be passed to the command (Run, Start, etc). 
But when i call the method it fails with error: "ssh: setenv failed"

Can someone provide an example how to use this method?

Thanks!

Gonzalo Paniagua Javier

necitită,
19 iun. 2014, 10:58:0219.06.2014
– dan.so...@gmail.com, golan...@googlegroups.com
Hi Dan,

Your sshd has a configuration line like:

  AcceptEnv LANG LC_*

If you try to set LANG or any variable that begins with LC_, the call to Setenv will succeed.

-Gonzalo


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dan Sosedoff

necitită,
19 iun. 2014, 10:59:0019.06.2014
– Gonzalo Paniagua Javier, golan...@googlegroups.com
Hi Gonzalo,

So its not worth using since it requires server-side configuration? One other
way i was exploring is to prepend any command with a string that contains
all needed environment variables. Rough example:

func run(cmd string) {
  vars := "FOO=bar BAR=foo"
  newCmd := vars + " " + cmd
  
  session.Run(newCmd)
}

Is there a better way to do this ?

Cobe Gu

necitită,
16 nov. 2021, 00:19:0016.11.2021
– golang-nuts
Hi Gonzalo,

i used LC_* to set env on remote server, i still stuck in failed situation.  could please help to have a check?

sshcli-setenv-error.png

Brian Candler

necitită,
16 nov. 2021, 05:13:3016.11.2021
– golang-nuts
You resurrected a 7 year old thread for this! :-)

The first thing I suggest you do is to print the value of "err" and you may get back some information about why it failed.  (Same for everywhere else that err != nil)

Cobe Gu

necitită,
16 nov. 2021, 22:37:5516.11.2021
– golang-nuts
Thanks for your reply.

that's a trick thing to print all embedded errors.

After digging more,  Setenv function is related to the configuration 'AcceptEnv' of remote server's sshd,   if variable name is not accepted by 'AcceptEnv', it will throw out this unclear error 'Failed to set env'

Brian Candler

necitită,
17 nov. 2021, 03:23:0817.11.2021
– golang-nuts
No: the "unclear" message "Failed to set env" is an error message *you* generated.  You ignored the content of the "err" variable (which could have contained a detailed description of the error), and replaced it with your own bland text.

Try replacing it with something like this (untested):

logger.Error.Fatalf("Failed to set env: %v", err)

Cobe Gu

necitită,
18 nov. 2021, 21:59:2218.11.2021
– golang-nuts
Hi Brain,

Nice to have your reply,

yes, my fault, wrong paste. but still hard to see the root reason with a few error contents.

as my understanding, Setenv has strong dependency on remote sshd config - AcceptEnv,  if need to pass LC_TEST to remote, it must be configured in remote to accept it first, that's not nice. 
Răspundeți tuturor
Răspundeți autorului
Redirecționați
0 mesaje noi