# environment variables to init



## izotov (Jul 9, 2010)

Hi,
I have configured [font=courier]init[/font] to keep alive [font=courier]ssh[/font] tunnels specifying some [font=courier]ssh[/font] commands in /etc/ttys. (For details see init(8).) It worked perfectly.

Now I must use passphrase protected private keys for [font=courier]ssh[/font]. 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 [font=courier]ssh-agent[/font].

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

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

The only way I could make it work was to specify something similar to

```
sh -c 'SSH_AUTH_SOCK=/tmp/ssh-init/agent ssh user@host'
```
instead of only

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

So the question is again: how could I pass some environment variables to [font=courier]init[/font]?

Thanks!


----------



## Alt (Jul 9, 2010)

You can make an sh script that sets env variable and then exec(1) your ssh
Or may write
	
	



```
sh -c 'SSH_AUTH_SOCK=/tmp/ssh-init/agent exec ssh user@host'
```
I think it should work


----------



## izotov (Jul 9, 2010)

Yes, thanks for this tip. This solves my problem with the processes.

But the question is still alive: can I set environment variables for [font="Courier New"]init[/font] (or in more general for processes already running)?


----------

