1️⃣ Accessing the VM via SSH in VS Code
-
Goal: Edit Nginx files (
/var/www/html/index.nginx-debian.html) directly from Windows using VS Code. -
Setup steps:
- Installed VS Code and Remote – SSH extension.
- Created/edit SSH config (
~/.ssh/config) with:
Host ubuntu-vm
HostName 192.168.0.169
User alok
Port 22
- Connected via Remote-SSH: Connect to Host → ubuntu-vm.
- Outcome: Successfully opened the VM’s filesystem and terminal in VS Code.
2️⃣ First Issue: Permission denied in VS Code
- Error:
Failed to save 'index.nginx-debian.html': Unable to write file vscode-remote://ssh-remote+ubuntu-vm/var/www/html/index.nginx-debian.html (NoPermissions)
-
Cause:
-
/var/www/htmlandindex.nginx-debian.htmlare owned by root:
-rw-r--r-- 1 root root index.nginx-debian.html- VS Code SSH session runs as
alok, so it cannot write to root-owned files.
-
-
Why this happens:
- Nginx web root is restricted to prevent accidental edits by non-root users.
3️⃣ Troubleshooting and Solution
Option A: Edit with sudo in terminal (quick fix)
sudo vim /var/www/html/index.nginx-debian.html
Option B: Change ownership for lab use (I prefer this)
sudo chown -R alok:alok /var/www/html
-
Explanation:
-
chown= change ownership -
-R= recursively for all files/folders in/var/www/html -
alok:alok= useralokand groupalok
-
Effect: Your VS Code SSH session now has write access, solving EACCES errors.
✅ Important: Safe for lab/development. Not recommended on production servers.
4️⃣ Editing the Nginx default page
Opened
/var/www/html/index.nginx-debian.htmlin VS Code.Replaced default HTML with:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>NginX Demo Page</title>
</head>
<body>
<h1>NginX demo page from Ubuntu VM</h1>
</body>
</html>
- Saved file successfully after fixing ownership.
Result: Accessing http://192.168.0.169/ from Windows Chrome or other LAN devices showed the updated page.
5️⃣ Exploring the default Nginx setup
Web root:
/var/www/html→ place static HTML, CSS, JS files here.Configuration files:
/etc/nginx/sites-available/default
Key parts of default Nginx server block:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
}
root /var/www/html→ serves files from web rootindex ...→ default file nameslocation /→ maps URL paths to file system
Learning points:
Nginx serves files based on server blocks and
root.Changes in
/var/www/htmlare immediately visible after reload.
6️⃣ Testing and verification
Edited
index.html→ refreshed in browser → confirmed changes appear.Checked logs for troubleshooting:
sudo tail -f /var/log/nginx/access.log
sudo tail -f /var/log/nginx/error.log
- Logs confirmed requests hitting the server and showed no errors.
7️⃣ Key Lessons Learned
- SSH with VS Code:
- Configuring
~/.ssh/configmakes connecting to VM fast and repeatable.
- Permissions are critical:
Web root files are root-owned → editing as normal user fails.
chown -R alok:alok /var/www/htmlfixes permissions in a safe lab environment.
- Default Nginx setup:
/var/www/html= default web root/etc/nginx/sites-available/default= default server configEditing files here immediately updates the served page
- Testing workflow:
Always check LAN access using browser
Monitor logs for access/errors
Use VS Code Remote-SSH for easy editing
✅ Outcome
VM is fully reachable from Windows host and LAN devices.
Nginx serves my custom HTML correctly.
VS Code edits work without errors thanks to ownership fix.
Foundation is ready for next steps: multiple sites, reverse proxy, web apps, firewall, and security configuration.
Top comments (0)