1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

bashでssh-agentが自動起動&鍵登録&自動終了するように設定

Posted at

.bash_profile 側

# ssh-agent auto startup
eval `ssh-agent` > /dev/null 2>&1
eval `ssh-add ~/.ssh/id_ed25519 > /dev/null 2>&1`

.bash_logout 側

# kill ssh-agent on logout
SSH_AGENT_PID="$(pidof ssh-agent | awk -F' ' {'print $1;'})" ssh-agent -k 2>&1 > /dev/null

SSH_AGENT_PID特定部分でawkパートがあるのは、
複数sshセッションがある際にPIDを1つだけに限定してssh-agentを落とすため
そうしないと以下のようになってしまう

SSH_AGENT_PID="2377 1603", which is not a good PID: invalid

手抜きawkなのでそのsshセッションで起動したssh-agentではないかもしれないが
最終的に辻褄は合うのであえて深入りしていない

参考

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?