0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Vscodeでのssh二段階接続

Posted at

はじめに

外部から大学の研究室のPCにsshでアクセスする際など、いくつかのサーバを経由して接続する場合、sshのコマンドを何回も打つ必要があります。毎回コマンドをたたくのは面倒なので、設定ファイル(~/.ssh/config)を編集してGUIでアクセスできるようにしたいと思います。

~/.ssh/config

結論から言うと以下のようになります。
※ 二段階接続の場合

~/.ssh/config
# 踏み台サーバー(Bastion)の設定
Host bastion
  HostName bastion-server-ip-or-hostname
  User bastion-user

# ターゲットサーバーの設定
Host target
  HostName target-server-ip-or-hostname
  User target-user
  ProxyJump bastion

ローカル -> bastion -> targetといった流れで接続します。

ここで ProxyCommandを用いて行われている記事が多いですが、レガシーな書き方でありProxyJumpの方が簡潔なため採用しています。

vscode remote-ssh

vscodeの拡張機能にある Remote Development というパッケージをインストールします。(vscode上でctrl+shift+xを押すことで拡張機能を開くことができ、そこから Remote Developmentと検索することでパッケージが出てきます)

Remote Developmentの扱い方は他の記事でやり方がたくさん出てくるため詳しくは説明しませんが、インストールするとvscodeの左側のアイコンの列にリモートエクスプローラーというアイコンが作成され、そこからGUIでsshログインをすることができます。

Remote Developmentの使い方:https://blog.future.ad.jp/vscode_remote_development

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?