AutoSSH Tunnel zu einer zentralen Stelle
Wenn man von extern in eine Umgebung kommen möchte zu der man keinen Zugriff hat kann man dies über einen Reverse-Tunnel machen.
Source-System = Server der intern steht und von extern nicht erreichbar ist. Dieser soll erreicht werden. Destination-System = Server von den man den Reverse-Tunnel nutzen kann um auf das Source-System zu gelangen.
1.) SSH User auf dem Destination-System anlegen
useradd -c "Autossh User <Kunde> - AutoSSH only" -m -s /bin/false <username>
2.) SSH Key auf Source-System erstellen
ssh-keygen -t rsa -b 4096
3. SSH Key auf Destination-System kopieren und absichern
Inhalt von File “id_rsa.pub” vom Destination-System in das File “authorized_keys” kopieren. Ganz am Anfang muss noch ein “no-pty” stehen. Dies hat den Vorteil das dieser User keine Shell bekommt (Security).Dies sieht dann so aus:
no-pty ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC8wYpv8lR1coS65mQMdFApw/cob3O6he9JPl2uXr8+G+wlNpPaHY74ZiW2y90TSct2kqAeBs0yVBIWOi1Gn7Vxk6xXeMEOgLdh2OTYEMHO9c8lmrP1JdEx8LrGKwPUF8tDVpAZyOqBOx6GVz48P2+xyuQtCzOLDkU01kckkgIwtAqqf853Nl7/OkWUqrIbaEFmcJ4kgTPx7l6G7GNBdQYcSypX/hfJrr1IOhQbZqB/IdjAnnqPNPUZmseY+kUgVtPgRax4lMvcYMPigpgKQrOUZYM5l+FGZc0zfTI+aM6VPFFyw31+PHPfFRIVMnd6wqmt61ljKEjP8k48UDZjoZMorIfD6TuUrt1Nil8h8B0XtGhSvDMGUF+PwUL9xtrz5XjGh5leWHdubHTWT/yDm62sNY4Lf4Gp4Pj/B0KUOkbxfQaBQhHy6RhgSjQWmjLSZ3BNo2i6f3HucxzyIYJF0V0vm5DbYlRJevrqHvoMAvI7XArrNAN7j7+AVFC5IdYwI1K9rx/kNrppjYwxJqwNDq9aU7tlg5SUFncPf/SkQxtEPb3hx8DFS4uVj1wQGJEb9YnBwXH9ospyLjKQXiGyaxSyye+1YrWpUmgYdmwwdaYGlp9kZAlnh+Hwwt85XhTcVx7zZ+MjrhfqtO780YTU7VpBkcZikKUDZJV+eGdbSmkLww== root@fileserver
4.) AutoSSH
Dies hat den Sinn das wenn die Verbindung einmal unterbrochen wird das diese automatisch wieder aufgebaut wird.
AutoSSH installieren auf dem Source-System.
apt-get install autossh
AutoSSH starten auf dem Source-System.
/usr/lib/autossh/autossh -M 0 -f -N -o ServerAliveInterval=80 -o ServerAliveCountMax=3 -R 10.1.1.1:<your port>:localhost:22 <remoteuser>@<remoteserver> Beispiel: /usr/lib/autossh/autossh -M 0 -f -N -o ServerAliveInterval=80 -o ServerAliveCountMax=3 -R 10.1.1.1:6662:localhost:22 tunnel_kundeXY@nibbler.heisl.org
5. Tunnel verwenden.
Der Tunnel kann jetzt vom Destination-System verwendet werden.
ssh -l <user> localhost -p <port> Beispiel: ssh -l root localhost -p 6662
Wenn man hier kein Passwort eingeben möchte kann man an dieser Stelle natürlich auch noch SSH Keys austauschen.
