Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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"
@NeMO84

This comment has been minimized.

Copy link

@NeMO84 NeMO84 commented Jun 13, 2017

Thanks! Came in very handy.

@Optiligence

This comment has been minimized.

Copy link

@Optiligence Optiligence commented Apr 24, 2018

eval (ssh-agent -c)

@ivakyb

This comment has been minimized.

Copy link

@ivakyb ivakyb commented Mar 4, 2019

Consider to use

fish_ssh_agent

Utility functions to start your ssh agent when using fish shell. You will only need to run ssh-add and type your password once, after the running ssh_agent should do the work for you. Need to run once, environment variables shared between sessions.

@talbergs

This comment has been minimized.

Copy link

@talbergs talbergs commented Oct 3, 2019

# config.fish
if test -z (pgrep ssh-agent)
  eval (ssh-agent -c)
  set -Ux SSH_AUTH_SOCK $SSH_AUTH_SOCK
  set -Ux SSH_AGENT_PID $SSH_AGENT_PID
  set -Ux SSH_AUTH_SOCK $SSH_AUTH_SOCK
end
@timmyjose

This comment has been minimized.

Copy link

@timmyjose timmyjose commented Dec 14, 2019

# config.fish
if test -z (pgrep ssh-agent)
  eval (ssh-agent -c)
  set -Ux SSH_AUTH_SOCK $SSH_AUTH_SOCK
  set -Ux SSH_AGENT_PID $SSH_AGENT_PID
  set -Ux SSH_AUTH_SOCK $SSH_AUTH_SOCK
end

Excellent. Thank you!

@aadibajpai

This comment has been minimized.

Copy link

@aadibajpai aadibajpai commented Jun 15, 2020

# config.fish
if test -z (pgrep ssh-agent)
  eval (ssh-agent -c)
  set -Ux SSH_AUTH_SOCK $SSH_AUTH_SOCK
  set -Ux SSH_AGENT_PID $SSH_AGENT_PID
  set -Ux SSH_AUTH_SOCK $SSH_AUTH_SOCK
end

is it worth it adding ssh-add somewhere in here so you only need to input your passphrase once per session?

@Immortalin

This comment has been minimized.

Copy link

@Immortalin Immortalin commented Oct 10, 2020

# config.fish
if test -z (pgrep ssh-agent)
  eval (ssh-agent -c) > /dev/null
  set -Ux SSH_AUTH_SOCK $SSH_AUTH_SOCK
  set -Ux SSH_AGENT_PID $SSH_AGENT_PID
  set -Ux SSH_AUTH_SOCK $SSH_AUTH_SOCK
end
@o-behemoth-o

This comment has been minimized.

Copy link

@o-behemoth-o o-behemoth-o commented Oct 24, 2020

# config.fish
if test -z (pgrep ssh-agent)
  eval (ssh-agent -c)
  set -Ux SSH_AUTH_SOCK $SSH_AUTH_SOCK
  set -Ux SSH_AGENT_PID $SSH_AGENT_PID
  set -Ux SSH_AUTH_SOCK $SSH_AUTH_SOCK
end

work for msys2+fish installation 👍

@oryon-dominik

This comment has been minimized.

Copy link

@oryon-dominik oryon-dominik commented Dec 22, 2020

# config.fish
if not pgrep -f ssh-agent > /dev/null
  eval (ssh-agent -c)
  set -Ux SSH_AUTH_SOCK $SSH_AUTH_SOCK
  set -Ux SSH_AGENT_PID $SSH_AGENT_PID
  set -Ux SSH_AUTH_SOCK $SSH_AUTH_SOCK
end

works in WSL too

@martin-g

This comment has been minimized.

Copy link

@martin-g martin-g commented Mar 31, 2021

No need to export set -Ux SSH_AUTH_SOCK $SSH_AUTH_SOCK twice!

@talbergs

This comment has been minimized.

Copy link

@talbergs talbergs commented Mar 31, 2021

Better twice, just to be sure!

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