xsshend 0.5.2

Simple CLI tool for uploading files to multiple SSH servers
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
# 📖 Guide d'utilisation de xsshend

> Guide complet pour maßtriser xsshend - Téléversement SSH simple et efficace via CLI

## 🎯 Vue d'ensemble

xsshend est un outil Rust moderne pour le téléversement de fichiers vers multiples serveurs SSH. Interface en ligne de commande simple avec filtrage avancé et suivi en temps réel des transferts.

## 🚀 Installation et configuration

### Installation via Cargo

```bash
cargo install xsshend
```

### Configuration initiale

```bash
# Initialisation assistée avec création du fichier hosts.json
xsshend init

# Forcer la réinitialisation si nécessaire
xsshend init --force
```

### PremiĂšre utilisation

```bash
# Lister les serveurs disponibles
xsshend list

# Aide générale
xsshend --help

# Aide sur une commande spécifique
xsshend upload --help
```

## ⚙ Configuration des serveurs

### Structure hiérarchique

xsshend organise les serveurs selon une structure Ă  3 niveaux :

```
Environment/
├── Region/
│   ├── Type/
│   │   ├── SERVER_NAME_1
│   │   └── SERVER_NAME_2
│   └── Type/
└── Region/
```

### Fichier hosts.json

Le fichier `~/.ssh/hosts.json` contient la configuration :

```json
{
  "Production": {
    "Region-A": {
      "Public": {
        "WEB_SERVER_01": {
          "alias": "web01@prod-web-01.example.com",
          "env": "PROD"
        },
        "API_SERVER_01": {
          "alias": "api01@prod-api-01.example.com",
          "env": "PROD"
        }
      },
      "Private": {
        "DATABASE_01": {
          "alias": "db01@prod-db-01.example.com",
          "env": "PROD"
        }
      }
    }
  },
  "Staging": {
    "Region-A": {
      "Public": {
        "STAGE_WEB_01": {
          "alias": "web01@stage-web-01.example.com",
          "env": "STAGE"
        }
      }
    }
  },
  "Development": {
    "Local": {
      "Services": {
        "DEV_DATABASE": {
          "alias": "dev@dev-db.local.example.com",
          "env": "DEV"
        }
      }
    }
  }
}
```

## 🎼 Utilisation CLI

### Commandes principales

#### Initialisation
```bash
xsshend init           # Configuration assistée
xsshend init --force   # Réinitialisation complÚte
```

#### Liste des serveurs
```bash
xsshend list           # Affichage hiérarchique avec filtres CLI
xsshend --list         # Forme courte
```

#### Téléversement de fichiers
```bash
xsshend upload <FILES>... [OPTIONS]
```

### Options de filtrage

#### Par environnement
```bash
xsshend upload config.json --env Production
xsshend upload app.jar --env Staging
xsshend upload debug.log --env Development
```

#### Par région
```bash
xsshend upload regional-config.json --region Region-A
xsshend upload backup.tar --region Region-B
```

#### Par type de serveur
```bash
xsshend upload public-config.json --type Public
xsshend upload db-script.sql --type Private
```

#### Filtrage combiné
```bash
# Environnement + Région
xsshend upload config.json --env Production --region Region-A

# Environnement + Type
xsshend upload app.war --env Production --type Public

# Région + Type
xsshend upload local-config.json --region Region-A --type Private

# Tous les filtres
xsshend upload deploy.sh --env Production --region Region-A --type Public
```

### Gestion des destinations

```bash
# Destination par défaut (/tmp/)
xsshend upload file.txt --env Production

# Destination personnalisée
xsshend upload app.war --env Production --dest /opt/tomcat/webapps/
xsshend upload config.json --env Staging --dest /etc/myapp/
xsshend upload logs/ --env Development --dest /var/log/myapp/
```

### Mode simulation (dry-run)

```bash
# Simulation complÚte sans transfert réel
xsshend upload deploy.sh --env Production --dry-run

# Vérification des serveurs ciblés
xsshend upload app.jar --env Production --region Region-A --dry-run

# Test avec filtrage complexe
xsshend upload config.json --env Production --type Public --dry-run
```

## 📊 Interface de progression

### Affichage en temps réel

Les transferts montrent une progression détaillée :

```
🚀 DĂ©but du tĂ©lĂ©versement: 1 fichier(s) vers 3 serveur(s)
📂 Destination: /opt/uploads/
🎯 Serveurs ciblĂ©s:
   ‱ Production:Region-A:Public:WEB_SERVER_01 → web01@prod-web-01.example.com (PROD)
   ‱ Production:Region-A:Public:API_SERVER_01 → api01@prod-api-01.example.com (PROD)
   ‱ Production:Region-A:Private:DATABASE_01 → db01@prod-db-01.example.com (PROD)

đŸ“€ TĂ©lĂ©versement de ./myapp.jar en cours...

web01@prod-web-01... [████████████████████████████████] 2.3MB/2.3MB ✅
api01@prod-api-01... [██████████████████              ] 1.5MB/2.3MB ⏳
db01@prod-db-01..... [████████████████████████████     ] 2.1MB/2.3MB ⏳

✅ TĂ©lĂ©versement terminĂ© avec succĂšs!
📊 3 serveur(s) - 0 Ă©chec(s)
```

### Gestion des erreurs

En cas d'erreur, xsshend affiche des détails précis :

```
❌ Échec de connexion: WEB_SERVER_02
   Erreur: Connection refused (port 22)
   Conseil: Vérifier que le serveur est accessible

✅ TĂ©lĂ©versement partiel terminĂ©
📊 2/3 serveur(s) rĂ©ussis - 1 Ă©chec(s)
```

## 🔑 Gestion des clĂ©s SSH

### Découverte automatique

xsshend détecte automatiquement les clés SSH :

- **Ed25519** : `~/.ssh/id_ed25519` (priorité 1)
- **RSA** : `~/.ssh/id_rsa` (priorité 2)
- **ECDSA** : `~/.ssh/id_ecdsa` (priorité 3)
- **DSA** : `~/.ssh/id_dsa` (priorité 4)

### Intégration ssh-agent

Si aucune clé n'est trouvée ou accessible, xsshend utilise ssh-agent :

```bash
# Vérifier les clés chargées
ssh-add -l

# Ajouter une clé
ssh-add ~/.ssh/id_ed25519

# Démarrer ssh-agent si nécessaire
eval $(ssh-agent)
```

## 📝 Exemples d'utilisation

### Déploiement d'application

```bash
# Déploiement complet en production
xsshend upload myapp.war --env Production --dest /opt/tomcat/webapps/

# Mise Ă  jour de configuration
xsshend upload application.properties --env Production --dest /etc/myapp/

# Déploiement sur serveurs publics seulement
xsshend upload static-files/ --env Production --type Public --dest /var/www/
```

### Gestion par environnement

```bash
# Configuration de développement
xsshend upload dev-config.json --env Development

# Test en staging
xsshend upload app-v2.jar --env Staging --dry-run

# Déploiement production avec validation
xsshend upload production-app.war --env Production --dry-run
xsshend upload production-app.war --env Production  # Si OK
```

### Maintenance et logs

```bash
# Copie de logs pour analyse
xsshend upload analyze-script.py --env Production --type Private

# Sauvegarde de configuration
xsshend upload backup-script.sh --env Production --region Region-A

# Mise à jour de sécurité
xsshend upload security-patch.sh --env Production --dry-run  # Test
xsshend upload security-patch.sh --env Production          # Application
```

### Multi-fichiers et répertoires

```bash
# Plusieurs fichiers
xsshend upload config.json app.jar deploy.sh --env Production

# Contenu d'un répertoire
xsshend upload static-files/ --env Production --type Public

# Mix fichiers et répertoires
xsshend upload app.war config/ scripts/ --env Staging
```

## 🔍 Commandes de diagnostic

### Liste détaillée des serveurs

```bash
# Vue complĂšte avec filtres CLI
xsshend list
```

Sortie exemple :
```
🔍 Liste des cibles SSH disponibles:

📁 Production (--env Production)
  📂 Region-A (--region Region-A)
    📂 Public (--type Public)
      đŸ–„ïž  WEB_SERVER_01 → web01@prod-web-01.example.com (PROD)
      đŸ–„ïž  API_SERVER_01 → api01@prod-api-01.example.com (PROD)
    📂 Private (--type Private)
      đŸ—„ïž  DATABASE_01 → db01@prod-db-01.example.com (PROD)

📁 Staging (--env Staging)
  📂 Region-A (--region Region-A)
    📂 Public (--type Public)
      đŸ–„ïž  STAGE_WEB_01 → web01@stage-web-01.example.com (STAGE)

📊 Total: 4 cibles disponibles

💡 Exemples d'utilisation:
   xsshend upload --env Production file.txt
   xsshend upload --env Staging --region Region-A file.txt
   xsshend upload --region Region-A --type Public file.txt
```

### Validation de configuration

```bash
# Test avec dry-run pour valider la configuration
xsshend upload test.txt --env Production --dry-run

# Test sur un serveur spécifique avec SSH manuel
ssh web01@prod-web-01.example.com "echo 'Test connection OK'"
```

## đŸ› ïž Conseils et bonnes pratiques

### Organisation des serveurs

1. **Environnements** : Production, Staging, Development, Testing
2. **Régions** : Region-A, Region-B, US-East, EU-West...
3. **Types** : Public, Private, Database, Cache, Load-Balancer

### Workflow recommandé

1. **Test** : Toujours utiliser `--dry-run` d'abord
2. **Staging** : Tester sur environnement de staging
3. **Production** : Déployer par étapes (région par région)

### Sécurité

- Utiliser des clés SSH Ed25519 de préférence
- Éviter les mots de passe, privilĂ©gier ssh-agent
- Valider les permissions des fichiers de configuration

### Performance

- Grouper les fichiers pour réduire les connexions SSH
- Utiliser le mode dry-run pour valider avant transfert
- Organiser la configuration pour un filtrage efficace

## đŸš« DĂ©pannage

### ProblĂšmes de connexion SSH

```bash
# Test manuel de connexion
ssh -v web01@prod-web-01.example.com

# Vérification des clés
ssh-add -l

# Ajout de clé si nécessaire
ssh-add ~/.ssh/id_ed25519
```

### Configuration

```bash
# Réinitialiser la configuration
xsshend init --force

# Vérifier les permissions .ssh
ls -la ~/.ssh/
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_*
```

### Logs et debug

```bash
# Mode verbeux
RUST_LOG=debug xsshend upload file.txt --env Production

# Logs trÚs détaillés
RUST_LOG=trace xsshend upload file.txt --env Production
```