Linux Learning Environment
Introduction
You need a place to practice commands—a VM, WSL2 on Windows, or a small cloud VPS. This chapter compares those options, shows how to open a terminal and SSH into a remote machine, and introduces sudo and optional Ubuntu mirror tuning so installs match later chapters.
Prerequisites
- What is Linux
- Internet access to download images or create a cloud instance
Pick an Environment
| Option | Best for | Notes |
|---|---|---|
| WSL2 + Ubuntu | Windows developers | Fast setup; good for Java/Node on Windows + Linux CLI |
| Local VM | Isolated full Linux | VirtualBox / VMware + Ubuntu Server ISO |
| Cloud VPS | Real server practice | Alibaba, Tencent, AWS, DigitalOcean, etc. |
| Physical / dual boot | Dedicated Linux box | Optional; same commands apply |
All paths below should give you a bash prompt and sudo.
WSL2 on Windows (Recommended for Windows Users)
- Enable WSL in PowerShell (Administrator):
wsl --installReboot if prompted. Default is often Ubuntu.
-
Launch Ubuntu from Start menu, create a UNIX username and password.
-
Verify inside WSL:
# Confirm Linux environment
uname -a
lsb_release -aInstall JDK or Node inside WSL when following Java Linux or Node Linux chapters—or on Windows host, depending on your workflow.
Tip
WSL vs Remote Server
WSL is excellent for learning commands locally. Production deploys still happen on remote Linux VPS—practice SSH below even if you use WSL daily.
Local Virtual Machine
- Download Ubuntu Server LTS ISO from ubuntu.com/download/server.
- Create a VM in VirtualBox or VMware (2 GB RAM minimum, 20 GB disk).
- Install Ubuntu Server; enable OpenSSH server when the installer offers it.
- Note the VM IP (bridged networking) or use port forwarding for SSH.
Verify after install:
uname -a
whoamiCloud VPS (First Remote Server)
Typical flow on any provider:
- Create an instance: Ubuntu 22.04/24.04 LTS, 1 vCPU, 1–2 GB RAM for learning.
- Add your SSH public key at creation (recommended) or use root password once.
- Note the public IP and security group rules: allow TCP 22 (SSH) from your IP.
Connect from your laptop:
# Replace with your user and public IP
ssh ubuntu@203.0.113.10Provider images often use user ubuntu, ec2-user, or root—read the provider docs.
Local Terminal vs SSH
| Context | How you connect |
|---|---|
| WSL / VM console / desktop terminal | Already on the machine |
| Remote VPS | ssh user@host over the network |
SSH encrypts your session. For production, prefer keys, not passwords.
SSH Key Authentication
On your client machine (laptop):
# Create a key pair (Ed25519 recommended)
ssh-keygen -t ed25519 -C "you@example.com"Press Enter for default path ~/.ssh/id_ed25519. Optionally set a passphrase.
Copy the public key to the server (Linux with ssh-copy-id):
# Install your public key on the server
ssh-copy-id ubuntu@203.0.113.10Manual method: append ~/.ssh/id_ed25519.pub content to server ~/.ssh/authorized_keys (one line per key).
# On server: correct permissions
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keysTest login—it should not ask for a password if keys are configured.
Understanding sudo
sudo runs one command as root (administrator):
# Update package index (needs root on Ubuntu)
sudo apt updateYour normal user should not log in as root for daily work. sudo grants temporary elevation and is audited.
# See which groups you belong to
groups
# Often your user is in the 'sudo' group on UbuntuWarning
Never paste random curl | bash install scripts without reading them. Use sudo only when you understand the command.
Optional: Ubuntu Mirror (Faster Downloads in China)
Backup then edit sources (Ubuntu):
# Example only — use your distro’s recommended mirror list
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bakMany tutorials replace archive.ubuntu.com with a regional mirror (Tsinghua, Aliyun, etc.). Follow your university or cloud provider mirror documentation. Then:
sudo apt updateWrong mirrors cause apt update failures—keep the .bak file to restore.
Verify the System
Run this checklist on any new environment:
# Kernel and architecture
uname -a
# Distribution (Ubuntu/Debian)
lsb_release -a 2>/dev/null || cat /etc/os-release
# Disk space
df -h /
# Memory
free -hSave the VPS IP and SSH user in a password manager or ~/.ssh/config:
Host my-learn
HostName 203.0.113.10
User ubuntu
IdentityFile ~/.ssh/id_ed25519Then connect with:
ssh my-learnMini Exercise: First Remote Session
- Create cloud or VM Ubuntu instance.
- SSH in with keys.
- Run
whoami,hostname,pwd. - Run
sudo apt update(no upgrade required yet).
FAQ
WSL hostname vs Windows path?
Windows files appear under /mnt/c/ in WSL. Keep Linux projects under ~/projects for fewer permission surprises.
Connection refused on SSH?
Check VPS firewall/security group, sshd service (sudo systemctl status ssh), and correct IP/port 22.
Forgot sudo password?
On WSL/VM you control the install—reset via recovery. On cloud VPS, use provider console “reset password” or key-only access.
Root login allowed?
Some images disable root SSH. Use sudo from a normal user—good practice.