'403 Forbidden' error message when pushing to a GitHub repository
Resolving GitHub ‘403 Forbidden’ Errors (HTTPS)
Section titled “Resolving GitHub ‘403 Forbidden’ Errors (HTTPS)”If you are trying to push code to a GitHub repository from a ruachost.com server and receiving a 403 Forbidden error, follow this guide to fix your authentication settings.
The Problem
Section titled “The Problem”When pushing changes using an HTTPS URL from your RuacHost terminal, you may see: error: The requested URL returned error: 403 Forbidden while accessing https://github.com/user/repo.git/info/refs
The Cause: GitHub no longer accepts your standard account password for Git operations. Additionally, some server environments on RuacHost require a specific URL format to trigger the authentication prompt correctly.
Method 1: The Modern HTTPS Fix (Recommended for Beginners)
Section titled “Method 1: The Modern HTTPS Fix (Recommended for Beginners)”To fix this, you must use a Personal Access Token (PAT) instead of your password.
Step 1: Generate your GitHub Token
Section titled “Step 1: Generate your GitHub Token”- Log in to GitHub and navigate to Settings → Developer Settings.
- Select Personal Access Tokens → Tokens (classic).
- Click Generate new token. Ensure you check the
reposcope. - Copy the token. (You will not be able to see it again).
Step 2: Update the Remote URL on RuacHost
Section titled “Step 2: Update the Remote URL on RuacHost”Log in to your RuacHost account via SSH, navigate to your project directory, and run:
# Verify your current remote URLgit config -l | grep url
# Update the URL to include your GitHub username# Replace 'your-username' and 'your-repo' with your actual infogit remote set-url origin "https://your-username@github.com/your-username/your-repo.git"Step 3: Push Using the Token
Section titled “Step 3: Push Using the Token”When you push your changes, Ruachost will prompt you for a password:
git push origin mainCRITICAL: When prompted for a Password, do NOT enter your GitHub login password. Instead, paste the Personal Access Token you generated in Step 1.
Method 2: The “Set and Forget” Fix (SSH)
Section titled “Method 2: The “Set and Forget” Fix (SSH)”SSH is often preferred for RuacHost servers because it avoids the need for tokens or passwords entirely.
| Step | Action |
|---|---|
| 1. Generate Key | Run ssh-keygen -t ed25519 on your RuacHost server. |
| 2. Add to GitHub | Copy the content of ~/.ssh/id_ed25519.pub to your GitHub SSH Settings. |
| 3. Change Remote | Update your origin: git remote set-url origin git@github.com:username/repo.git |
Pro-Tip for Ruachost Users
Section titled “Pro-Tip for Ruachost Users”If you are tired of pasting your token every time on RuacHost, you can tell Git to cache your credentials for a specific duration:
# This saves your token for 2 hours (7200 seconds)git config --global credential.helper 'cache --timeout=7200'