Add SSH setup guide for Gitea authentication
- Step-by-step instructions for key generation - How to add public key to Gitea - Testing SSH connection - Integration with init-project workflow - Troubleshooting tips
This commit is contained in:
106
SSH-SETUP.md
Normal file
106
SSH-SETUP.md
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
# SSH Setup for Gitea
|
||||||
|
|
||||||
|
To push code to Gitea from your VPS, you need to set up SSH authentication.
|
||||||
|
|
||||||
|
## Generate SSH Key
|
||||||
|
|
||||||
|
On your VPS, run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N ""
|
||||||
|
```
|
||||||
|
|
||||||
|
This creates:
|
||||||
|
- `~/.ssh/id_ed25519` (private key)
|
||||||
|
- `~/.ssh/id_ed25519.pub` (public key)
|
||||||
|
|
||||||
|
## Add Public Key to Gitea
|
||||||
|
|
||||||
|
1. Display your public key:
|
||||||
|
```bash
|
||||||
|
cat ~/.ssh/id_ed25519.pub
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Copy the output (entire line starting with `ssh-ed25519`)
|
||||||
|
|
||||||
|
3. Go to Gitea: http://100.120.125.113:3000/user/settings/keys
|
||||||
|
|
||||||
|
4. Click "Add Key"
|
||||||
|
|
||||||
|
5. Paste your public key
|
||||||
|
|
||||||
|
6. Click "Add Key"
|
||||||
|
|
||||||
|
## Test SSH Connection
|
||||||
|
|
||||||
|
Verify it works:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ssh -T git@100.120.125.113
|
||||||
|
```
|
||||||
|
|
||||||
|
You should see a message like:
|
||||||
|
```
|
||||||
|
Hi pdm! You've successfully authenticated, but Gitea does not provide shell access.
|
||||||
|
```
|
||||||
|
|
||||||
|
## Using SSH with Git
|
||||||
|
|
||||||
|
When you `init-project`, it automatically sets up SSH remotes:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
init-project my-app
|
||||||
|
cd my-app
|
||||||
|
git remote -v
|
||||||
|
# Should show: origin git@100.120.125.113:pdm/my-app.git (fetch)
|
||||||
|
```
|
||||||
|
|
||||||
|
Now when you push:
|
||||||
|
```bash
|
||||||
|
git push origin main
|
||||||
|
```
|
||||||
|
|
||||||
|
No password needed - SSH key handles authentication!
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
**SSH key not being used:**
|
||||||
|
```bash
|
||||||
|
# Check SSH agent is running
|
||||||
|
eval "$(ssh-agent -s)"
|
||||||
|
|
||||||
|
# Add your key
|
||||||
|
ssh-add ~/.ssh/id_ed25519
|
||||||
|
```
|
||||||
|
|
||||||
|
**Still getting authentication errors:**
|
||||||
|
1. Verify key is in Gitea (http://100.120.125.113:3000/user/settings/keys)
|
||||||
|
2. Check file permissions: `chmod 600 ~/.ssh/id_ed25519`
|
||||||
|
3. Test connection: `ssh -T git@100.120.125.113`
|
||||||
|
|
||||||
|
**Need different key per VPS:**
|
||||||
|
Generate separate keys:
|
||||||
|
```bash
|
||||||
|
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_vps-name -N ""
|
||||||
|
```
|
||||||
|
|
||||||
|
Add to Gitea with a descriptive name (e.g., "vps-name-key")
|
||||||
|
|
||||||
|
## One-Time Setup Script
|
||||||
|
|
||||||
|
To automate this on a new VPS:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
# Auto-setup SSH for Gitea
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N ""
|
||||||
|
echo ""
|
||||||
|
echo "✅ SSH key generated!"
|
||||||
|
echo "Add this to Gitea (http://100.120.125.113:3000/user/settings/keys):"
|
||||||
|
cat ~/.ssh/id_ed25519.pub
|
||||||
|
echo ""
|
||||||
|
echo "Test with: ssh -T git@100.120.125.113"
|
||||||
|
```
|
||||||
|
|
||||||
|
Save as `~/.homelab-scripts/setup-ssh.sh` and run: `bash ~/.homelab-scripts/setup-ssh.sh`
|
||||||
Reference in New Issue
Block a user