LoginSignup
160
143

More than 5 years have passed since last update.

githubで2段階認証を設定したらpushできなくなった

Last updated at Posted at 2014-04-06

現象

keyの設定は正常。

$ ssh -T git@github.com
Warning: Permanently added 'github.com,192.30.252.128' (RSA) to the list of known hosts.
Hi myoan! You've successfully authenticated, but GitHub does not provide shell access.

しかし、正しいpasswordを入れてもinvaildと言われてしまう。

Username for 'https://github.com': myoan
Password for 'https://myoan@github.com':
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/myoan/repository.git/'

しかも、以前はきちんとpushは出来ていた。

原因

githubの2段階認証をonにすると、httpsプロトコルで登録してるrepositoryごとにOAuthのアクセストークンを生成する必要があるっぽい。

解決策

(追記)はい、投稿から10秒で良さげな解決策をだされている投稿を見つけました。
- 参照 hubを2-factor authentication(2要素認証)有効でも使いたい

解決策は2つ。

1. レポジトリ用にアクセストークンを生成する

どうしても安全に利用したい場合(社用で開発しているものとか)

ただし、この場合アクセストークンをpushの度に聞かれることになる。

試してないけど、macならosxkeychainを利用できるらしい。
- 参照: Set Up Git

(keychain使ってないんだけどどうしよう...)

2. gitプロトコルつかう

自分用のレポジトリはgitプロトコルを使えばいいと思う。
(追記: gitプロトコルを明示しました。uasiさん、ご指摘ありがとうございました)

$ git remote set-url origin git://git@github.com:myoan/repository.git
$ git push

Counting objects: 5, done.
Writing objects: 100% (3/3), 255 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:myoan/repository.git
   6ec9b96..100c737  master -> master

自分用と会社用のを分けようかなぁ...

160
143
3

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
160
143