SSH Tunnel on Windows RDP
Architecture
- User Story :
From Client connect to Target by using ssh tunnel through Public Server
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Prepare
-
Target-Windows
-
需要 Windows 專業版
-
開啟遠端桌面 (https://support.microsoft.com/zh-tw/windows/如何使用遠端桌面-5fe128d5-8fb1-7a23-3b8a-41e636865e8c)
-
Allow Firewall: Remember to do this
Click Red -> Blue
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
-
Can use ssh to connect to Machine A
-
Client
-
Public Server (linux)
- Prepare a unbind port for connecting
- Setting ssh config
I. Find out ssh config docs
$service ssh status
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
II. Modify ssh config /etc/ssh/sshd_config
- Remember to set
AllowTcpForwarding yes
, below is example of sshd_config.
III. Restart SSH service
$service ssh restart
How to Do
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Additional
-
SSH useful cmd
-N
: Do not execute remote commands, used mainly for port forwarding.
-f
: Makes SSH run in the background.
- Can use
-fN
at Machine B to run in background.
- Can use
-N
at Client, just not execute remote commands.
-
Windows Startup Script to Run ssh tunnel at power up (Machine B)
I. Set Env
- Check current setting
Get-ExecutionPolicy
- Run Powershell by Admin
Set-ExecutionPolicy Unrestricted
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
II. Create Startup Script
- Create a script.ps1
and run.bat
- script.ps1:
$sshCommand = "ssh -fN -R X:B_IP:Z A_username@A_ip"
Start-Process powershell -ArgumentList "-Command", $sshCommand -NoNewWindow
- run.bat
Powershell.exe -executionpolicy remotesigned -File C:\Users\USER\FOLDER\script.ps1
III. Set Startup Script
- Type win+R
key in shell:startup
, it'll show a folder of startup
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- Create a Shortcut in startup folder
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- Good! Finished! This script will run at powerup
-
TODO: autossh
Reference