17
17

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 3 years have passed since last update.

ssh-add できないときの解決方法

Last updated at Posted at 2020-09-10

#ssh-addができないときの解決方法
gitで詰まったところを備忘録的に書いています.

##環境
windows 10
git bash
##結論
手順をとても簡単にしたものです

#ssh-agentをバックグラウンドで起動
$ eval $(ssh-agent -s)
Agent pid 1440

#ssh key を追加
$ ssh-add ~/.ssh/id_rsa
Enter passphrase for /c/Users/Username/.ssh/id_rsa:
Identity added: /c/Users/Username/.ssh/id_rsa (example@mailm)

#確認する
$ ssh-add -l
(あなたのキー)

##問題点
ssh公開鍵を毎回パスフレーズ求められるのは面倒くさい,,

$ git pull
Enter passphrase for key '/Users/Username/.ssh/id_rsa':

##解決方法
ssh keyを自動で認証できるようにしよう

1.このままだとssh-addできない

$ ssh-add ~/.ssh/id_rsa
Could not open a connection to your authentication agent.

$ ssh-add -K
Could not open a connection to your authentication agent.

$ ssh-add -l
Could not open a connection to your authentication agent.

2.ssh-agentをバックグラウンドで起動
とりあえずssh-agentすればいいすればいいらしい

//これはできなかった
$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-IFr4jBWrz8XT/agent.1429; export SSH_AUTH_SOCK;
SSH_AGENT_PID=1430; export SSH_AGENT_PID;
echo Agent pid 1430;

#これもできなかった
$ eval "ssh-agent"
SSH_AUTH_SOCK=/tmp/ssh-axacGz0TApMp/agent.1434; export SSH_AUTH_SOCK;
SSH_AGENT_PID=1435; export SSH_AGENT_PID;
echo Agent pid 1435;

#これで成功
$ eval $(ssh-agent -s)
Agent pid 1440

3.ssh-addする
こんな感じで返ってきたら毎回パスフレーズを求められなくなる.

$ ssh-add ~/.ssh/id_rsa
Enter passphrase for /c/Users/Username/.ssh/id_rsa:
Identity added: /c/Users/Username/.ssh/id_rsa (example@mailm)

#確認する
$ ssh-add -l
(あなたのキー)

##参考文献
新しい SSH キーを生成して ssh-agent に追加する

17
17
2

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
17
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?