Skip to content

Instantly share code, notes, and snippets.

@gerbsen
Forked from schaary/ssh_agent_start.fish
Last active July 16, 2024 16:52
Show Gist options
  • Save gerbsen/5fd8aa0fde87ac7a2cae to your computer and use it in GitHub Desktop.
Save gerbsen/5fd8aa0fde87ac7a2cae to your computer and use it in GitHub Desktop.
Auto-launching ssh-agent in fish shell
# content has to be in .config/fish/config.fish
# if it does not exist, create the file
setenv SSH_ENV $HOME/.ssh/environment
function start_agent
echo "Initializing new SSH agent ..."
ssh-agent -c | sed 's/^echo/#echo/' > $SSH_ENV
echo "succeeded"
chmod 600 $SSH_ENV
. $SSH_ENV > /dev/null
ssh-add
end
function test_identities
ssh-add -l | grep "The agent has no identities" > /dev/null
if [ $status -eq 0 ]
ssh-add
if [ $status -eq 2 ]
start_agent
end
end
end
if [ -n "$SSH_AGENT_PID" ]
ps -ef | grep $SSH_AGENT_PID | grep ssh-agent > /dev/null
if [ $status -eq 0 ]
test_identities
end
else
if [ -f $SSH_ENV ]
. $SSH_ENV > /dev/null
end
ps -ef | grep $SSH_AGENT_PID | grep -v grep | grep ssh-agent > /dev/null
if [ $status -eq 0 ]
test_identities
else
start_agent
end
end
@Zabanaa
Copy link

Zabanaa commented Dec 4, 2016

thanks a ton for this 😄

@DonPavlov
Copy link

What does, the ssh-add command do? normally i would think i should add my keys here like:
ssh-add ~/.ssh/id_rsa ssh-add ~/.ssh/ed_25519
or am i thinking wrong.

@denniswebb
Copy link

Good work.

@mklemersson
Copy link

thanks a lot :)

@csvan
Copy link

csvan commented Sep 16, 2017

This is perfect, thank you so much.

@kgourgou
Copy link

Great stuff! 👍 👍

@kave
Copy link

kave commented Aug 8, 2018

just what i was looking for 👍

@nucab
Copy link

nucab commented Feb 25, 2019

Great stuff!

@isaiahtaylor
Copy link

Exactly what I needed, thanks.

@m4lh2
Copy link

m4lh2 commented Oct 22, 2019

Thanks for sharing!

Copy link

ghost commented Dec 1, 2020

This is great thank you

@mezhgano
Copy link

mezhgano commented Dec 2, 2020

Thanks a lot
It's a time saver

@dmezh
Copy link

dmezh commented Feb 23, 2021

Awesome, thanks!

@BunnyNoBugs
Copy link

Thank you, it works!

@tenomax-hash
Copy link

awesome bro , its works!

@Benex254
Copy link

thanks a lot

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