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?

SSHトンネルでRDP接続してみた

Posted at

背景・目的

以前、下記の記事で踏み台サーバへの多段接続、リモート接続を個別に試してみました。
今回は、踏み台サーバ+リモートデスクトップを試してみたいと思います。

実践

下記の構成を構築します。

image.png

前提

VPC

以前、下記で作成したVPCを再利用します。下記が用意されています。

  • Public Subnet * 1
  • Private Subnet * 1
  • NAT
  • IGW

EC2インスタンスの起動

  1. 下記の要領で作成します
項目 踏み台サーバ プライベートマシン
用途 踏み台 リモートデスクトップ
サブネットワーク パブリック プライベート
セキュリティグループ ・ポート:22
・ソース:自分のPC
・ポート:3389、22
・ソース:踏み台サーバのSG
OS Amazon Linux Ubuntu
IPアドレス Public
Private
Privateのみ

SSH Configの設定とProxy Jump

  1. .ssh/configを下記の修正します

    
    Host bastion # 踏み台のEC2
      HostName <Public IP>
      User ubuntu
      IdentityFile ~/.ssh/bastion-key.pem
    
    Host rdp # プライベートサブネットのEC2
      HostName <Private IP>
      User ubuntu
      IdentityFile ~/.ssh/private-key.pem
      ProxyJump bastion
    
  2. ssh rdpでProxy Jumpを使用してログインします。できました

    ~ % ssh rdp
    Welcome to Ubuntu 24.04.2 LTS (GNU/Linux 6.8.0-1024-aws x86_64)
    
     * Documentation:  https://help.ubuntu.com
     * Management:     https://landscape.canonical.com
     * Support:        https://ubuntu.com/pro
    
     System information as of Sun Apr 20 05:16:25 UTC 2025
    
      System load:  0.01              Processes:             106
      Usage of /:   34.0% of 6.71GB   Users logged in:       0
      Memory usage: 27%               IPv4 address for enX0: XX.XX.XX.XX
      Swap usage:   0%
    
     * Ubuntu Pro delivers the most comprehensive open source security and
       compliance features.
    
       https://ubuntu.com/aws/pro
    
    Expanded Security Maintenance for Applications is not enabled.
    
    40 updates can be applied immediately.
    To see these additional updates run: apt list --upgradable
    
    Enable ESM Apps to receive additional future security updates.
    See https://ubuntu.com/esm or run: sudo pro status
    
    
    *** System restart required ***
    Last login: Sun Apr 20 05:14:00 2025 from XX.XX.XX.XX
    To run a command as administrator (user "root"), use "sudo <command>".
    See "man sudo_root" for details.
    
    ubuntu@ip-XX-XX-XXX-XXX:~$ 
    

EC2のセットアップ

UbuntuにGUI(xfce4)とxrdpをインストール

下記と同様にインストールします。

  1. apt update & upgradeします

    sudo apt update && sudo apt upgrade -y
    
  2. xfce4 xfce4-goodies xrdpをインストールします

    sudo apt install xfce4 xfce4-goodies xrdp -y
    
  3. セッションをxfce4に設定します

    ~$ echo xfce4-session > ~/.xsession
    ~$ cat ~/.xsession
    xfce4-session
    ~$ 
    
  4. 再起動します

    sudo systemctl restart xrdp
    

パスワードを設定(初回ログイン用)

  1. パスワードを入力します
    ~$ sudo passwd ubuntu
    New password: 
    Retype new password: 
    passwd: password updated successfully
    ~$ 
    

クライアントPCから接続

SSHトンネルを作成

  1. ~/.ssh/configを設定します
    Host bastion # 踏み台のEC2
      HostName <Public IP>
      User ubuntu
      IdentityFile ~/.ssh/bastion-key.pem
    
    Host rdp-tunnel
      HostName  <Private IP>       # RDPマシンのプライベートIP
      User ubuntu                  
      ProxyJump bastion            # bastion を経由
      IdentityFile ~/.ssh/private-key.pem
      LocalForward 13389 127.0.0.1:3389
      ExitOnForwardFailure yes
      ServerAliveInterval 60
    
  2. 下記で接続します
    ssh rdp-tunnel
    

Windows Appからの接続

以前、下記でセットアップしたMicrosoft Remote Desktopを使用します。

  1. Windows Appを起動します
    image.png

  2. 「Add PC」をクリックします
    image.png

  3. 「PC name」にlocalhost:13389を入力し、「Add」をクリックします
    image.png

  4. 「Connect」をクリックします
    image.png

  5. あらかじめ作成したUsernameとPasswordを入力し、「Continue」をクリックします
    image.png

  6. 接続できました
    image.png

  7. Terminalを起動してみます。設定したマシンのIPアドレスとユーザが確認できました

    ubuntu@ip-XXXX:~$ `id
    > 
    > ^C
    ubuntu@ip-XXXX:~$ 
    ubuntu@ip-XXXX:~$ id
    uid=1000(ubuntu) gid=1000(ubuntu) groups=1000(ubuntu),4(adm),24(cdrom),27(sudo),30(dip),105(lxd)
    ubuntu@ip-XXXX:~$ uname -a
    Linux ip-XXXX 6.8.0-1024-aws #26-Ubuntu SMP Tue Feb 18 17:22:37 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
    

考察

今回、踏み台(Bastion)を経由してプライベートサブネット上のUbuntuサーバーに対し、SSHトンネルを使ってRDP接続を行う構成を構築・検証しました。結果として、リモートデスクトップ接続できました。

参考

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?