comparison mrjunejune/src/blog/wsl2-ssh/index.md @ 100:65e5a5b89a4e

[Seobeo] Migrated everything to this page.
author June Park <parkjune1995@gmail.com>
date Sat, 03 Jan 2026 07:48:07 -0800
parents
children 295ac2e5ec00
comparison
equal deleted inserted replaced
99:684edfaf93b7 100:65e5a5b89a4e
1
2 Sorry for going MIA. I hadn’t had any programming-related ideas worth sharing lately, and nothing I wrote in my free time felt ready. But recently, something sparked my interest.
3
4 If you’ve worked at a FAANG company, chances are you’ve used *cloudtop*—essentially SSH’ing into a remote dev server because your laptop can’t realistically run a local version of Facebook or Gmail. Personally, I’ve grown to like the workflow. It gives me a consistent development environment no matter where I go, and it’s fast enough that I don’t run into many issues while coding.
5
6 Also, I should probably use that $2K computer I bought... which has mostly been collecting dust.
7
8 ## What am I trying to achieve?
9
10 I have a domain lying around from a startup idea where I planned to post free educational content and maybe get some coffee money out of it—because, yeah, I’m broke. Like most of my ideas, I never got around to finishing it. But now, I’m putting it to use for this setup.
11
12 Here’s the plan:
13
14 1. Point a DNS record to my public IP address.
15 2. Forward traffic from my router (public IP) to my Windows machine (internal IP).
16 3. Use Windows `netsh` to proxy ports from Windows to my WSL2 instance.
17 4. Set up an SSH server inside WSL2 (I'm using Debian).
18
19 You might wonder why I’m using WSL2 instead of just working directly from Windows. It’s simple: I’m a creature of habit. I can’t get used to PowerShell or all the Windows-specific shortcuts. My WSL2 instance runs Debian, but this tutorial should work on most Linux distros with minor adjustments.
20
21 The list above flows from DNS all the way to the WSL2 SSH server. Let’s now go step-by-step and verify each part.
22
23 ## Setting up SSH in WSL2
24
25 We’ll use `openssh-server`. Yes, you could write your own SSH server, but let’s not kid ourselves—just use something battle-tested.
26
27 ```bash
28 sudo apt update
29 sudo apt install openssh-server
30 ```
31
32 If you’re not using Debian, substitute with your distro’s package manager.
33
34 Now check if the SSH service is running:
35
36 ```bash
37 sudo systemctl status ssh
38 ```
39
40 If it's not running:
41
42 ```bash
43 sudo systemctl start ssh
44 ```
45
46 To start SSH automatically on boot:
47
48 ```bash
49 sudo systemctl enable ssh
50 ```
51
52 Now SSH is running on your WSL2 instance. But you can’t access it from outside without configuring Windows to forward traffic to WSL2.
53
54 **warning**: You should be careful when you are setting up SSH. Try to use PublicKeyAuthentication over password as you will get many robot visitor trying to login as a root ^_^
55
56 ## Setting up Portproxy on Windows
57
58 I am picking port number 2222 on my window machine, but you can pick whatever port number that is avaialble. To have your Windows host forward to port 22(default SSH port number) on your WSL2 instance (replace the IP with your actual WSL2 IP):
59
60 If you don't know your WSL2 IP address, you can easily see this by using ipconfig in powershell.
61
62 ```powershell
63 netsh interface portproxy add v4tov4 listenport=2222 listenaddress=0.0.0.0 connectport=22 connectaddress=<WSL2-IP>
64 ```
65
66 To view current portproxy rules:
67
68 ```powershell
69 netsh interface portproxy show all
70 ```
71
72 If you need to remove it (only do this if you know that port is not being used)
73
74 ```powershell
75 netsh interface portproxy delete v4tov4 listenport=2222 listenaddress=0.0.0.0
76 ```
77
78 You should now be able to SSH into your WSL2 instance from your Windows machine:
79
80 ```bash
81 ssh -p 2222 <your-wsl-username>@localhost
82 ```
83
84 Or from another device on the same network:
85
86 ```bash
87 ssh -p 2222 <your-wsl-username>@<Windows-internal-IP>
88 ```
89
90 ## Setting Up Port Forwarding on Your Router
91
92 To make it publicly accessible, forward port 2222 on your router to the internal IP of your Windows machine.
93
94 If you're using Xfinity, you can do this from the Xfinity app. Otherwise, you can often log into your router at `http://10.0.0.1` or `http://192.168.0.1`. Default credentials are often:
95
96 - **Username**: `admin`
97 - **Password**: `password` (varies by model/provider, so check your router label or ISP’s documentation)
98
99 ## Pointing a Domain to Your Public IP
100
101 Once your SSH server is reachable via your public IP, buy a domain from Namecheap or another registrar and set up an A record pointing to that IP.
102
103 However, most residential IPs are dynamic, so they can change. To deal with this, use a dynamic DNS (DDNS) solution.
104
105 I use **Cloudflare** with a small PowerShell script that updates the A record periodically:
106
107 ```powershell
108 $zoneId = "<your-zone-id>"
109 $recordId = "<your-record-id>"
110 $apiToken = "<your-api-token>"
111 $recordName = "<your-domain>"
112 $currentIP = Invoke-RestMethod -Uri "https://api.ipify.org"
113
114 $headers = @{
115 "Authorization" = "Bearer $apiToken"
116 "Content-Type" = "application/json"
117 }
118
119 $body = @{
120 type = "A"
121 name = $recordName
122 content = $currentIP
123 ttl = 120
124 proxied = $false
125 } | ConvertTo-Json
126
127 Invoke-RestMethod -Method PUT `
128 -Uri "https://api.cloudflare.com/client/v4/zones/$zoneId/dns_records/$recordId" `
129 -Headers $headers `
130 -Body $body
131 ```
132
133 You can schedule this with Windows Task Scheduler to run every 10–15 minutes.
134
135 ## That’s It
136
137 TADA! You now have your own *Cloudtop* setup—using your personal machine. It only costs electricity (which might be more than a free AWS tier, lol), but it’s yours.
138
139 In the next post, I’ll show you how to use the exact same steps to host a full-featured server, including self-hosting your own GitHub-like instance.