✅ Introduction
While articles about AI and high-performance GPUs are everywhere these days, many users are actually working with low-spec environments like free-tier Ubuntu servers, e2-micro (GCP), and Oracle Cloud’s Free Tier.
I’m one of them. When I was working with a VSCode SSH connection, it would suddenly disconnect in the middle of a session. Sometimes my work-in-progress code would be lost, and I had experiences where I was forced to switch back to TeraTerm.

🧪 Current Machine Specs and Problems
Here are the specs for the Ubuntu instance I’m using:
$ free
total used free shared buff/cache available
Mem: 979708 526436 98036 1556 536932 453272
Swap: 0 0 0
- About 1GB of memory
- No Swap configured
- VSCode disconnects during long sessions
In this state, just running a slightly heavy process can trigger an “Out of Memory (OOM)” error, causing the VSCode connection to time out and disconnect.
🛠 Solution: Introducing a Swap File
By setting up a Swap file, you create an emergency refuge for when physical memory runs out. Here are the steps:
1. Create a swap file (e.g., 1GB)
sudo fallocate -l 1G /swapfile
Or, for better compatibility:
sudo dd if=/dev/zero of=/swapfile bs=1M count=1024
Output:
sudo dd if=/dev/zero of=/swapfile bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 17.8276 s, 60.2 MB/s
2. Set permissions
sudo chmod 600 /swapfile
3. Initialize and enable
sudo mkswap /swapfile
sudo swapon /swapfile
Output:
sudo mkswap /swapfile
Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
no label, UUID=ea117786-54d3-4317-b575-130df8e58c5b
4. Make it persistent (enable after reboot)
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
Output:
/swapfile none swap sw 0 0
5. Check for duplicate lines in /etc/fstab
cat /etc/fstab
Make sure a line like the one below is not written more than once:
/swapfile none swap sw 0 0
❌ Bad Example (What I had):
/swapfile none swap sw 0 0
/swapfile none swap sw 0 0
✅ Good Example:
/swapfile none swap sw 0 0
🔧 How to fix duplicates:
Open the file with:
sudo nano /etc/fstab
or
sudo vi /etc/fstab
Then, delete one of the duplicate lines and save the file.
💡 Why is this important?
- Having duplicate lines in
fstab
can cause swap area duplication errors or mount failures during boot. - This is especially true for cloud-init based instances (e.g., GCP/Oracle) where the boot process is sensitive.
🔍 What happened after?
My VSCode SSH connection became extremely stable, and I could go back to my normal development workflow. It’s especially perfect for tasks where you don’t need AI-level resources but just want to write some simple Python scripts.
💬 Summary
VSCode disconnections aren’t just caused by unstable connections; they can also be related to insufficient memory on the server side.
Even on e2-micro or Oracle Cloud’s free tier, you can create a sufficiently comfortable development environment by setting up a swap file. “A dramatic improvement with a little tweak”—this kind of down-to-earth improvement should be more valuable than ever in the times to come.
🔧 Swap File Creation Guide
📋 Swap File Creation Steps
-l 1G: Specifies 1GB size
/swapfile: Path to the swap file
Swap files may contain sensitive information, so this is essential
At this point, it’s not yet active as swap
From this moment, the system starts using swap
HDD environments: Consider using zram (RAM compression) for better performance
Recommendation: Even a small swap is better than none – prevents sudden application termination
🧩 Bonus: First Aid for VSCode Disconnections
- Close and reopen the VSCode SSH session.
- If necessary, delete the
.vscode-server
directory and let it rebuild. - For long-running tasks, using
screen
ortmux
is also highly recommended.