Master Gitea SSH: The Ultimate Guide to Local & GitHub Repository Cloning
This comprehensive tutorial guides you through configuring Gitea and your local machine for secure cloning, pushing, and pulling repositories using SSH, covering both local repositories hosted on your Raspberry Pi and repositories mirrored from GitHub.
Blog Title Options
If you plan to publish this guide, here are several strong title options:
- Master Gitea SSH: The Ultimate Guide to Local & GitHub Repository Cloning
- Secure Git Hosting: Set Up Gitea SSH for Seamless Local and Remote Pushes
- No More Passwords: Configure SSH Keys for Gitea & GitHub Git Workflow
1. Prerequisites
Before starting, ensure the following are true:
- Gitea is installed and running (with the SSH port, e.g.,
222, exposed). - Your Gitea user account is created.
- Git is installed on your local machine.
2. Decide and Prepare Your SSH Key 🔑
You need a key pair to authenticate with Gitea. You can either use a key you already have or create a new one specifically for Gitea.
Option A: Use an Existing Key (e.g., ~/.ssh/id_ed25519)
If you already use a default key for services like GitHub, you can reuse it.
- Identify your public key file. This is usually
~/.ssh/id_ed25519.pubor~/.ssh/id_rsa.pub. - Make a note of the file's exact name (e.g.,
id_ed25519). You will need this name in the SSH Configuration step.
Option B: Create a New Key with a Custom Name (Recommended)
Creating a dedicated key avoids conflicts and simplifies management. This example uses id_gitea_raspi_key.
-
Open your local terminal (Git Bash on Windows, Terminal on Linux/macOS).
-
Run the key generation command, using the
-fflag to specify the custom file name:ssh-keygen -t ed25519 -C "your_email@example.com-gitea-raspi" -f ~/.ssh/id_gitea_raspi_keyWhen prompted for a Passphrase, enter a secure one.
This command creates two new files in your ~/.ssh/ directory: the private key (id_gitea_raspi_key) and the public key (id_gitea_raspi_key.pub).
3. Upload SSH Public Key to Gitea 📤
You must upload the content of the public key file (.pub) to your Gitea profile.
-
Copy the public key content. Replace
YOUR_KEY_NAMEwith the name you chose in Step 2 (e.g.,id_ed25519.puborid_gitea_raspi_key.pub):cat ~/.ssh/YOUR_KEY_NAME.pub -
Access Gitea: Log into your Gitea instance in your browser.
-
Navigate to your Profile Settings > SSH / GPG Keys.
-
Click the "Add Key" button.
-
Title: Give the key a name (e.g.,
Laptop Gitea Key). -
Content: Paste the entire content copied in step 1 into the text box.
-
Click "Add Key".
4. Local SSH Configuration (The ~/.ssh/config file)
Since your Gitea server uses a non-standard port (222), you must create an entry in your local ~/.ssh/config file. This allows you to use a simple nickname in your Git commands.
-
Open or create the configuration file:
~/.ssh/config -
Add the following block, ensuring the
IdentityFileline points to the private key file you decided to use in Step 2:Host gitea-server
HostName [YOUR_RASPBERRY_PI_IP]
Port 222
User git
# Point to your chosen PRIVATE key file (no .pub extension)
IdentityFile ~/.ssh/YOUR_PRIVATE_KEY_NAME
StrictHostKeyChecking noExample: If you used Option B, the line would be:
IdentityFile ~/.ssh/id_gitea_raspi_key -
Save and close the file.
Testing the Gitea SSH Connection
Test the connection using the nickname you just created:
ssh -T gitea-server
You should see a welcome message similar to: Hi your_username! You've successfully authenticated...
5. Cloning and Uploading Repositories 🚀
A. Cloning a Gitea Repository
Use your new configuration nickname to simplify the clone command:
# Simplified link using the 'Host' nickname from your config
git clone gitea-server:username/repo-name.git
B. Mirroring a GitHub Repository to Gitea via SSH
This process copies a remote GitHub repository to your local Gitea instance.
-
Create an Empty Repo on Gitea: First, create an empty repository with the desired name on your Gitea web interface.
-
Clone the GitHub repository (using the
--bareoption is best for mirroring):git clone --bare git@github.com:original-user/repo.git
cd repo.git -
Change the Remote Origin (to point to your Gitea server using the SSH nickname):
git remote set-url origin gitea-server:your-gitea-username/repo-name.git -
Push the entire repository to Gitea:
git push --mirrorThis command pushes all branches, tags, and history to your new Gitea repository.