TUNNEL SSH

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
ssh-keygen -t rsa -b 4096      // création clef ssh ( si pas déjà fait)
 
ssh  user@dev.monserveur.com  <-password // première connexion serveur relais manuelle
 
ssh-copy-id root@ monserveur.com  // copie clef
 
dans sshd_config ajouter :  GatewayPorts yes
/etc/init.d/ssh restart  //(debian)
 
ssh -R 4444:localhost:80 user@dev.monserveur.com
en se connectant sur dev.monserveur.com:4444 c'est localhost:80 qui répond.
 
autossh   -M 0 -q -f -N -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3"  -R 4444:localhost:80 user@dev.monserveur.com
même chose mais en tache de fond avec reconnexion automatique
 
Lancement au boot ajouter un fichier /etc/systemd/system/autossh-tunnel.service
[Unit]
Description=AutoSSH tunnel service local 80 port 4444 dev.monserveur.mobi
After=network.target
 
[Service]
Environment="AUTOSSH_GATETIME=0"
ExecStart=/usr/bin/autossh -M 0 -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -NR 4444:localhost:80 root@dev.monserveur.mobi
Restart=always
User=pi
 
[Install]
WantedBy=multi-user.target
 
puis:
sudo systemctl start autossh-tunnel.service
sudo systemctl stop autossh-tunnel.service
sudo systemctl enable autossh-tunnel.service  pour démarrage auto

https://wiki.archlinux.fr/Autossh