I got an .xinitrc file with the following line:

# it will start my window manager
ssh-agent dwm

After that I got an ssh-agent process, but environment variables like $SSH_AGENT_PID and $SSH_AUTH_SOCK does not exists when I start a terminal from dwm. Any ideas why?

I wish there was only one ssh-agent process. Each call to ssh-add should connect to the agent that started dwm.

2 Answers 2


ssh-agent outputs the environment variables you need to have to connect to it, by calling eval you immediately load those variables into your environment.

Why ssh-agent can't do that itself?

In Unix, a process can only modify its own environment variables, and pass them on to children. It can not modify its parent process' environment because the system won't allow it. This is pretty basic security design.

In relation to it read this.

Therefore, leave your `.xinitrc as:

eval $(ssh-agent) &
exec dwm
  • You should check man ssh-agent. The agent can act as a wrapper to other programs and exports the right variables to them, no need for eval in that case. If you don't believe me, make sure you don't have an agent running and then run ssh-agent bash. You'll find that the bash session has a running agent.
    – cryptarch
    Jan 13 at 3:21

In your .xinitrc, dwm should be called with exec. The following sets up an agent for dwm for me:

exec ssh-agent dwm

Running startx and then opening a terminal shows the agent loaded.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .