Skip to content

Instantly share code, notes, and snippets.

@josh-padnick
Last active February 24, 2024 14:59
  • Star 42 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save josh-padnick/c90183be3d0e1feb89afd7573505cab3 to your computer and use it in GitHub Desktop.
Run ssh-agent via fish shell
#!/bin/bash
#
# Convert ssh-agent output to fish shell
#
eval "$(ssh-agent)" >/dev/null
echo "set SSH_AUTH_SOCK \"$SSH_AUTH_SOCK\"; export SSH_AUTH_SOCK"
echo "set SSH_AGENT_PID \"$SSH_AGENT_PID\"; export SSH_AGENT_PID"
@raj23689
Copy link

Your code shows the ssh id agent number after every instance of a terminal is opened, please tell me how to hide that.

@thibault-ketterer
Copy link

Isn't it only for new instances (when ssh-agent is not running) ?
but, I think you have to redirect the eval to /dev/null
or maybe my prompt is overriding the ouput 🤷

@ekalosak
Copy link

ekalosak commented Mar 4, 2022

+1 @Optiligence 's answer.

@HoneyBearCodes
Copy link

Isn't it only for new instances (when ssh-agent is not running) ? but, I think you have to redirect the eval to /dev/null or maybe my prompt is overriding the ouput shrug

uhhhh, see the thing is I am a beginner and I don't know anything about fish/bash scripting so can you please tell me how am I supposed to fix it?

@tim3trick
Copy link

To remove the agent pid information replace eval (ssh-agent -c) with eval (ssh-agent -c | head -n2)

@edouard-lopez
Copy link

@thibault-ketterer would you care create a MR of your snippet into https://github.com/danhper/fish-ssh-agent?

@matu3ba
Copy link

matu3ba commented Mar 23, 2023

I am astonished, that no solution bothers to cleanup started agents, ie with on of those for security:

trap "kill $SSH_AGENT_PID" exit
trap "ssh-agent -k" exit

See also https://rabexc.org/posts/pitfalls-of-ssh-agents. Ideally the WM has a ssh-agent instance one could use instead of spawning a new one in each terminal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment