linux/SSH/ssh_forward_unix_socket.adoc

57 lines
2.1 KiB
Plaintext
Raw Normal View History

= Accesso remoto a socket locali Unix via OpenSSH
Remote access to local Unix socket by OpenSSH
:authors: Celestino Amoroso
:docinfo: shared
:encoding: utf-8
:toc: right
:toclevels: 4
:toc-title: Indice Generale
:icons: font
:icon-set: fi
:numbered:
:table-caption: Tabella
:figure-caption: Diagramma
:docinfo1:
:sectlinks:
:sectanchors:
:source-highlighter: rouge
// :rouge-style: ThankfulEyes
:rouge-style: gruvbox
// :rouge-style: colorful
//:rouge-style: monokay
toc::[]
## Inoltro socket Unix
OpenSSH, oltre all'inoltro di porte TCP, consente anche l'inoltro di socket locali Unix.
### Inoltro di un socket Unix remoto ad una porta TCP locale
Comando per collegare una porta TCP locale, ad esempio sul proprio PC, ad un socket remoto esistente su un server remoto.
[user@mypc ~]$ ssh -nNT -L 1234:/var/run/remote-app/remote-app.sock -o "ExitOnForwardFailure yes" remote-host
Esempio di inoltro del socket di PostgreSQL:
[user@mypc ~]$ ssh -nNT -L 5432:/var/run/postgresql/.s.PGSQL.5432 -o "ExitOnForwardFailure yes" remote-host
Accesso al database PostgreSQL remoto tramite la porta TCP locale 5432:
[user@mypc ~] psql -U db-user -h localhost -p 5432 my-db-name
### Inoltro di un socket Unix locale ad una porta TCP remota
Il comando da usare è analogo al precedente. Lo schema seguente fa rimerimento all'host _myhost_ dal quale si vuole inoltrare un socket locale _my-app.sock_ ad una porta TCP sull'host _remote-host_:
[user@myhost ~]$ ssh -nNT -R /var/run/my-app/my-app.sock:localhost:1234 -o "ExitOnForwardFailure yes" remote-host
Questo comando stabilisce una connessione all'host _remote-host_ attraverso la quale inoltrerà il socket _my-app.sock_ alla porta `1234` aperta sull'interfaccia localhost di _remote-host_.
## Riferimenti esterni
Per ulteriori approfondimenti vedere il post di Stefan Kreutz https://www.skreutz.com/posts/unix-domain-socket-forwarding-with-openssh/[qui].
Kreutz appofondisce il particolare le possibilità di controllare l'accesso remoto da un socket Unix mediante inoltro ad una porta TCP.
'''
*Celestino Amoroso* +
*celestino . amoroso @ gmail . com*
image::https://gravatar.com/avatar/88d204d546890e5d89073fb1cec29fe9.png?size=48[]