199 lines
4.4 KiB
Markdown
199 lines
4.4 KiB
Markdown
# Installation Headless
|
|
|
|
|
|
|
|
Télécharger l'image [Raspian Stretch Lite](https://www.raspberrypi.org/downloads/raspbian/) et l'installer sur la carte SD avec [Etcher](https://www.balena.io/etcher/).
|
|
|
|
### Activer et connecter le wifi:
|
|
|
|
Il faut créer un fichier `wpa_supplicant.conf` dans /boot
|
|
|
|
```bash title="Depuis macOS"
|
|
cd /Volumes/boot
|
|
nano wpa_supplicant.conf
|
|
```
|
|
|
|
|
|
|
|
```ini title="wpa_supplicant.conf"
|
|
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
|
|
update_config=1
|
|
country=FR
|
|
|
|
network={
|
|
ssid="SSID"
|
|
psk="Mot de passe"
|
|
key_mgmt=WPA-PSK
|
|
}
|
|
```
|
|
|
|
### Activer SSH:
|
|
|
|
Il faut créer un fichier `ssh` dans /boot
|
|
|
|
```bash title="Depuis macOS"
|
|
cd /Volumes/boot
|
|
touch ssh
|
|
```
|
|
|
|
Démarrer le Raspberry, il va se connecter automatiquement à la Box.
|
|
Pour trouver l'ip, aller sur la box :material-arrow-right: Configuration DHCP :material-arrow-right: Baux DHCP valides
|
|
|
|
Se connecter au Raspberry en SSH:
|
|
|
|
```bash
|
|
$ ssh pi@ip
|
|
avec le mot-de-passe Raspberry
|
|
```
|
|
|
|
Changer le mot-de-passe:
|
|
|
|
```bash
|
|
$ passwd
|
|
Changing password for pi.
|
|
(current) UNIX password:
|
|
Enter new UNIX password:
|
|
Retype new UNIX password:
|
|
passwd: password updated successfully
|
|
```
|
|
|
|
### Mettre en IP fixe:
|
|
|
|
```bash
|
|
sudo nano /etc/dhcpcd.conf
|
|
```
|
|
|
|
```bash title="dhcpcd.conf"
|
|
# à rajouter à la fin du fichier:
|
|
|
|
interface eth0
|
|
static ip_address=192.168.1.24/24
|
|
static routers=192.168.1.1
|
|
static domain_name_servers=192.168.1.1
|
|
|
|
interface wlan0
|
|
static ip_address=192.168.1.23/24
|
|
static routers=192.168.1.1
|
|
static domain_name_servers=192.168.1.1
|
|
```
|
|
|
|
#### Ajouter la clé ssh:
|
|
|
|
```
|
|
bruno@silverbook:~/.ssh$ ssh pi@framboise.local 'mkdir -p ~/.ssh; chmod 0700 ~/.ssh; echo ' $(< ~/.ssh/id_ed25519.pub) ' >> ~/.ssh/authorized_keys ; chmod 0600 ~/.ssh/authorized_keys'
|
|
```
|
|
|
|
#### Sécuriser ssh:
|
|
|
|
```bash
|
|
sudo nano /etc/ssh/sshd_config
|
|
```
|
|
|
|
```bash title="sshd_config"
|
|
Port 36722
|
|
PermitRootLogin prohibit-password
|
|
|
|
yes (défaut)
|
|
# without-password (prohibit-password) authentification par mot de passe désactivée, # authentification par clé publique seulement
|
|
# forced-commands-only avec l'option Commande, authentification par clé publique seulement
|
|
# no
|
|
```
|
|
|
|
```bash
|
|
sudo service ssh restart
|
|
```
|
|
|
|
|
|
|
|
### Configurer le Raspberry:
|
|
|
|
```bash
|
|
sudo raspi-config
|
|
```
|
|
|
|
```bash title="raspî-config"
|
|
-Network Options -> changer le hostname
|
|
-Localisations Options -> Change Locale, Change Timezone
|
|
-Interfacing Options -> enable Camera, SPI, I2C, Serial
|
|
-Advanced Options -> Expanding filesystem
|
|
-Update (raspi-config)
|
|
```
|
|
|
|
#### Installer git:
|
|
|
|
```bash
|
|
sudo apt-get install -y git dirmngr
|
|
```
|
|
|
|
#### Installer log2ram:
|
|
|
|
```bash
|
|
cd /home/pi
|
|
git clone https://github.com/azlux/log2ram.git
|
|
cd log2ram
|
|
chmod +x install.sh
|
|
sudo ./install.sh
|
|
|
|
#Change the log size value to 128M
|
|
sudo vi /etc/log2ram.conf
|
|
```
|
|
|
|
##### Vérifier l'installation de log2ram:
|
|
|
|
```bash
|
|
$ df -h
|
|
Sys. de fichiers Taille Utilisé Dispo Uti% Monté sur
|
|
/dev/root 15G 1,1G 13G 8% /
|
|
devtmpfs 181M 0 181M 0% /dev
|
|
tmpfs 186M 0 186M 0% /dev/shm
|
|
tmpfs 186M 2,7M 183M 2% /run
|
|
tmpfs 5,0M 4,0K 5,0M 1% /run/lock
|
|
tmpfs 186M 0 186M 0% /sys/fs/cgroup
|
|
/dev/mmcblk0p1 44M 23M 22M 51% /boot
|
|
log2ram 40M 636K 40M 2% /var/log
|
|
tmpfs 37M 0 37M 0% /run/user/1000
|
|
```
|
|
|
|
Toutes les heures, log2ram copie les logs en mémoire vers les fichiers. On peut modifier pour que ce soit tous les jours.
|
|
|
|
```bash
|
|
sudo mv /etc/cron.hourly/log2ram /etc/cron.daily/log2ram
|
|
sudo reboot
|
|
```
|
|
|
|
|
|
|
|
### Mettre à jour le Raspberry:
|
|
|
|
```bash
|
|
sudo apt-get update && sudo apt-get upgrade
|
|
```
|
|
|
|
*Créer un alias dans .bashrc:*
|
|
`alias update='sudo apt-get update && sudo apt-get upgrade'`
|
|
|
|
|
|
|
|
### Backup de la carte SD
|
|
|
|
https://raspberrypi.stackexchange.com/questions/311/how-do-i-backup-my-raspberry-pi
|
|
|
|
```bash
|
|
bruno@silverbook:~$ diskutil list
|
|
bruno@silverbook:~$ sudo dd if=/dev/rdisk2 of=/Users/bruno/Downloads/litePi_1.img bs=1m
|
|
# ou
|
|
bruno@silverbook:~$ sudo dd if=/dev/rdisk2 bs=1m | gzip > /Users/bruno/Downloads/litePi_1.gz
|
|
# avec progression:
|
|
bruno@silverbook:~$ sudo dd if=/dev/rdisk2 bs=1m | pv | gzip > /Users/bruno/Downloads/litePi_1.gz
|
|
```
|
|
|
|
#### Restaurer:
|
|
|
|
```bash
|
|
bruno@silverbook:~$ diskutil list
|
|
bruno@silverbook:~$ sudo dd if=/Users/bruno/Downloads/litePi_1.img of=/dev/rdisk2 bs=1m
|
|
# ou
|
|
bruno@silverbook:~$ gzip -dc /Users/bruno/Downloads/litePi_1.gz | sudo dd of=/dev/rdisk2 bs=1m
|
|
```
|
|
|