[Git] GitHub: SSH鍵認証しているはずなのにパスワードを求められるを解決する方法

git push するたびに、ユーザー名とパスワードを入力するのはどうかと思うので、鍵認証の設定をします。

[markdown]

## 症状

このような形で鍵を用意して、github.com に公開鍵を登録します。

> * [ssh – 鍵作成とconfigによる複数ホストの管理 | deadwood](https://www.d-wood.com/blog/2013/05/17_3620.html)

ホスト github.com に対して、設定した秘密鍵が使われていることを確認します。

“`
% ssh git@github.com
PTY allocation request failed on channel 0
Hi DriftwoodJP! You’ve successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.
“`

OKなので、さっそくpushします。

“`
% git push origin master
Username for ‘https://github.com’:
Password for ‘https://github.com’:
remote: Anonymous access to DriftwoodJP/Agile-Web-Development-with-Rails.git denied.
fatal: Authentication failed for ‘https://github.com/DriftwoodJP/Agile-Web-Development-with-Rails.git/’
“`

ユーザー名とパスワードを求められます。

## 対応

git remote add したときに、https で add したことが原因とのこと。

> * [authentication – Git push requires username and password – Stack Overflow](http://stackoverflow.com/questions/6565357/git-push-requires-username-and-password)

記憶にございませんが、たしかにディフォルト表記はこのようになってます。

git 2013-08-29 15-02-52

### git remote set-url

remote の情報を github のリポジトリで確認します。

git 2013-08-29 15-05-07

remote の情報を書き換えます。

“`
% git remote set-url origin git@github.com:DriftwoodJP/Agile-Web-Development-with-Rails.git
“`

無事、git push できるようになりました。

### git remote -v

`git remote -v` で、リモートの情報を確認できます。

“`
% git remote -v
origin https://github.com/DriftwoodJP/automator-workflows.git (fetch)
origin https://github.com/DriftwoodJP/automator-workflows.git (push)
% git remote set-url origin git@github.com:DriftwoodJP/automator-workflows.git
% git remote -v
origin git@github.com:DriftwoodJP/automator-workflows.git (fetch)
origin git@github.com:DriftwoodJP/automator-workflows.git (push)
“`

[/markdown]