1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ppkキーしかない場合に踏み台サーバを経由してSSH接続したいとき

Posted at

背景

踏み台サーバーを使用している環境で、目的のサーバーにSSH接続したいときに、情報が少なく接続できなくて困っていたが、解決できたので記事として残しておく。ppkキーしか手元にない状態でVScodeから踏み台サーバー経由→目的のサーバーに接続する手順を記載する。

pemキーの説明
https://qiita.com/one_punch_man/items/2ad8b4664ed012bee5a7

接続構成

VScode → 踏み台サーバー → 目的のサーバー(図にしたい)

手順

大きく分けて以下2つの手順を踏むことになる。
1.pemキーの生成
2.VScodeからSSH接続の設定

1.pemキーの生成

まず、pemキーを生成するためにputtygenをダウンロードする。
https://www.puttygen.com/download.php?val=49
上記URLにアクセスするとputtygen.exeのダウンロードが始まる。

ダウンロードしたputtygen.exeを立ち上げ、Loadを押して、ppkキーを読み込む
image.png

Conversionsメニューをクリックして、「Export OpenSSH key (force new file format)」を選択
image.png

ポップアップは「はい」を選択
image.png

ファイル保存のダイアログがでるため「pemkey.pem」などと名前を付けて保存する。

2.VScodeからSSH接続の設定

VScodeの拡張機能で「remote」と検索し、Remote Developmentをインストールする。
image.png

VScodeの左側にリモートエクスプローラーのアイコンができるため、クリック後、上部のプルダウンでSSH Targetsを選択
image.png

SSH TARGETSと表示されている辺りにマウスを持ってくるとメニューが出てくるため、歯車マークをクリック。上部にプルダウンが出てきて、以下を選択
C:\Users[ユーザー名].ssh\config
image.png

configファイルに以下のように記入する

config
# 踏み台サーバー
Host Hop_server  # 任意の名称
    HostName xxx.xxx.xxx.xxx  # サーバー情報
    Port xxx  # ポート番号
    User user_name  # ユーザー名
    IdentityFile ~/Documents/ssh/pemkey.pem  # 作成したpemキーを指定

# 目的のサーバー
Host Target_server  # 任意の名称
    HostName xxx.xxx.xxx.xxx  # サーバー情報
    Port xxx  # ポート番号
    User user_name  # ユーザー名
    IdentityFile ~/Documents/ssh/pemkey.pem  # 作成したpemキーを指定
    ProxyCommand ssh -W %h:%p Hop_server  # 踏み台を経由させるコマンド、最後に踏み台サーバーに付けた名称を記載

configを記載して保存すると左側に反映されるため、接続したいサーバーをクリックすると新しいウィンドウで接続が開始される
image.png

パスワードを求められたら入力し、接続が成功するとVScodeの左下に緑色でSSHと表示され、Terminalを使えたりディレクトリにアクセスできる。
image.png

以上

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?