「git push」したら403エラー…
「remote: Permission denied」って何?
「GitHubにアクセスできなくなった…」
突然Gitの操作ができなくなって困っていませんか?
この記事では、Git操作中に発生する「403 Forbidden」エラーについて、原因から具体的な解決方法まで、初心者の方にもわかりやすく解説します。
結論:403エラーの主な原因と解決法

まず結論から:
主な原因:
- 認証エラー(最多) – パスワード認証の廃止、トークン不足
- 権限不足 – リポジトリへのアクセス権がない
- 古い認証情報 – キャッシュされた情報が間違っている
基本的な解決手順:
- 個人アクセストークン(PAT)を作成
- 古い認証情報を削除
- 新しいトークンで再認証
それでは詳しく見ていきましょう。
403エラーとは
エラーメッセージの例
典型的なエラー:
$ git push origin main
Username for 'https://github.com': your-username
Password for 'https://your-username@github.com':
remote: Support for password authentication was removed on August 13, 2021.
fatal: unable to access 'https://github.com/user/repo.git/':
The requested URL returned error: 403
バリエーション:
# パターン1:権限エラー
remote: Permission to user/repo.git denied to username.
fatal: unable to access 'https://github.com/user/repo.git/':
The requested URL returned error: 403
# パターン2:アクセス拒否
remote: The requested repository either does not exist or you do not have access.
fatal: unable to access 'https://github.com/user/repo.git/':
The requested URL returned error: 403
# パターン3:認証失敗
fatal: Authentication failed for 'https://github.com/user/repo.git/'
403エラーの意味
HTTP 403 Forbidden:
- サーバーはリクエストを理解した
- しかしアクセスを拒否している
- 「権限がありません」という意味
Gitでの403エラー:
- 認証情報が正しくない
- リポジトリへのアクセス権がない
- 認証方式が古い
403エラーの原因
原因1:パスワード認証の廃止(最多)
重要な変更:
GitHubは2021年8月13日にパスワード認証を廃止しました。
以前(〜2021年8月12日):
Username: your-username
Password: your-password ← パスワードでOK
現在(2021年8月13日〜):
Username: your-username
Password: ghp_xxxxxxxxxxxx ← 個人アクセストークンが必須
なぜ廃止されたのか:
- セキュリティ強化
- パスワードは推測されやすい
- 使い回しのリスク
- 漏洩した時の被害が大きい
- より安全な認証
- トークンは用途別に作成
- 権限を細かく設定可能
- 有効期限を設定できる
- いつでも無効化できる
この原因のサイン:
remote: Support for password authentication was removed on August 13, 2021.
remote: Please use a personal access token instead.
原因2:古い認証情報のキャッシュ
状況:
- 以前は動作していた
- 最近になって突然エラー
- パスワードを入力していない
原因:
- OSが古い認証情報を記憶している
- パスワードまたは古いトークンがキャッシュされている
- アカウントを変更したが情報が残っている
保存場所:
- Windows: 資格情報マネージャー
- Mac: キーチェーンアクセス
- Linux: ~/.git-credentials
原因3:リポジトリへのアクセス権限がない
パターンA:プライベートリポジトリ
remote: The requested repository either does not exist or you do not have access.
原因:
- リポジトリがプライベート設定
- 招待されていない
- 招待を承認していない
パターンB:本家ではなくForkにプッシュすべき
remote: Permission to original-owner/repo.git denied to your-username.
状況:
- オープンソースプロジェクトへの貢献
- 本家リポジトリに直接pushしようとしている
- 自分のForkにpushすべき
原因4:トークンの権限不足
状況:
- トークンは作成した
- でも403エラーが出る
原因:
- トークンに必要な権限(スコープ)がない
- 読み取り専用のトークン
- 有効期限切れ
必要な権限:
- 読み取りのみ:
repo:status,public_repo - 読み書き:
repo(フルアクセス)
原因5:組織・企業のポリシー
Bitbucketなどの企業向けサービス:
IP制限:
remote: To access this repository, an admin must whitelist your IP.
fatal: unable to access: The requested URL returned error: 403
2段階認証の要求:
remote: To access this repository, enable two-step authentication.
fatal: unable to access: The requested URL returned error: 403
アカウント停止:
remote: Your account is suspended.
fatal: unable to access: The requested URL returned error: 403
解決方法:基本編

解決方法1:個人アクセストークン(PAT)の作成と使用
これが最も一般的な解決方法です。
ステップ1:GitHubでトークンを作成
手順:
- GitHubにログイン
https://github.com
- 設定画面を開く
- 右上のプロフィールアイコンをクリック
- 「Settings」を選択
- Developer settingsへ
- 左メニューの一番下
- 「Developer settings」をクリック
- Personal access tokensを選択
- 「Personal access tokens」をクリック
- 「Tokens (classic)」を選択
- 新しいトークンを生成
- 「Generate new token」ボタンをクリック
- 「Generate new token (classic)」を選択
- トークンの設定
Note(トークン名):
例:My Laptop - 2025
用途がわかる名前をつける
Expiration(有効期限):
30 days(30日)
60 days(60日)
90 days(90日)
Custom(カスタム)
No expiration(無期限) ← セキュリティリスク
推奨: 90日〜1年程度
Select scopes(権限):
最低限必要な権限:
☑ repo ← これをチェック
☑ repo:status
☑ repo_deployment
☑ public_repo
☑ repo:invite
☑ security_events
追加で便利な権限:
☑ workflow ← GitHub Actionsを使う場合
☑ read:org ← 組織情報を読む場合
☑ gist ← Gistを使う場合
- トークンを生成
- 一番下の「Generate token」ボタンをクリック
- トークンをコピー
ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
⚠️ 重要:
- トークンは一度しか表示されません
- 必ずコピーして安全な場所に保存
- パスワードマネージャーの使用を推奨
トークンをなくした場合:
- 再表示はできません
- 新しいトークンを作成する必要があります
- 古いトークンは削除しましょう
ステップ2:トークンを使用する
方法A:コマンドラインで入力
Git操作を実行:
$ git push origin main
認証情報を求められたら:
Username for 'https://github.com': your-username
Password for 'https://your-username@github.com': ghp_xxxxxxxxxxxx
↑ パスワードではなくトークンを貼り付け
注意点:
- 「Password」と表示されますが、トークンを入力
- トークンは貼り付けても表示されません
- 入力後にEnterキーを押す
方法B:URLに直接埋め込む(非推奨)
git clone https://your-username:ghp_xxxxxxxxxxxx@github.com/user/repo.git
⚠️ 非推奨の理由:
- トークンがコマンド履歴に残る
- 画面共有時に見えてしまう
- セキュリティリスク
方法C:credential helperを使う(推奨)
設定:
# Windowsの場合
git config --global credential.helper wincred
# Macの場合
git config --global credential.helper osxkeychain
# Linuxの場合(キャッシュ)
git config --global credential.helper cache
# Linuxの場合(ファイル保存)
git config --global credential.helper store
一度トークンを入力すれば、次回から自動的に使用されます。
解決方法2:古い認証情報の削除
Windows:資格情報マネージャーで削除
手順:
- 資格情報マネージャーを開く
方法1:スタートメニューから
スタートメニュー → 「資格情報」と検索 → 「資格情報マネージャー」をクリック
方法2:コントロールパネルから
コントロールパネル → ユーザーアカウント → 資格情報マネージャー
- Windows資格情報を選択
- 「Windows資格情報」タブをクリック
- Git関連の資格情報を見つける
探すべきエントリ:
git:https://github.com
git:http://github.com
- 削除する
- エントリーをクリックして展開
- 「削除」ボタンをクリック
コマンドラインで削除:
# 特定の資格情報を削除
cmdkey /delete:git:https://github.com
# 一覧表示
cmdkey /list
Mac:キーチェーンアクセスで削除
手順:
- キーチェーンアクセスを開く
方法1:Spotlightから
Command + Space → 「Keychain Access」と入力 → Enter
方法2:Finderから
アプリケーション → ユーティリティ → キーチェーンアクセス
- GitHubの認証情報を検索
- 右上の検索ボックスに「github.com」と入力
- 該当エントリを見つける
種類:インターネットパスワード
アカウント:your-username
場所:github.com
- 削除する
- エントリをクリック
- Delete キーを押す
- または右クリック → 削除
コマンドラインで削除:
# GitHub認証情報を削除
git credential-osxkeychain erase << EOF
protocol=https
host=github.com
EOF
# Enterキーを押す
管理者権限で削除が必要な場合:
sudo open /System/Applications/Utilities/"Keychain Access.app"
Linux:認証情報ファイルの削除
保存場所を確認:
git config --get credential.helper
結果別の対処:
cacheの場合:
# キャッシュをクリア
git credential-cache exit
# または
rm -rf ~/.git-credential-cache
storeの場合:
# 認証情報ファイルを編集または削除
nano ~/.git-credentials
# または完全削除
rm ~/.git-credentials
ファイルの中身:
https://username:password@github.com
![]()
The most-comprehensive AI-powered DevSecOps platformFrom planning to production, bring teams together in one application. Ship secure code more efficiently to deliver value...
不要な行を削除して保存。
解決方法3:SSH認証への切り替え(推奨)
HTTPSの代わりにSSHを使用することで、トークン管理の手間を省けます。
SSH認証のメリット
メリット:
- パスワード・トークン入力不要
- セキュリティが高い
- 一度設定すれば永続的
- 複数サービスで同じ鍵が使える
デメリット:
- 初期設定がやや複雑
- 企業ファイアウォールでブロックされる場合がある
ステップ1:SSH鍵の作成
注意:GitHubは古いRSA鍵を拒否
❌ 使用不可(非推奨):
# SHA-1を使うRSA鍵(GitHub 2021年9月以降拒否)
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
✅ 推奨:
# ECDSA鍵(推奨)
ssh-keygen -t ecdsa -b 521 -C "your_email@example.com"
# または Ed25519鍵(よりモダン)
ssh-keygen -t ed25519 -C "your_email@example.com"
対話形式の質問:
# 保存場所
Enter file in which to save the key (/Users/you/.ssh/id_ecdsa):
→ Enterキー(デフォルトでOK)
# パスフレーズ(推奨)
Enter passphrase (empty for no passphrase):
→ パスフレーズを入力(空でも可能だが非推奨)
# パスフレーズ確認
Enter same passphrase again:
→ 同じパスフレーズを入力
作成されるファイル:
~/.ssh/id_ecdsa ← 秘密鍵(絶対に公開しない)
~/.ssh/id_ecdsa.pub ← 公開鍵(GitHubに登録)
ステップ2:公開鍵をGitHubに登録
- 公開鍵をコピー
# Macの場合
pbcopy < ~/.ssh/id_ecdsa.pub
# Linuxの場合
cat ~/.ssh/id_ecdsa.pub
# 表示された内容をコピー
# Windowsの場合
clip < ~/.ssh/id_ecdsa.pub
- GitHubに登録
GitHub → Settings → SSH and GPG keys → New SSH key
Title:
例:My MacBook Pro
わかりやすい名前
Key:
ssh-ecdsa AAAAC3NzaC1lZDI1NTE5AAAA... your_email@example.com
↑ コピーした公開鍵を貼り付け
- Add SSH key ボタンをクリック
ステップ3:接続テスト
ssh -T git@github.com
初回接続時:
The authenticity of host 'github.com (xxx.xxx.xxx.xxx)' can't be established.
ECDSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no/[fingerprint])?
yesと入力してEnter
成功メッセージ:
Hi your-username! You've successfully authenticated, but GitHub does not provide shell access.
ステップ4:リモートURLをSSHに変更
現在のURLを確認:
git remote -v
HTTPS URLの例:
origin https://github.com/username/repo.git (fetch)
origin https://github.com/username/repo.git (push)
SSHに変更:
git remote set-url origin git@github.com:username/repo.git
確認:
git remote -v
SSH URLに変更されている:
origin git@github.com:username/repo.git (fetch)
origin git@github.com:username/repo.git (push)
今後の操作:
git push origin main
# パスワード・トークン入力不要!
解決方法:特殊ケース編
ケース1:複数のGitHubアカウント
状況:
- 個人用アカウント
- 仕事用アカウント
- 間違ったアカウントで認証されている
解決法1:リポジトリごとにアカウントを設定
cd /path/to/repo
# このリポジトリ専用の設定
git config user.name "Work Username"
git config user.email "work@company.com"
# 認証情報も分ける
git config credential.username "work-username"
解決法2:SSH設定で使い分け
~/.ssh/configを編集:
# 個人用GitHub
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ecdsa_personal
# 仕事用GitHub
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ecdsa_work
使用方法:
# 個人用
git clone git@github.com:username/repo.git
# 仕事用
git clone git@github-work:company/repo.git
ケース2:Forkしたリポジトリへの貢献
エラー:
remote: Permission to original-owner/repo.git denied to your-username.
原因:
- 本家リポジトリに直接pushしようとしている
正しい手順:
- 自分のForkを作成
- GitHubで「Fork」ボタンをクリック
- Forkをクローン
git clone https://github.com/your-username/repo.git
- 本家をupstreamとして追加
cd repo
git remote add upstream https://github.com/original-owner/repo.git
- Forkにpush
git push origin feature-branch
- Pull Requestを作成
- GitHub上で「New Pull Request」
ケース3:組織のリポジトリ
エラー:
remote: Permission to organization/repo.git denied.
確認事項:
- 組織メンバーか確認
https://github.com/orgs/organization/people
- 招待を承認したか確認
- メールを確認
- 招待承認のリンクをクリック
- リポジトリの権限を確認
- Read(読み取り)
- Write(書き込み)
- Admin(管理者)
必要な権限:
- push: Write以上
- pull: Read以上
ケース4:トークンの権限不足
エラー:
remote: Permission to user/repo.git denied to user.
(トークンは作成済み)
原因:
- トークンに必要な権限がない
解決方法:
- GitHub → Settings → Developer settings → Personal access tokens
- 該当トークンをクリック
- 権限を確認
必要な権限:
☑ repo ← これが必須
- 権限が足りない場合
- 既存トークンは編集できません
- 新しいトークンを作成
- 適切な権限を設定
- 古いトークンを削除
- 「Delete」ボタン
ケース5:企業ネットワークの制限
プロキシ経由の接続
設定:
# HTTP/HTTPSプロキシ
git config --global http.proxy http://proxy.company.com:8080
git config --global https.proxy http://proxy.company.com:8080
# 認証が必要な場合
git config --global http.proxy http://username:password@proxy.company.com:8080
# プロキシ解除
git config --global --unset http.proxy
git config --global --unset https.proxy
SSL証明書の問題
企業の独自証明書:
# 証明書のパスを指定
git config --global http.sslCAInfo /path/to/certificate.pem
# 一時的に証明書検証を無効化(非推奨)
git config --global http.sslVerify false
⚠️ 警告:
sslVerify falseはセキュリティリスク- 一時的な対処のみに使用
- 問題解決後は必ず元に戻す
# 元に戻す
git config --global http.sslVerify true
トラブルシューティング:診断フロー
フローチャート
403エラーが発生
↓
┌────────────────────────┐
│エラーメッセージを確認 │
└────────────────────────┘
↓
├→ "password authentication was removed" → パスワード認証の廃止
│ → 個人アクセストークンを作成
│
├→ "Permission to user/repo.git denied" → 権限エラー
│ ├→ 自分のリポジトリ → トークンの権限を確認
│ └→ 他人のリポジトリ → Forkして作業
│
├→ "Your account is suspended" → アカウント停止
│ → GitHubサポートに連絡
│
└→ その他のメッセージ → 以下の診断を実行
診断コマンド
1. Git設定の確認
# すべての設定を表示
git config --list
# credential helperを確認
git config --get credential.helper
# リモートURLを確認
git remote -v
# ユーザー情報を確認
git config user.name
git config user.email
2. 接続テスト
HTTPSの場合:
# GitHubに接続できるか確認
curl -I https://github.com
# 認証情報付きでテスト
git ls-remote https://github.com/username/repo.git
SSHの場合:
# SSH接続テスト
ssh -T git@github.com
# 詳細なデバッグ情報
ssh -vT git@github.com
3. 認証情報の確認
Windows:
# 保存されている認証情報を確認
cmdkey /list | findstr git
Mac:
# キーチェーンの確認
security find-internet-password -s github.com
Linux:
# 保存されている認証情報を確認
cat ~/.git-credentials
段階的デバッグ
レベル1:基本確認
# 1. URLが正しいか
git remote -v
# 2. ネットワーク接続
ping github.com
# 3. 認証方式
git config --get credential.helper
レベル2:認証情報リセット
# 1. 認証情報を削除(OS別の方法を使用)
# 2. 新しいトークンを作成
# 3. 再度push
git push origin main
レベル3:詳細ログ
# HTTPSの詳細ログ
GIT_CURL_VERBOSE=1 git push origin main
# SSHの詳細ログ
GIT_SSH_COMMAND="ssh -vvv" git push origin main
よくある質問(FAQ)

Q1: トークンを作成したのに403エラーが出る
回答: トークンの権限が不足している可能性があります。
確認点:
- repoスコープがチェックされているか
- GitHub → Settings → Developer settings
- Personal access tokens
- 該当トークンを確認
- トークンを正しく入力しているか
- 先頭に空白がないか
- 全文字をコピーしたか
- トークンの有効期限
- 期限切れになっていないか
解決策:
- 新しいトークンを作成
repoスコープを必ず含める- 古いトークンを削除
Q2: パスワードを入力しても403エラーが出る
回答: パスワード認証は2021年8月に廃止されました。
正しい方法:
- 個人アクセストークンを作成
- パスワードの代わりにトークンを入力
注意:
- 「Password」と表示されますがトークンを入力してください
Q3: 以前は動いていたのに突然エラーが出る
回答: いくつかの原因が考えられます。
原因1:トークンの有効期限切れ
# 新しいトークンを作成
# 古い認証情報を削除
# 新しいトークンで再認証
原因2:リポジトリの権限変更
# リポジトリの設定を確認
# 必要に応じて管理者に連絡
原因3:GitHubアカウントの問題
# ブラウザでGitHubにログインできるか確認
# 2段階認証の設定を確認
Q4: SSHとHTTPS、どちらを使うべき?
回答: それぞれメリット・デメリットがあります。
HTTPSのメリット:
- 設定が簡単
- ファイアウォールを通過しやすい
- ポート443(一般的に開放されている)
HTTPSのデメリット:
- トークン管理が必要
- 有効期限がある
- 毎回認証が必要(credential helper未使用時)
SSHのメリット:
- 一度設定すれば永続的
- パスワード・トークン入力不要
- セキュリティが高い
SSHのデメリット:
- 初期設定がやや複雑
- 企業ネットワークでブロックされる場合がある
- ポート22(制限されている場合がある)
推奨:
- 個人利用: SSH
- 企業ネットワーク: HTTPS(まず試す)
- 初心者: HTTPS
Q5: 複数のGitHubアカウントを使い分けるには?
回答: SSH設定で使い分けるのが最も簡単です。
手順:
- アカウントごとにSSH鍵を作成
# 個人用
ssh-keygen -t ecdsa -b 521 -C "personal@email.com" -f ~/.ssh/id_ecdsa_personal
# 仕事用
ssh-keygen -t ecdsa -b 521 -C "work@company.com" -f ~/.ssh/id_ecdsa_work
- ~/.ssh/configを設定
# 個人用
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ecdsa_personal
# 仕事用
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ecdsa_work
- 使用方法
# 個人用
git clone git@github.com:personal-username/repo.git
# 仕事用
git clone git@github-work:company/repo.git
Q6: トークンを紛失しました
回答: トークンは再表示できません。
対処法:
- 古いトークンを削除
- GitHub → Settings → Developer settings
- Personal access tokens
- 該当トークンの「Delete」
- 新しいトークンを作成
- 前回と同じ権限で作成
- 今回は安全に保存
保存方法の推奨:
- パスワードマネージャー(1Password、LastPassなど)
- credential helperを使用
- 暗号化されたファイル
⚠️ 非推奨:
- 平文のテキストファイル
- GitHubのリポジトリ
- 共有ドライブ
Q7: 「Authentication failed」と403エラーの違いは?
回答: 微妙に意味が違います。
Authentication failed:
- 認証プロセス自体が失敗
- ユーザー名またはパスワード/トークンが間違っている
- トークンが無効または期限切れ
403 Forbidden:
- 認証は通った
- しかし権限が不足している
- リポジトリへのアクセス権がない
診断フロー:
Authentication failed
→ ユーザー名/トークンを確認
→ 新しいトークンを作成
403 Forbidden
→ 権限を確認
→ リポジトリの設定を確認
→ トークンのスコープを確認
Q8: Git Credential Managerとは?
回答: Microsoftが提供する認証情報管理ツールです。
機能:
- 自動的にトークンを管理
- Webブラウザで認証
- 2段階認証に対応
- トークンの自動更新
インストール:
- Windows: Git for Windowsに含まれる
- Mac/Linux: 別途インストールが必要
公式サイト:
https://github.com/git-ecosystem/git-credential-manager
メリット:
- トークンを手動で管理する必要がない
- より安全
- 使いやすい
Q9: プライベートリポジトリにアクセスできない
回答: いくつかの原因が考えられます。
原因1:招待されていない
# リポジトリの所有者に連絡
# 招待を依頼
原因2:招待を承認していない
# メールを確認
# 招待リンクをクリック
# または GitHub通知を確認
原因3:トークンの権限不足
# repoスコープを含むトークンが必要
# 新しいトークンを作成
確認方法:
- ブラウザでリポジトリにアクセスできるか
- アクセスできる場合 → トークンの問題
- アクセスできない場合 → 招待・権限の問題
Q10: 会社のネットワークで403エラーが出る
回答: 企業ネットワークの制限が原因の可能性があります。
可能性1:プロキシ
# プロキシ設定
git config --global http.proxy http://proxy.company.com:8080
git config --global https.proxy http://proxy.company.com:8080
可能性2:ファイアウォール
# HTTPSポート(443)は通常OK
# SSHポート(22)はブロックされている可能性
# HTTPSを使用
git remote set-url origin https://github.com/user/repo.git
可能性3:SSL証明書
# 会社の証明書を設定
git config --global http.sslCAInfo /path/to/company-cert.pem
対処:
- IT部門に相談
- 必要なドメイン・ポートの開放を依頼
- プロキシ設定を確認
予防策:403エラーを防ぐために
ベストプラクティス
1. 個人アクセストークンの管理
適切な有効期限:
短すぎる(30日) → 頻繁な更新が必要
長すぎる(無期限)→ セキュリティリスク
推奨:90日〜1年
用途別にトークンを分ける:
個人プロジェクト用
仕事用
CI/CD用
読み取り専用用
定期的な棚卸し:
月に1回、使っていないトークンを削除
2. credential helperの使用
設定推奨:
Windows:
git config --global credential.helper wincred
Mac:
git config --global credential.helper osxkeychain
Linux:
# キャッシュ(一時的)
git config --global credential.helper cache --timeout 3600
# ストア(永続的、暗号化なし)
git config --global credential.helper store
3. SSH認証の導入
推奨する理由:
- パスワード・トークン管理不要
- セキュリティが高い
- 一度設定すれば永続的
定期的なメンテナンス:
# 使っていない鍵を削除
# パスフレーズを変更
# 新しいアルゴリズムに更新
セキュリティのヒント
トークンの保管
✅ 良い例:
- パスワードマネージャー
- 暗号化されたファイル
- credential helper
❌ 悪い例:
- 平文のテキストファイル
- デスクトップのメモ
- メールで送信
- GitHubのリポジトリ
- Slackのメッセージ
トークンが漏洩したら
即座に実施:
- 該当トークンを削除
GitHub → Settings → Developer settings
→ Personal access tokens
→ Delete
- 新しいトークンを作成
- 影響範囲を確認
- どのリポジトリにアクセスされたか
- 不審なコミットがないか
- Settings → Security log
- パスワードを変更
- GitHubアカウントのパスワード
- 2段階認証を有効化
まとめ
403エラーの主な原因
- パスワード認証の廃止(最多)
- 2021年8月13日以降、パスワード認証は使用不可
- 個人アクセストークン(PAT)が必須
- 古い認証情報のキャッシュ
- Windows資格情報マネージャー
- Macキーチェーンアクセス
- Linuxの.git-credentials
- 権限不足
- リポジトリへのアクセス権がない
- トークンの権限(スコープ)が不足
- 組織のポリシー制限
基本的な解決手順
ステップ1:個人アクセストークンを作成
GitHub → Settings → Developer settings
→ Personal access tokens → Generate new token
→ repoスコープをチェック
ステップ2:古い認証情報を削除
Windows: 資格情報マネージャー
Mac: キーチェーンアクセス
Linux: ~/.git-credentials
ステップ3:新しいトークンで認証
git push origin main
Username: your-username
Password: ghp_xxxxxxxxxxxx ← トークン
推奨事項
短期的:
- 個人アクセストークンを作成
- credential helperを設定
- 定期的にトークンを更新
長期的:
- SSH認証に移行
- 複数アカウントの場合はSSH config設定
- セキュリティベストプラクティスを実践
最後に
Git 403エラーは、セキュリティ強化の結果として発生することが多いです。
最初は面倒に感じるかもしれませんが:
- トークンやSSH鍵は一度設定すれば長く使えます
- より安全な認証方式です
- 慣れれば簡単です
この記事の手順に従えば、ほとんどの403エラーは解決できます。
それでも解決しない場合は:
- GitHubサポートに問い合わせ
- GitHubコミュニティフォーラムで質問
- Stack Overflowで検索
安全で快適なGitライフを!
関連リンク:


コメント