LoginSignup
111
71

More than 5 years have passed since last update.

Githubの2段階認証を実施してgitコマンドが使えないときにやったこと

Last updated at Posted at 2017-06-27

Githubの2段階認証を実施してやったこと

Githubの2段階認証(Two-Factor Authentication)とは?

まずは2段階認証の説明など

Github上のアカウントのセキュリティ向上のために、パスワードによるログインだけでなく2段階目の認証を追加出来る

2段階認証の設定方法

細かい設定については記載しないが、まずはGithubのサイトにログインし、アカウントの設定画面から設定可能
(https://github.com/settings/profile)

設定項目の「Security」から設定可能

gitコマンドでの利用

2段階認証とgitコマンド

素朴な疑問として、gitコマンドで2段階認証ってどうするの?というところがある
対策としては Personal access tokens を利用すべし

Personal access tokens

2段階認証を設定しているGithubアカウントにて、Githubサイトの設定ページ(https://github.com/settings/profile) にアクセスしPersonal asccess toensを取得する

作成時に「どこまでの権限を付与するか」のチェック項目があるが、gitコマンドでの操作であればとりあえず
repo
があれば大丈夫

スクリーンショット 2017-06-27 18.44.08.png

ここから Generate token すると token(40文字の英数字)が発行される

gitコマンドでの利用

通常のgitコマンドセットアップや利用開始と同じような流れで、パスワード入力の箇所でaccess tokenそのものを入れるだけである
以下はgit cloneしようとしたときのサンプル

$ git clone https://github.com/sample.git
Cloning into 'sample'...
Username for 'https://github.com': nmorioka
Password for 'https://nmorioka@github.com':(access token:40文字の英数字)

あとは他所(Source Treeなど)でも利用出来るように
git credential-osxkeychain
あたりを設定しておけば良いはず

111
71
0

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
111
71