LoginSignup
2
0

More than 3 years have passed since last update.

【WSL】【fish】WSLでssh-agentを使う (fish版)

Posted at

WSLでssh-agentを自動起動したい時、.bashrcに以下のような感じで記述すると思います。

SSH_AGENT_FILE=$HOME/.ssh/ssh-agent
test -f $SSH_AGENT_FILE && source $SSH_AGENT_FILE
if ! ssh-add -l > /dev/null 2>&1; then
  ssh-agent > $SSH_AGENT_FILE
  source $SSH_AGENT_FILE
  ssh-add $HOME/.ssh/id_rsa
fi

これをfishでも動くように改変しました。使いたい人もいるかもしれないので(僕とか)、ここに記載しておきます。

set -x SSH_AGENT_FILE $HOME/.ssh/ssh-agent
if test -f $SSH_AGENT_FILE
   source $SSH_AGENT_FILE
end
# 先にコマンドを実行して $status をif文で評価
ssh-add -l > /dev/null ^&1
if test $status -ne 0
  # ssh-agent に -c オプションを追加 (csh-style)
  ssh-agent -c > $SSH_AGENT_FILE
  source $SSH_AGENT_FILE
  ssh-add $HOME/.ssh/id_rsa
end

これで今のところ動いています。ご参考に。

【参考】
https://qiita.com/wing-tail/items/66ddcfe352664a182ba1
https://alpaca0984.github.io/2018/01/14/Using-ssh-agent-in-fish-shell/

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0