Reputation: 860
Everytime I log to mi user and run ssh-add -l
it returns The agent has no identities.
So I had to add this line to mi fish.config file:
ssh-add ~/.ssh/id_one and ssh-add ~/.ssh/id_two > /dev/null ^ /dev/null
I know it works but I want to evaluate first it they have been already added to the agent in order to prevent this line to run every time I open up a terminal tab.
PD: also if there's a different way to keep them consistently on the ssh agent I'll be glad to know, already tried adding them with the -K option and adding
IdentityFile ~/.ssh/id_one
IdentityFile ~/.ssh/id_two
to my ~/.ssh/config
and ~/.ssh/ssh_config
with no result.
Upvotes: 3
Views: 771
Reputation: 7469
First thing to point out is your command
ssh-add ~/.ssh/id_one and ssh-add ~/.ssh/id_two > /dev/null ^ /dev/null
doesn't do what you think it does. The fish and
command is not syntactically the same as &&
. It's a command. Which means it has to follow a semi-colon or be the first word on a line. So that should be
ssh-add ~/.ssh/id_one; and ssh-add ~/.ssh/id_two > /dev/null ^ /dev/null
Also, throwing away stderr in this situation is risky. If you didn't do that you would have noticed the command wasn't doing what you thought. You should only throw away stderr when you know the command will emit error messages you know can be safely ignored.
The simplest, portable, way is to simply test whether one of the IDs is already registered with the ssh agent:
if status is-login
if not ssh-add -l | grep -q $HOME/.ssh/id_one
ssh-add ~/.ssh/id_one ~/.ssh/id_two
end
end
Upvotes: 1