0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Githubの認証方法

Posted at

概要

Gihubの認証周りで少しつまづいたので、認証周りがどうなってるんだっけ?
といったことを理解するための記事です。

アクセス方法

  • ブラウザ内、
  • GitHub Desktop
  • API
  • コマンドライン

など、さまざまな方法でアクセスできるっぽい。

認証方法

認証方法は、

  • 2 要素認証を使用したユーザー名とパスワード、またはパスキー
  • Personal access token
  • SSH キー
    の主に3種類での認証方法があるとのこと。

アクセス方法に認証方法が依存してるので、アクセス方法に合った認証方法を選択する必要があるらしい。うん。それはそうだよね。

個人的には、CLIで完結できるならCLIがいい(GUI慣れるまで時間かかるので)人間なので、コマンドラインでの認証で試していきます。

コマンドラインでの認証

  • HTTPS
  • SSH
    の2つの方法のみらしい。

Githubでの推奨は、HTTPSとのこと。パッとメリデメが分からなかったので、下記の記事を参考にさせてもらいました。

なぜHTTPS? かといったところは、

  • アカウント情報だけでリポジトリに書き込めるので、どこからでも簡単にアクセスできるから
  • HTTPSはすべてのファイアウォールで開かれているから

一方、SSHのメリットとしては、

  • 情報漏えい対策としては最適解
  • 鍵がハードディスク上のユーザアクセスが可能なファイルとして保存されることが欠点

とのこと。まぁそうだよねって感じ。
セキュリティー面を考える必要が今回はないので、使い勝手を考えるとHTTPSがいいかなと。

実際に試してみる

ghコマンド入ってなかったので、入れました。

brew install gh
yuya.k@mbp work % brew install gh
==> Auto-updating Homebrew...
Adjust how often this is run with HOMEBREW_AUTO_UPDATE_SECS or disable with
HOMEBREW_NO_AUTO_UPDATE. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Auto-updated Homebrew!
・
・
・
==> Running `brew cleanup gh`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
yuya.k@mbp work % 

ログインしていきます。

yuya.k@mbp work % gh auth login  
? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations on this host? HTTPS
? Authenticate Git with your GitHub credentials? Yes
? How would you like to authenticate GitHub CLI? Paste an authentication token
Tip: you can generate a Personal Access Token here https://github.com/settings/tokens
The minimum required scopes are 'repo', 'read:org', 'workflow'.
? Paste your authentication token: 
・
・
・
? Paste your authentication token: **********************************************************************************- gh config set -h github.com git_protocol https
✓ Configured git protocol
✓ Logged in as 〜

事前に作成しておいたアクセストークンを入力して、これでログインOKですね。
アクセストークンの作成方法は、下記の記事が見やすかったので載せておきます。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?