I was running eval `ssh-agent -s\`
I get this error
fish: Unknown command: `ssh-agent
I was running eval `ssh-agent -s\`
I get this error
fish: Unknown command: `ssh-agent
There are two parts to your question:
eval `ssh-agent -s`
?ssh-agent
in the Fish shellFor the first, the feature you are looking for is called "command substitution". There are two ways of doing this in Bash/POSIX shells:
`command`
), as you are using$(command)
The backticks form is highly discouraged, so if you are coming across documentation or a blog utilizing them, realize that it's severely out of date (or unaware).
In Fish, as you've discovered, the (command)
grouping is the "most supported" way to do command substitution. However, as of Fish 3.4.0, the $(command)
form also works. So using either:
eval (ssh-agent -c)
oreval $(ssh-agent -c)
will workHowever, I would recommend the use of keychain
for simplifying ssh-agent
use in Fish (and other shells). Ignore the part of the webpage that says (as @Charliesneath points out in the comments), "Currently, keychain is not compatible with Fish shell." The webpage just hasn't been updated in a while.
Keychain actually does have built-in support for Fish (added in 2017) and can make use of universal variables to keep your keys in sync across multiple shell sessions.
For instance, if you have two Fish shell sessions open, and you run ssh-agent
/ssh-add
in one of them, you still need to run the same in the other, and enter your password again. There are ways to share the agent among shell sessions, but Keychain handles it for you.
Keychain can be installed directly from most distributions' repositories. For instance, sudo apt install keychain
.
It can be enabled in Fish with:
keychain --eval <keyfile> | source
I have this set up in Fish as follows.
Create the following script in ~/.config/fish/conf.d/keychain.fish
if status is-login
and status is-interactive
# To add a key, set -Ua SSH_KEYS_TO_AUTOLOAD keypath
# To remove a key, set -U --erase
SSH_KEYS_TO_AUTOLOAD[index_of_key]
keychain --eval $SSH_KEYS_TO_AUTOLOAD | source
end
set -Ua SSH_KEYS_TO_AUTOLOAD ~/.ssh/id...
for whatever key(s) you want to use.
That's pretty much it. When you start a login Fish shell, if the key isn't unlocked, Keychain will ask for the password and add it to a shared ssh-agent
. If it is already unlocked, then it won't ask again.
You can, of course, simplify the script by embedding static key name(s). I prefer universal variables to keep the script dynamic. This allows a single script to be stored in my dotfiles repo even though I use different keys on different systems.
keychain
page: "Currently, keychain is not compatible with Fish shell." funtoo.org/Funtoo:Keychain
Commented
Sep 15, 2022 at 0:02
is-login
and is-interactive
, as far as I know login shells are interactive shells by definition (but not all interactive shells are login shells).
fish -l -c "status is-login && echo 'is-login'; status is-interactive || echo 'but not interactive'"
? It seems to me that any shell invocation with both -l
and -c
meets that criteria, right?
Commented
Feb 19 at 23:11
I get this solution
run
eval (ssh-agent -c)
reference:https://wiki.archlinux.org/title/Fish#Evaluate_ssh-agent
I use fish_ssh_agent
from gihub https://github.com/ivakyb/fish_ssh_agent
That repo also has few valuable hint on topic SSH, SSH-agent, Fish-shell.