Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ogawa/1d61d0241b82af802d99cba7cb03d1ff to your computer and use it in GitHub Desktop.
Save ogawa/1d61d0241b82af802d99cba7cb03d1ff to your computer and use it in GitHub Desktop.

OpenSSHを用いたインタラクティブノードへのログイン

概要

以下ではアクセスサーバ (as.abci.ai) へのポートフォワーディングによるトンネルを作った上で、別ターミナルでSSHトンネルを用いてインタラクティブノードにアクセスする方法を説明しています。

しかし、OpenSSHを用いるともっと簡便にインタラクティブノードにアクセスできます。このメモではその方法を説明します。

OpenSSH 7.3以降

ProxyJump (-J) オプションを使ってコマンド1つでログインできます。

[user@localmachine] $ ssh -J %r@as.abci.ai abciuser@es

localmachineの $HOME/.ssh/config に以下のように記述しておくと、さらに省力化になります。

Host abci
     HostName es
     User abciuser
     ProxyJump %r@as.abci.ai

ログインする場合:

[user@localmachine] $ ssh abci

ファイル転送する場合:

[user@localmachine] $ scp src-files abci:dest-dir

SSHポートフォワーディング(トンネリング)を設定する場合(localhostの8088ポートへのアクセスをgXXXXの8888ポートに転送):

[user@localmachine] $ ssh -N -L 8088:gXXXX.abci.local:8888 abci

OpenSSH 5.4以降

ProxyCommandオプションを使ってコマンド1つでログインできます。

[user@localmachine] $ ssh -o ProxyCommand='ssh %r@as.abci.ai -W %h:%p' abciuser@es

同様に、localmachineの $HOME/.ssh/config に以下のように記述しておくと省力化になります。

Host abci
     HostName es
     User abciuser
     ProxyCommand ssh %r@as.abci.ai -W %h:%p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment