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?

More than 1 year has passed since last update.

WSL経由でサーバーへSSH接続してみた

Last updated at Posted at 2022-06-26

はじめに

端末にインストールしたWSLを使用して、VirtualBoxの踏み台サーバー経由で、VirtualBoxのwebサーバーにssh接続を試しました。

以下のサイトで学びました。
infracollege
https://infracollege.vamdemicsystem.black/linux/

動作条件

VirtualBox仮想サーバー2台 ※2台ともCentOS7

VirtualBox仮想サーバー2台とも、パスワード認証の設定をしました。
以下を参考にしてください
https://qiita.com/gama1234/items/3ad5f698784af3fd39d1

WSLをWindows11端末にインストールした
以下のサイトを参考にしてください
https://qiita.com/gama1234/items/5828b2b2e4e9e1365711

構成図

image.png

手順

WSLにブリッチ接続設定をした

ブリッチ設定の方法は、以下のサイトを参考にしました。
https://qiita.com/shigeokamoto/items/d45d0a86aed7338a9dc9

/home/test
test@DESKTOP-0S2U0NI:~$
test@DESKTOP-0S2U0NI:~$ cat .wslconfig
[wsl2]
networkingMode=bridged
vmSwitch=my-switch

WSLのパッケージをアップデートをした

以下のサイトを参考にしました。
https://qiita.com/rubytomato@github/items/fdfc0a76e848442f374e

test@DESKTOP-0S2U0NI:~$ sudo apt update
test@DESKTOP-0S2U0NI:~$ sudo apt upgrade -y

WSLのSSHサービスを再起動しました

test@DESKTOP-0S2U0NI:~$ sudo service ssh restart
 * Restarting OpenBSD Secure Shell server sshd                                                                                                                   [ OK ]
test@DESKTOP-0S2U0NI:~$
test@DESKTOP-0S2U0NI:~$ sudo service ssh status
 * sshd is running

VirtualBox 踏み台サーバーのネットワーク設定した

アダプター1は、WSLと通信するため、ブリッジアダプターとしました

image.png

アダプター2 WEBサーバーへと通信するため、内部ネットワークとしました

image.png

VirtualBox 踏み台サーバーのipアドレスを設定した

アダプター1のipアドレス設定

image.png
設定値
ipアドレス
ホストOSのipアドレス「192.168.0.14」だったため、同じネットワークの任意なIPアドレス「192.168.0.2」にした。

Gateway
Windos端末のコマンドプロンプトを開き、以下のコマンドを実行した

ipconfig

赤枠のGatewayを確認した
image.png

DNSはGoogleのDNS「8.8.8.8」を設定した

アダプター2のipアドレス設定

ipアドレスは、ホストOSのipアドレス「192.168.0.xx」とは異なる任意なネットワーク「10.0.1.x」にした
image.png

ipアドレス設定後、networkサービスを再起動した

# systemctl restart network

VirtualBox WEBサーバーのネットワーク設定した

image.png

VirtualBox WEBサーバーのipアドレスを設定した

踏み台サーバーのIPアドレスが「10.0.1.2」だったため、同じネットワークの任意のIPアドレス「10.0.1.1」にした
image.png

ipアドレス設定後、networkサービスを再起動した

# systemctl restart network

WSLからVirtualBoxの踏み台サーバーへSSH接続した

パスワード認証でSSH接続した

test@DESKTOP-0S2U0NI:~$ ssh root@192.168.0.2
root@192.168.0.2's password:
Last login: Sun Jun 26 09:40:50 2022 from 192.168.0.14

WSLからVirtualBoxの踏み台サーバー経由して、WEBサーバーへSSH接続した

[root@localhost ~]# ssh root@10.0.1.1
root@10.0.1.1's password:
Last login: Sun Jun 26 09:33:13 2022 from 10.0.1.2
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?