LoginSignup
39
23

More than 5 years have passed since last update.

1分でできるGithubの2段階認証の設定

Last updated at Posted at 2018-04-02

他の記事を見ていてgithub初心者なので全然わからない。
UIが変わるので他の記事を見てもふむ...という感じだった。ので、記事を書いて見ました。

はじめに現象

2段階認証を設定して初めてpushしようとしたら下記のようなエラーがでた。

 $ git push -u origin master
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/_repo_.git/'
 $ git push origin master
Username for 'https://github.com': _USERNAME_
Password for 'https://4geru@github.com': ****
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/_USERNAME_/_repo_.git/'

解決法

手順は以下の通りです。
1. Tokenの発行
2. ~/.netrcの記述

1. Tokenの発行

Github > SettingsからPersonal settingsのDeveloper settingsを選択
スクリーンショット 2018-04-03 5.11.53.png
Personal access tokensからGenerate new tokenでtokenを作成します。
スクリーンショット 2018-04-03 5.12.28.png

token生成時に必要なのは、Token descriptionとSelect Scopeです。
操作できるscopeは、repositoryに関する操作だけで十分だと思います。
スクリーンショット 2018-04-03 5.12.40.png

生成されるTokenは必ずコピーしてください。忘れた場合は再度生成することができます。

2. ~/.netrcの記述

~/.netrcをtouchで生成し、中に設定を記述していきます。

$ touch ~/.netrc

お好みのエディタで、~/.netrcの設定を書いてください。

~/.netrc
machine github.com
login [あなたのGitHubのID]
password [1のtoken]

参考URL

Githubを二段階認証にして、弾かれた時にする一番ラクな対策
[Git][GitHub]GitHubにPushする際に認証失敗する
Github 登録時の二段階認証
GitHubで二段階認証に変更する

39
23
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
39
23