Help us understand the problem. What is going on with this article?

Gitを使うとき、ssh-agentが増殖してしまう問題のシンプルな解法

More than 5 years have passed since last update.

今までのやり方

.bashrcにこう書いていた。

eval `ssh-agent`
ssh-add

ssh-agentはbashを閉じても死なないので、このやり方だと、bashを開く度にssh-agentのプロセスが増殖してしまう。

解決方法

ssh-agentの出力をファイルに吐き出して、使いまわす

Windows版Gitの場合

  • start-ssh-agent.bat(ssh-agent起動スクリプト。スタートアップ時などに呼び出せばいい)
set git="C:\Program Files\Git\bin\sh.exe"
%git% --norc -c "/bin/ps | /bin/grep -q ssh-agent && /bin/ps | /bin/grep ssh-agent | /bin/gawk '{print $1}' | /bin/xargs /bin/kill"
%git% --norc -c "/bin/mkdir -p /var && /bin/ssh-agent > /var/ssh-agent.out"
  • .bashrc
eval `cat /var/ssh-agent.out`
ssh-add

Linuxの場合

※Windows版と内容はまったく同じ。むしろこっちのほうがシンプル。

  • start-ssh-agent.sh(ssh-agent起動スクリプト。スタートアップ時などに呼び出せばいい)
ps ax | awk '$5 ~ /^ssh-agent/{print "kill "$1}' | sh
ssh-agent > /var/ssh-agent.out
  • .bashrc
eval `cat /var/ssh-agent.out`
ssh-add
kunst1080
Play + Javaで小規模WEBサービス作ってるかも
http://kunst1080.hatenablog.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした