2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Git】VSCodeからGitHubへの接続で403エラーが出た時の対処法(Mac)

Posted at

はじめに

VSCodeやコンソールからGitHubに接続しようとした時に、トークンの認証画面が出てこず、リポジトリを追加できませんでした。
簡単なmacの設定で繋げることができるようになったので、手順をまとめておきます。

問題

以下のコマンドでGitHub上のリポジトリにリモート接続しようとしました。

git remote add origin https://username@github.com/username/sample.git

次に、originリポジトリにmasterブランチをpushしようとしたところ、以下の認証エラーが表示されました。

git push origin master
remote: Permission to username/sample.git denied to username.
fatal: unable to access 'https://github.com/username/sample.git/': The requested URL returned error: 403

解決方法

"キーチェーンアクセス"にて、トークンを設定することで解決できます。

手順

  1. GitHubにログインし、Personal Access Token を発行します。
  2. macOSの"キーチェーンアクセス"を開きます。
    "キーチェーンアクセス"はFinderの「アプリケーション」>「ユーティリティ」>「キーチェーンアクセス」から開くか、Spotlight検索(command + space)で「キーチェーンアクセス」と入力して開きます。
  3. 検索欄に github と入力し、種類が"インターネットパスワード"の項目を探します。
  4. 対象の項目をダブルクリックして開きます。
  5. 「パスワードを表示」にチェックを入れてMacのログインパスワードを入力し、パスワード欄にGitHubで発行したトークンを貼り付けます。
  6. これで問題のコマンドを入力すれば、エラーが出力されずに接続ができるようになっているはずです。

終わりに

認証エラーに遭遇したときは、まずキーチェーンの中にあるGitHub情報を確認・修正してみましょう。

2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?