ufw est dans /usr/sbin/ qui n'est pas dans le PATH utilisateur. Sans sudo, bash affiche "command not found" au lieu d'erreur de permissions. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
479 lines
8.7 KiB
Markdown
479 lines
8.7 KiB
Markdown
# Setup VPS rapide
|
|
|
|
Configuration sécurisée d'un VPS en 30-45 minutes.
|
|
|
|
**Vous voulez comprendre en détail ?** → [vps-setup-complet.md](vps-setup-complet.md)
|
|
|
|
---
|
|
|
|
## 🎯 Vue d'ensemble
|
|
|
|
```
|
|
1. Connexion SSH (5 min)
|
|
2. Mises à jour (5 min)
|
|
3. Utilisateur (5 min) - Type A uniquement
|
|
4. Clés SSH (10 min)
|
|
5. Sécuriser SSH (5 min)
|
|
6. Pare-feu UFW (5 min)
|
|
7. Fail2ban (5 min)
|
|
8. Mises à jour auto (5 min)
|
|
9. Apache (5 min)
|
|
10. SSL (Let's Encrypt) (5 min)
|
|
────────────────────────────────
|
|
Total: 30-50 min
|
|
```
|
|
|
|
---
|
|
|
|
## Prérequis
|
|
|
|
- VPS avec IP publique
|
|
- Terminal (macOS/Linux)
|
|
- [Vim basics](linux-essentials/vim-guide-essentiel.md) : `i` pour éditer, `Esc :wq` pour sauvegarder
|
|
|
|
**Types d'accès :**
|
|
- **Type A** (OVH, Hetzner) : accès `root` direct
|
|
- **Type B** (Infomaniak) : utilisateur `debian`/`ubuntu` avec sudo → **Sautez étape 3**
|
|
|
|
---
|
|
|
|
## 1. Première connexion (5 min)
|
|
|
|
```bash
|
|
# Type A
|
|
ssh root@IP-DU-VPS
|
|
|
|
# Type B
|
|
ssh debian@IP-DU-VPS # ou ubuntu, admin selon l'hébergeur
|
|
```
|
|
|
|
**Type A seulement - Changer le mot de passe root :**
|
|
```bash
|
|
passwd # Mot de passe fort (20+ caractères)
|
|
```
|
|
|
|
---
|
|
|
|
## 2. Mises à jour (5 min)
|
|
|
|
```bash
|
|
# Type A
|
|
apt update && apt upgrade -y && apt autoremove -y
|
|
|
|
# Type B
|
|
sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y
|
|
```
|
|
|
|
---
|
|
|
|
## 3. Créer un utilisateur (5 min)
|
|
|
|
**⚠️ Type B : SAUTEZ cette étape**
|
|
|
|
**Type A uniquement :**
|
|
|
|
```bash
|
|
# Créer l'utilisateur (remplacez "monuser")
|
|
adduser monuser
|
|
|
|
# Ajouter au groupe sudo
|
|
usermod -aG sudo monuser
|
|
|
|
# Vérifier
|
|
groups monuser # Doit afficher : monuser sudo
|
|
```
|
|
|
|
---
|
|
|
|
## 4. Clés SSH (10 min)
|
|
|
|
**Sur votre machine locale :**
|
|
|
|
```bash
|
|
# Vérifier si vous avez déjà une clé
|
|
ls ~/.ssh/id_*.pub
|
|
|
|
# Si non, créer une clé
|
|
ssh-keygen -t ed25519 -C "votre-email@example.com"
|
|
# Appuyez sur Entrée 3 fois
|
|
|
|
# Afficher la clé
|
|
cat ~/.ssh/id_ed25519.pub
|
|
# Copiez la ligne complète
|
|
```
|
|
|
|
**Sur le VPS :**
|
|
|
|
```bash
|
|
# Type A - passer à votre utilisateur
|
|
su - monuser
|
|
|
|
# Type B - déjà votre utilisateur
|
|
|
|
# Créer le dossier .ssh
|
|
mkdir -p ~/.ssh && chmod 700 ~/.ssh
|
|
|
|
# Ajouter la clé
|
|
vim ~/.ssh/authorized_keys
|
|
# Appuyez sur 'i', collez la clé, Esc puis :wq
|
|
|
|
# Droits
|
|
chmod 600 ~/.ssh/authorized_keys
|
|
|
|
# Type A - retour à root
|
|
exit
|
|
```
|
|
|
|
**Tester (nouveau terminal) :**
|
|
|
|
```bash
|
|
ssh monuser@IP-DU-VPS # Doit marcher SANS mot de passe
|
|
```
|
|
|
|
---
|
|
|
|
## 5. Sécuriser SSH (5 min)
|
|
|
|
```bash
|
|
# Éditer la config
|
|
# Type A
|
|
vim /etc/ssh/sshd_config
|
|
|
|
# Type B
|
|
sudo vim /etc/ssh/sshd_config
|
|
```
|
|
|
|
**Modifier ces lignes :**
|
|
|
|
```
|
|
PermitRootLogin no
|
|
PasswordAuthentication no
|
|
```
|
|
|
|
**Redémarrer SSH :**
|
|
|
|
```bash
|
|
# Type A
|
|
systemctl restart sshd
|
|
|
|
# Type B
|
|
sudo systemctl restart sshd
|
|
```
|
|
|
|
**⚠️ IMPORTANT : Tester dans un NOUVEAU terminal avant de fermer l'ancien !**
|
|
|
|
```bash
|
|
ssh monuser@IP-DU-VPS # Doit marcher
|
|
```
|
|
|
|
---
|
|
|
|
## 6. Pare-feu UFW (5 min)
|
|
|
|
```bash
|
|
# Type A (root)
|
|
apt install ufw -y
|
|
sudo ufw default deny incoming
|
|
sudo ufw default allow outgoing
|
|
sudo ufw allow 22/tcp
|
|
sudo ufw allow 80/tcp
|
|
sudo ufw allow 443/tcp
|
|
sudo ufw enable
|
|
sudo ufw status verbose
|
|
|
|
# Type B (utilisateur sudo)
|
|
sudo apt install ufw -y
|
|
sudo ufw default deny incoming
|
|
sudo ufw default allow outgoing
|
|
sudo ufw allow 22/tcp
|
|
sudo ufw allow 80/tcp
|
|
sudo ufw allow 443/tcp
|
|
sudo ufw enable
|
|
sudo ufw status verbose
|
|
```
|
|
|
|
**💡 Note :** `ufw` nécessite toujours `sudo` (même en root) car il est dans `/usr/sbin/`
|
|
|
|
---
|
|
|
|
## 7. Fail2ban (5 min)
|
|
|
|
```bash
|
|
# Installer
|
|
# Type A
|
|
apt install fail2ban -y
|
|
|
|
# Type B
|
|
sudo apt install fail2ban -y
|
|
|
|
# Configuration minimale
|
|
# Type A
|
|
cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
|
|
vim /etc/fail2ban/jail.local
|
|
|
|
# Type B
|
|
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
|
|
sudo vim /etc/fail2ban/jail.local
|
|
```
|
|
|
|
**Dans le fichier, trouver et vérifier :**
|
|
|
|
```ini
|
|
[DEFAULT]
|
|
bantime = 600
|
|
findtime = 600
|
|
maxretry = 5
|
|
|
|
[sshd]
|
|
enabled = true
|
|
```
|
|
|
|
**Démarrer :**
|
|
|
|
```bash
|
|
# Type A
|
|
systemctl start fail2ban
|
|
systemctl enable fail2ban
|
|
fail2ban-client status
|
|
|
|
# Type B
|
|
sudo systemctl start fail2ban
|
|
sudo systemctl enable fail2ban
|
|
sudo fail2ban-client status
|
|
```
|
|
|
|
---
|
|
|
|
## 8. Mises à jour automatiques (5 min)
|
|
|
|
```bash
|
|
# Installer
|
|
# Type A
|
|
apt install unattended-upgrades -y
|
|
dpkg-reconfigure -plow unattended-upgrades
|
|
|
|
# Type B
|
|
sudo apt install unattended-upgrades -y
|
|
sudo dpkg-reconfigure -plow unattended-upgrades
|
|
|
|
# Sélectionnez "Oui"
|
|
```
|
|
|
|
---
|
|
|
|
## 9. Apache (5 min)
|
|
|
|
```bash
|
|
# Installer
|
|
# Type A
|
|
apt install apache2 -y
|
|
systemctl start apache2
|
|
systemctl enable apache2
|
|
|
|
# Type B
|
|
sudo apt install apache2 -y
|
|
sudo systemctl start apache2
|
|
sudo systemctl enable apache2
|
|
```
|
|
|
|
**Tester :**
|
|
- Allez sur `http://IP-DU-VPS` dans votre navigateur
|
|
- Vous devriez voir "Apache2 Debian Default Page"
|
|
|
|
---
|
|
|
|
## 10. Configurer un site (10 min)
|
|
|
|
### DNS
|
|
|
|
Chez votre registrar :
|
|
```
|
|
Type Nom Valeur
|
|
A @ IP-DU-VPS
|
|
A www IP-DU-VPS
|
|
```
|
|
|
|
Attendre 5-30 min, puis vérifier :
|
|
```bash
|
|
nslookup monsite.com # Doit retourner votre IP
|
|
```
|
|
|
|
### VirtualHost Apache
|
|
|
|
```bash
|
|
# Créer le dossier
|
|
# Type A
|
|
mkdir -p /var/www/monsite.com
|
|
chown -R monuser:monuser /var/www/monsite.com
|
|
echo "<h1>Ça marche !</h1>" > /var/www/monsite.com/index.html
|
|
|
|
# Type B (remplacez debian par votre user)
|
|
sudo mkdir -p /var/www/monsite.com
|
|
sudo chown -R debian:debian /var/www/monsite.com
|
|
echo "<h1>Ça marche !</h1>" > /var/www/monsite.com/index.html
|
|
|
|
# Créer le VirtualHost
|
|
# Type A
|
|
vim /etc/apache2/sites-available/monsite.com.conf
|
|
|
|
# Type B
|
|
sudo vim /etc/apache2/sites-available/monsite.com.conf
|
|
```
|
|
|
|
**Contenu du fichier :**
|
|
|
|
```apache
|
|
<VirtualHost *:80>
|
|
ServerName monsite.com
|
|
ServerAlias www.monsite.com
|
|
DocumentRoot /var/www/monsite.com
|
|
|
|
<Directory /var/www/monsite.com>
|
|
Options -Indexes +FollowSymLinks
|
|
AllowOverride All
|
|
Require all granted
|
|
</Directory>
|
|
|
|
ErrorLog ${APACHE_LOG_DIR}/monsite.com_error.log
|
|
CustomLog ${APACHE_LOG_DIR}/monsite.com_access.log combined
|
|
</VirtualHost>
|
|
```
|
|
|
|
**Activer le site :**
|
|
|
|
```bash
|
|
# Type A
|
|
a2enmod rewrite
|
|
a2ensite monsite.com.conf
|
|
a2dissite 000-default.conf
|
|
apache2ctl configtest # Doit dire "Syntax OK"
|
|
systemctl reload apache2
|
|
|
|
# Type B
|
|
sudo a2enmod rewrite
|
|
sudo a2ensite monsite.com.conf
|
|
sudo a2dissite 000-default.conf
|
|
sudo apache2ctl configtest
|
|
sudo systemctl reload apache2
|
|
```
|
|
|
|
**Tester :**
|
|
- Allez sur `http://monsite.com`
|
|
- Vous devriez voir "Ça marche !"
|
|
|
|
---
|
|
|
|
## 11. SSL (Let's Encrypt) (5 min)
|
|
|
|
```bash
|
|
# Installer Certbot
|
|
# Type A
|
|
apt install certbot python3-certbot-apache -y
|
|
certbot --apache -d monsite.com -d www.monsite.com
|
|
|
|
# Type B
|
|
sudo apt install certbot python3-certbot-apache -y
|
|
sudo certbot --apache -d monsite.com -d www.monsite.com
|
|
|
|
# Répondre aux questions :
|
|
# Email : votre-email@example.com
|
|
# Terms : (A)gree
|
|
# Redirect : 2 (forcer HTTPS)
|
|
```
|
|
|
|
**Tester :**
|
|
- Allez sur `http://monsite.com` → redirige vers `https://monsite.com` 🔒
|
|
|
|
---
|
|
|
|
## ✅ Checklist finale
|
|
|
|
- [ ] Connexion SSH par clé fonctionne
|
|
- [ ] Mot de passe SSH désactivé
|
|
- [ ] Root SSH désactivé
|
|
- [ ] UFW actif (ports 22, 80, 443)
|
|
- [ ] Fail2ban actif
|
|
- [ ] Apache fonctionne
|
|
- [ ] Site accessible en HTTP
|
|
- [ ] SSL installé et HTTPS fonctionne
|
|
- [ ] Redirection HTTP → HTTPS active
|
|
|
|
---
|
|
|
|
## 🚀 Prochaines étapes
|
|
|
|
### Déployer votre site
|
|
|
|
- **Kirby CMS** → [kirby-vps-deploy.md](kirby-vps-deploy.md)
|
|
- **Autre site statique** → Utilisez rsync :
|
|
```bash
|
|
rsync -avhP ./mon-site/ user@IP:/var/www/monsite.com/
|
|
```
|
|
|
|
### Maintenance de base
|
|
|
|
```bash
|
|
# Voir les logs Apache
|
|
sudo tail -f /var/log/apache2/monsite.com_error.log
|
|
|
|
# Voir les IPs bannies par Fail2ban
|
|
sudo fail2ban-client status sshd
|
|
|
|
# Espace disque
|
|
df -h
|
|
|
|
# Mettre à jour
|
|
sudo apt update && sudo apt upgrade -y
|
|
```
|
|
|
|
---
|
|
|
|
## 📚 Pour aller plus loin
|
|
|
|
- **Guide complet** → [vps-setup-complet.md](vps-setup-complet.md)
|
|
- **Vim** → [vim-guide-essentiel.md](linux-essentials/vim-guide-essentiel.md)
|
|
- **Diagnostic** → [diagnostic-espace-disque.md](linux-essentials/diagnostic-espace-disque.md)
|
|
|
|
---
|
|
|
|
## Commandes de référence rapide
|
|
|
|
```bash
|
|
# SSH
|
|
ssh user@host
|
|
ssh -i ~/.ssh/cle user@host
|
|
|
|
# UFW
|
|
sudo ufw status
|
|
sudo ufw allow 8080/tcp
|
|
sudo ufw delete 3
|
|
|
|
# Fail2ban
|
|
sudo fail2ban-client status
|
|
sudo fail2ban-client status sshd
|
|
sudo fail2ban-client set sshd unbanip IP
|
|
|
|
# Apache
|
|
sudo systemctl status apache2
|
|
sudo systemctl reload apache2
|
|
sudo apache2ctl configtest
|
|
sudo a2ensite site.conf
|
|
sudo a2dissite site.conf
|
|
|
|
# Certbot
|
|
sudo certbot certificates
|
|
sudo certbot renew --dry-run
|
|
|
|
# Logs
|
|
sudo tail -f /var/log/apache2/error.log
|
|
sudo journalctl -u apache2 -n 50
|
|
|
|
# Système
|
|
df -h
|
|
du -sh /var/www/*
|
|
systemctl list-units --type=service --state=running
|
|
```
|
|
|
|
---
|
|
|
|
**Temps total :** 30-50 minutes pour un VPS sécurisé et fonctionnel ! 🎉
|