SSHによるワンステップクライアントVNC接続(例:-viaオプションを使用)

SSHによるワンステップクライアントVNC接続(例:-viaオプションを使用)

これら2つのコマンドを1つにどのように減らすことができますか?クライアントはx11vncサーバーに接続していますが、以下の2つのコマンドはすでに機能しています。私は段階的にそれをしたいと思います:

最初のコマンド:

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

第二:

vncviewer localhost:5901

マニュアルページを読んでみると、-viaオプションはこれを行うようです。残念ながら、マニュアルページは私を非常に混乱させます。ちなみに(私が理解したわけではない)私のマニュアルページに次のように示されています。

   -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.

ベストアンサー1

これがマニュアルページが言うことです。次の設定があります。

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

メモ:上の図は以下を使用して完成しました。アスキー

vncviewer私のラップトップで実行しています。私のラップトップで次のコマンドを実行し、vncserverルーターの背後にあるコマンドに接続できます。

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

その後すぐに接続されますvncserver。このコマンドは私のラップトップに表示され、マニュアルページで説明したいことを示すのに役立ちます。

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

vncviewerスイッチ使用時に自動的に構築される命令です-via gateway

ssh構成を含める

~/.ssh/configそのファイルを使用して、次のようにアイテムを配置できます。

Host *
IdentityFile ~/.ssh/id_dsa

または、次のように特定のホストをターゲティングできます。

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

Hostこれにより、このファイルのエントリを次のように利用できます。

$ vncviewer vncserver_host:0 -via mygateway

おすすめ記事