この記事では非公開のOrganizationを使った例を載せていますが、個人のリポジトリでもほとんどやることは同じです。(おそらくステップ5が不要なくらい)
問題
GitHubに二段階認証を設定した後、普通にgit clone等のgit操作をしようとするとauthエラーで何もできない。
$ git clone https://github.com/private-organization/repository.git
Cloning into 'repository'...
Username for 'https://github.com': kitoko552
Password for 'https://kitoko552@github.com':
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/private-organization/repository.git/'
httpsでなくsshに切り替えてもできない。
$ git clone git@github.com:private-organization/repository.git
Cloning into 'repository'...
Enter passphrase for key '/path/to/.ssh/id_rsa':
ERROR: The `private-organization' organization has enabled or enforced SAML SSO. To access
this repository, you must use the HTTPS remote with a personal access token
or SSH with an SSH key and passphrase
that has been whitelisted for this organization. Visit
https://help.github.com/articles/authenticating-to-a-github-organization-with-saml-single-sign-on/ for more information.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
解決策
1. GitHubの自分のメニューからSettings>Developer settings>Personal access tokens
Settings | Developer settings | Personal access tokens |
---|---|---|
![]() |
![]() |
![]() |
|
2. Generate new token
![genereta_new_token.png](https://qiita-user-contents.imgix.net/https%3A%2F%2Fqiita-image-store.s3.amazonaws.com%2F0%2F42132%2F1aa51192-edd5-e041-b734-4b01cf9a5e18.png?ixlib=rb-4.0.0&auto=format&gif-q=60&q=75&s=7feafb79f11f78e23246948cba1f61de)
3. repoからgistまでを全てチェックしてGenerate token
![new_personal_access_token.png](https://qiita-user-contents.imgix.net/https%3A%2F%2Fqiita-image-store.s3.amazonaws.com%2F0%2F42132%2F5bdab63f-3447-7a0b-849d-630b3e41db5c.png?ixlib=rb-4.0.0&auto=format&gif-q=60&q=75&s=8ae16c6037f5e7cbcdfc66fbe1d23614)
4. tokenをコピーしてどっかに保存(1回しか教えてくれないから注意)
5. 作ったtokenのSSOボタンをタップ -> ポップアップ内のprivate-organizationのAuthorize
6. httpsでgit clone
$ git clone https://github.com/private-organization/repository.git
Cloning into 'repository'...
Username for 'https://github.com': kitoko552
Password for 'https://kitoko552@github.com': {ここでGitHubのパスワードでなくtokenを入力する}