Recently I added the following script to my auto-start (in KDE):eval `ssh-agent`ssh-addThe script should be started at login and ask for my passphrase and load my secret key. It does almost fine. The scripts is executed right and the agent is started and the environment variables are all set and I'm asked for my passphrase. The only problem is that the key is not loaded after that. But if I then enter ssh-add into a terminal I'm asked for my passphrase and the key is stored for the rest of my X-session.What am I doing wrong? Why is the key not loaded, even though I'm asked for my passphrase?PS: I'm running on Debian jessie.
ssh-agent not adding key when started graphically
ssh;kde;ssh agent
There are 2 possible scenarios I can think of that might be causing this.Both of them stem from the fact that many desktop managers launch their own ssh key agent. This is done because the agent needs to be started before the desktop manager for the exported variables to be picked up by applications started by the desktop manager (your terminal emulator).Your desktop manager is launching its own ssh agent after you launch yours, and it ends up replacing it.I'm not sure at what point, or how, you're launching your ssh agent, but if the desktop manager launches one after yours, its exported variables will override the ones you created.Your desktop manager is launching its own ssh agent before yours, and yours isn't being persisted.If you're just launching a terminal window and doing eval $(ssh-agent); ssh-add, then the variables exported by that ssh-agent won't persist after you close the terminal window. Once you launch a new terminal window, you'll get the variables set by the ssh agent launched by the desktop manager.The way ssh-agent works is that it starts up a daemon in the background, and then prints out several variables that need to be set up.$ ssh-agentSSH_AUTH_SOCK=/tmp/ssh-JLbBwVBP4754/agent.4754; export SSH_AUTH_SOCK;SSH_AGENT_PID=4755; export SSH_AGENT_PID;echo Agent pid 4755;So when you eval $(ssh-agent), you're just setting all those variables.Now variables are only inherited by children, so for them to persist into your desktop manager, they have to be set before your desktop manager starts. This can be difficult to get right and varies between distros. This is why many desktop managers do it themselfs.Note that this is also sometimes done during the pam stack initialization as well.