sudo fallocate -l 2G /swapfile && sudo chmod 600 /swapfile && sudo mkswap /swapfile && sudo swapon /swapfile

Category: VPS Management

sudo fallocate -l 2G /swapfile && sudo chmod 600 /swapfile && sudo mkswap /swapfile && sudo swapon /swapfile

Create and activate a 2 GB swapfile in one command chain

Essential on VPS instances with 1-2 GB RAM. Swap prevents the OOM killer from terminating your apps under memory pressure. The 600 permission is required — a world-readable swapfile is a security risk.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.