1

I have a bash session on tty2 and an ssh-agent process belonging to me (same user id) from a previous session (TTY = ?)

On tty2, ssh-add says : Could not open a connection to your authentication agent.

Do I have to start an eval $(ssh-agent) each time I log in, even when there's already an ssh-agent process running ? But then at the end, I will have many ssh-agent process instances running :-(

EDIT : I would like to use my already running ssh-agent process.

I found a way to contact my already running ssh-agent like this :

export SSH_AUTH_SOCK=$(find /tmp/ssh-*/ -user $USER -type s -name "agent.*" 2>/dev/null | head -1)
export SSH_AGENT_PID=$(echo $SSH_AUTH_SOCK | cut -d. -f2)

but I'm not sure this is very secure.

EDIT 2: The command eval $(ssh-agent) starts a new instance of the ssh-agent process every time I run this command :-(

migrated from stackoverflow.com Apr 22 '18 at 9:12

This question came from our site for professional and enthusiast programmers.

2

You could eval and save the ssh-agent output at the same time,

eval $(ssh-agent | tee agent.env)

then from other terminals or subsequent sessions,

source agent.env

Tighten up the permissions to be slightly more secure,

chmod go-rwx agent.env
  • I guess there is security issue here. If one gets access to the root privilege and is a bad person, he could still all my ssh-agent keys :-( – SebMa Mar 30 '18 at 15:12
  • 1
    @SebMa I think that root user can use the private keys but not still them. From the man page: The agent will never send a private key over its request channel. Instead, operations that require a private key will be performed by the agent, and the result will be returned to the requester. – Ortomala Lokni Mar 30 '18 at 16:16
  • @OrtomalaLokni You are absolutely right, that was a typo, I meant use instead of still :) – SebMa Mar 30 '18 at 17:58
  • @SebMa If a malicious person gets root access, then your SSH keys are the least of your problems. – Kusalananda Apr 22 '18 at 9:26
  • @Kusalananda Yes and no : If someone uses my SSH keys, he/she can do bad things with my identity on remotes servers, and I would have to pay these consequences. – SebMa Apr 22 '18 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.