Estabelecendo a conexão VNC do cliente sobre o SSH em uma etapa (por exemplo, com a opção -via)

3

Como reduzo esses dois comandos para um? Estou me conectando do meu cliente para um servidor x11vnc e os dois comandos abaixo já funcionam. Eu só quero fazer isso em um passo:

primeiro comando:

ssh -fNL 5901:localhost:5678 -i ~/.ssh/some_id_rsa [email protected]

e segundo:

vncviewer localhost:5901

A partir da leitura da página man, parece que a opção -via pode fazê-lo. Infelizmente, a página man me deixa muito confusa. Para referência (não que eu entenda), aqui está o que diz minha página de manual:

   -via gateway
          Automatically create encrypted TCP tunnel to the gateway machine before con‐
          nection, connect to the host through  that  tunnel  (TightVNC-specific).  By
          default,  this  option  invokes SSH local port forwarding, assuming that SSH
          client binary can be accessed as /usr/bin/ssh. Note that when using the -via
          option,  the  host  machine name should be specified as known to the gateway
          machine, e.g.  "localhost"  denotes  the  gateway,  not  the  machine  where
          vncviewer  was  launched.  The environment variable VNC_VIA_CMD can override
          the            default             tunnel             command             of
          /usr/bin/ssh -f -L "$L":"$H":"$R" "$G" sleep 20.  The tunnel command is exe‐
          cuted with the environment variables L, H, R, and G taken the values of  the
          local  port number, the remote host, the port number on the remote host, and
          the gateway machine respectively.
    
por MountainX 21.07.2013 / 01:56

1 resposta

4

Isso é o que a man page está tentando dizer. Eu tenho a seguinte configuração.

  vncviewer         .-,(  ),-.    
   __  _         .-(          )-.           gateway           vncserver 
  [__]|=|  ---->(    internet    )-------> __________ ------> ____   __ 
  /::/|_|        '-(          ).-'        [_...__...°]       |    | |==|
                     '-.( ).-'                               |____| |  |
                                                             /::::/ |__|

OBSERVAÇÃO: O diagrama acima foi feito usando asciio .

O vncviewer está sendo executado no meu laptop. Do meu laptop, posso executar o seguinte comando e conectar-me ao vncserver que está por trás do meu roteador:

$ vncviewer vncserver_host:0 -via mygateway.mydom.com

Isso me conectará instantaneamente ao vncserver . Este comando é mostrado no meu laptop, o que ajuda a mostrar o que a página do manual está tentando explicar:

/usr/bin/ssh -f -L 5599:vncserver_host:5900 mygateway.mydom.com sleep 20

Este é o comando que vncviewer está construindo automaticamente quando você usa a opção -via gateway .

incluindo ssh configurações

Você pode usar o arquivo ~/.ssh/config e colocar entradas nesse arquivo da seguinte forma:

Host *
IdentityFile ~/.ssh/id_dsa

Ou você pode segmentar um host específico como este:

Host mygateway
    User sam
    HostName mygateway.mydom.com
    IdentityFile ~/.ssh/someother_id_rsa

Isso permitirá que você aproveite as entradas Host neste arquivo da seguinte forma:

$ vncviewer vncserver_host:0 -via mygateway
    
por 21.07.2013 / 03:34