270
153

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.

GitHubに二段階認証を設定した後にGit操作できない時の解決策

Last updated at Posted at 2018-09-07

この記事では非公開の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
settings.png developer_settings.png personal_access_token.png

|

2. Generate new token

genereta_new_token.png

3. repoからgistまでを全てチェックしてGenerate token

new_personal_access_token.png

4. tokenをコピーしてどっかに保存(1回しか教えてくれないから注意)

5. 作ったtokenのSSOボタンをタップ -> ポップアップ内のprivate-organizationのAuthorize

SSOボタンをタップして...
sso.png

Authorize
authorize.png

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を入力する}
270
153
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
270
153

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?