environment variables to init

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!
 
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
 
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)?
 
Back
Top