# '403 Forbidden' error message when pushing to a GitHub repository

> Fix '403 Forbidden' errors when pushing to GitHub over HTTPS by using a personal access token or switching to SSH.

Source: https://helpcenter.ruachost.com/developers/version-control/403-forbidden-error-message-when-pushing-to-a-github-repository/

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

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)

To fix this, you must use a **Personal Access Token (PAT)** instead of your password.

### Step 1: Generate your GitHub Token

1. Log in to GitHub and navigate to **Settings** → **Developer Settings**.
2. Select **Personal Access Tokens** → **Tokens (classic)**.
3. Click **Generate new token**. Ensure you check the **`repo`** scope.
4. **Copy the token.** (You will not be able to see it again).

### 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 URL
git config -l | grep url

# Update the URL to include your GitHub username
# Replace 'your-username' and 'your-repo' with your actual info
git remote set-url origin "https://your-username@github.com/your-username/your-repo.git"
```

### Step 3: Push Using the Token

When you push your changes, Ruachost will prompt you for a password:

```
git push origin main
```

**CRITICAL:** 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)

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

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'
```
