1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

environment variables to init

Discussion in 'Userland Programming and Scripting' started by izotov, Jul 9, 2010.

  1. izotov

    izotov New Member

    Messages:
    118
    Thanks Received:
    6
    Hi,
    I have configured init to keep alive ssh tunnels specifying some ssh commands in /etc/ttys. (For details see init(8).) It worked perfectly.

    Now I must use passphrase protected private keys for ssh. To be able to use the key without typing in the passphrase all the time (which is impossible for an automated ssh tunnel) I use the ssh-agent.

    Now my problem is that ssh communicates with ssh-agent through a socket stored in the SSH_AUTH_SOCK environment variable that is totally unknown by the init. How could I pass this variable to init?

    Specifying it in /etc/profile and /etc/csh.login does not work.
    Tried to create a script setting and exporting the variable and make init to run it with init_script loader variable does not work.

    The only way I could make it work was to specify something similar to
    Code:
    sh -c 'SSH_AUTH_SOCK=/tmp/ssh-init/agent ssh user@host'

    instead of only
    Code:
    ssh user@host
    in /etc/ttys.
    This is problematic as it starts two processes instead of only one and init monitors the sh process instead of the ssh and can produce misleading error messages. Not the best...

    So the question is again: how could I pass some environment variables to init?

    Thanks!
     
  2. Alt

    Alt New Member

    Messages:
    726
    Thanks Received:
    79
    You can make an sh script that sets env variable and then exec(1) your ssh
    Or may write
    Code:
    sh -c 'SSH_AUTH_SOCK=/tmp/ssh-init/agent exec ssh user@host'
    I think it should work
     
  3. izotov

    izotov New Member

    Messages:
    118
    Thanks Received:
    6
    Yes, thanks for this tip. This solves my problem with the processes.

    But the question is still alive: can I set environment variables for init (or in more general for processes already running)?