Files
michaelschiemer/docs/deployment/SSH-MAKEFILE-COMMANDS.md
Michael Schiemer 24cbbccf4c feat: update deployment configuration and encrypted env loader
- Update Ansible playbooks and roles for application deployment
- Add new Gitea/Traefik troubleshooting playbooks
- Update Docker Compose configurations (base, local, staging, production)
- Enhance EncryptedEnvLoader with improved error handling
- Add deployment scripts (autossh setup, migration, secret testing)
- Update CI/CD workflows and documentation
- Add Semaphore stack configuration
2025-11-02 20:38:06 +01:00

320 lines
6.3 KiB
Markdown

# SSH Makefile-Befehle
**Datum**: 2025-11-02
**Status**: ? Verf?gbar
**Zweck**: Einfache SSH-Verbindungen ?ber Makefile-Befehle
---
## ?bersicht
Das Projekt bietet Makefile-Befehle f?r SSH-Verbindungen zum Production- und Git-Server. Diese nutzen die konfigurierte SSH-Config (`~/.ssh/config`) und autossh f?r persistente Verbindungen.
---
## Verf?gbare Befehle
### `make ssh` oder `make ssh-production`
?ffnet eine SSH-Verbindung zum Production-Server.
```bash
make ssh
```
**Was passiert:**
- Nutzt die SSH-Config (`~/.ssh/config`) mit dem `production` Host
- Verbindet zu `94.16.110.151` als User `deploy`
- Nutzt den SSH-Schl?ssel `~/.ssh/production`
- Keep-Alive aktiviert (ServerAliveInterval 60)
**Beispiel:**
```bash
$ make ssh
?? Verbinde zum Production-Server...
Welcome to Ubuntu...
deploy@production:~$
```
---
### `make ssh-git`
?ffnet eine SSH-Verbindung zum Git-Server.
```bash
make ssh-git
```
**Was passiert:**
- Nutzt die SSH-Config mit dem `git.michaelschiemer.de` Host
- Verbindet zu `git.michaelschiemer.de` Port 2222 als User `git`
- Nutzt den SSH-Schl?ssel `~/.ssh/git_michaelschiemer`
---
### `make ssh-status`
Pr?ft den Status der autossh-Services.
```bash
make ssh-status
```
**Ausgabe:**
```bash
?? Pr?fe autossh Service-Status...
? autossh-production.service - AutoSSH for production
Loaded: loaded (/home/michael/.config/systemd/user/autossh-production.service; enabled; preset: enabled)
Active: active (running) since Sun 2025-11-02 18:21:06 CET
Main PID: 35533 (autossh)
Tasks: 2 (limit: 14999)
Memory: 1.8M
michael 35533 0.0 0.0 2484 1536 ? Ss 18:21 0:00 /usr/lib/autossh/autossh -M 20000 -N -o ServerAliveInterval=60 -o ServerAliveCountMax=3 production
```
---
### `make ssh-logs`
Zeigt die Logs der autossh-Services an.
```bash
make ssh-logs
```
**Ausgabe:**
```bash
?? Zeige autossh Logs...
Nov 02 18:21:06 Mike-PC systemd[19787]: Started autossh-production.service - AutoSSH for production.
Nov 02 18:21:06 Mike-PC autossh[35533]: short poll time: adjusting net timeouts to 5000
Nov 02 18:21:06 Mike-PC autossh[35533]: starting ssh (count 1)
Nov 02 18:21:06 Mike-PC autossh[35533]: ssh child pid is 35537
```
**F?r Live-Logs:**
```bash
journalctl --user -u autossh-production.service -f
```
---
### `make setup-autossh`
Richtet autossh f?r persistente SSH-Verbindungen ein.
```bash
make setup-autossh
```
**Was passiert:**
- F?hrt das Setup-Script aus (`scripts/setup-autossh.sh both`)
- Erweitert SSH-Config mit Keep-Alive-Optionen
- Erstellt systemd Services f?r Production- und Git-Server
- Testet SSH-Verbindungen
**Siehe auch:** `docs/deployment/AUTOSSH-SETUP.md`
---
## SSH-Config
Die Makefile-Befehle nutzen die SSH-Config (`~/.ssh/config`):
### Production-Server
```ssh-config
Host production
HostName 94.16.110.151
User deploy
IdentityFile ~/.ssh/production
ServerAliveInterval 60
ServerAliveCountMax 3
TCPKeepAlive yes
Compression yes
StrictHostKeyChecking accept-new
```
### Git-Server
```ssh-config
Host git.michaelschiemer.de
HostName git.michaelschiemer.de
Port 2222
User git
IdentityFile ~/.ssh/git_michaelschiemer
ServerAliveInterval 60
ServerAliveCountMax 3
TCPKeepAlive yes
Compression yes
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
```
---
## Erweiterte Nutzung
### SSH mit zus?tzlichen Befehlen
Du kannst auch direkt `ssh` mit zus?tzlichen Befehlen verwenden:
```bash
# Remote-Befehl ausf?hren
ssh production "docker ps"
# SSH-Tunnel erstellen
ssh production -L 8080:localhost:80 -N
# Datei kopieren (SCP)
scp production:/path/to/file ./local-file
# Datei hochladen
scp ./local-file production:/path/to/file
```
### Mit dem Production-Server arbeiten
```bash
# Docker-Container Status pr?fen
make ssh
# Dann im SSH:
docker ps
cd /var/www/html && docker compose ps
# Logs anzeigen
cd ~/deployment/stacks/application && docker compose logs -f
```
---
## Troubleshooting
### SSH-Verbindung schl?gt fehl
**Problem**: `make ssh` verbindet nicht
**L?sung**:
1. Pr?fe SSH-Config:
```bash
cat ~/.ssh/config | grep -A 10 "Host production"
```
2. Teste Verbindung manuell:
```bash
ssh -v production
```
3. Pr?fe SSH-Schl?ssel:
```bash
ls -la ~/.ssh/production
```
4. Teste mit IP-Adresse:
```bash
ssh -i ~/.ssh/production deploy@94.16.110.151
```
### Autossh l?uft nicht
**Problem**: `make ssh-status` zeigt Service als inaktiv
**L?sung**:
1. Service starten:
```bash
systemctl --user start autossh-production.service
```
2. Service aktivieren:
```bash
systemctl --user enable autossh-production.service
```
3. Autossh neu einrichten:
```bash
make setup-autossh
```
### Verbindung bricht regelm??ig ab
**Problem**: SSH-Verbindung bricht auch mit autossh ab
**L?sung**:
1. Pr?fe autossh Status:
```bash
make ssh-status
```
2. Pr?fe Logs:
```bash
make ssh-logs
```
3. Teste Keep-Alive:
```bash
ssh -o ServerAliveInterval=30 -o ServerAliveCountMax=10 production
```
---
## Weitere SSH-Befehle im Makefile
Es gibt weitere SSH-bezogene Befehle im Makefile:
```bash
# Production-Container neu starten
make restart-production
# Production-Logs anzeigen
make logs-production
make logs-staging
# Production-Status pr?fen
make status-production
```
**Siehe auch:** `make help` f?r alle verf?gbaren Befehle
---
## Best Practices
1. **Nutze `make ssh` statt direkter SSH-Befehle**:
Dies stellt sicher, dass die korrekte Konfiguration verwendet wird.
2. **Pr?fe regelm??ig den autossh-Status**:
```bash
make ssh-status
```
3. **Nutze SSH-Config statt direkter IPs**:
Nutze `ssh production` statt `ssh deploy@94.16.110.151`
4. **Pr?fe Logs bei Problemen**:
```bash
make ssh-logs
```
---
## Referenzen
- **Autossh Setup**: `docs/deployment/AUTOSSH-SETUP.md`
- **Autossh Setup Abgeschlossen**: `docs/deployment/AUTOSSH-SETUP-COMPLETED.md`
- **Setup-Script**: `scripts/setup-autossh.sh`
- **SSH-Config**: `~/.ssh/config`
- **Makefile**: `Makefile`
---
## Zusammenfassung
? Makefile-Befehle f?r SSH-Verbindungen verf?gbar
? Einfache Verbindung zum Production-Server: `make ssh`
? Service-Status pr?fen: `make ssh-status`
? Logs anzeigen: `make ssh-logs`
? Autossh einrichten: `make setup-autossh`
Alle Befehle nutzen die konfigurierte SSH-Config und autossh f?r persistente Verbindungen.