Skip to content

Instantly share code, notes, and snippets.

@salah93
Last active February 18, 2021 14:57
Show Gist options
  • Save salah93/8380fcb5911dc96c0817c578e2b7db38 to your computer and use it in GitHub Desktop.
Save salah93/8380fcb5911dc96c0817c578e2b7db38 to your computer and use it in GitHub Desktop.
starting ssh agent in fish shell
function kill-ssh-agent
killall ssh-agent
set -e SSH_AGENT_PID
set -e SSH_AUTH_SOCK
rm $SSH_ENV > /dev/null 2>&1
end
# for ssh-add -c to work you would need to install openssh-askpass
# then set this environment variable to point to the ssh-askpass script
# this and DISPLAY should be set BEFORE starting ssh-agent
if test -e /usr/libexec/openssh/ssh-askpass
set -x SSH_ASKPASS /usr/libexec/openssh/ssh-askpass
else if type -q ssh-askpass
set -x SSH_ASKPASS (which ssh-askpass)
end
if test -z $SSH_ENV
set -xg SSH_ENV $HOME/.ssh/environment
end
pgrep -fq "ssh-agent -t 1800 -c"
set -l ssh_agent_is_running $status
if test -f $SSH_ENV
and test $ssh_agent_is_running -eq 0
source $SSH_ENV > /dev/null 2>&1
else
kill-ssh-agent
end
# on gnome edit this file /etc/xdg/autostart/gnome-keyring-ssh.desktop
# include the line X-GNOME-Autostart-enabled=false
# then restart for it to take effect
function start-ssh-agent
set -gx DISPLAY :0
eval (ssh-agent -t 1800 -c)
# WARNING - setting display in startup results in login loop in gnome!! setting it here will help us avoid this
echo set -gx DISPLAY :0 >> $SSH_ENV
echo set -gx SSH_AUTH_SOCK $SSH_AUTH_SOCK > $SSH_ENV
echo set -gx SSH_AGENT_PID $SSH_AGENT_PID >> $SSH_ENV
chmod 600 $SSH_ENV
source $SSH_ENV > /dev/null 2>&1
end
@salah93
Copy link
Author

salah93 commented Jan 31, 2021

this takes a lot of what fish-ssh-agent does https://github.com/danhper/fish-ssh-agent
but is more manual and works for me using tmux

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