この記事では非公開の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
3. repoからgistまでを全てチェックしてGenerate token
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を入力する}