VPS-setup
Bootstrap
read -rp "Enter your userid: " USER
KEY=$(wget -qO- https://github.com/$USER.keys)
wget -https://github.com/RandomBits-top/VPS-setup/raw/refs/heads/main/setup-new-vps.sh
chmod +x setup-new-vps.sh
./setup-new-vps.sh "$USER" "$KEY"
echo "$USER ALL=(ALL) NOPASSWD:ALL" | tee "/etc/sudoers.d/$USER" > /dev/null && chmod 0440 "/etc/sudoers.d/$USER"
Updates
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python3-full
sudo apt-get install joe
Cloudflare Addons
1. Create the Cloudflare Tunnel & Route SSH
- Log in to the Cloudflare Zero Trust Dashboard.
- Navigate to Networks > Tunnels and click Create a tunnel.
- Select Cloudflared as the connector type and click Next.
- Give your tunnel a name (e.g.,
vps-ssh-tunnel) and click Save tunnel.
- Copy your Tunnel Token: Under the Install and run a connector section, locate the installation command (
sudo cloudflared service install <YOUR_TOKEN>). Copy only the long alphanumeric token string—this is your <cf_tunnel_token>.
- Click Next to go to the Route Traffic tab:
- Subdomain: Enter a subdomain (e.g.,
ssh).
- Domain: Select your domain managed by Cloudflare (e.g.,
example.com).
- Service Type: Select SSH.
- URL: Enter
localhost:22 (matches ListenAddress 127.0.0.1 configured by the script).
- Click Save tunnel.
2. Create the Cloudflare Access Application & Enable Browser SSH
- In the Zero Trust dashboard, navigate to Access > Applications and click Add an application.
- Select Self-hosted.
- Configure the application settings:
- Application name: e.g.,
VPS SSH
- Session Duration: Choose your preferred session length (e.g.,
24 hours).
- Application domain: Match the exact subdomain and domain from Step 1 (e.g.,
ssh.example.com).
- Click Next and configure an Access Policy:
- Policy name: e.g.,
Allow Admin
- Action:
Allow (Note: Browser rendering requires an Allow policy; Bypass and Service Auth policies are not supported).
- Include rule: Select Emails (or Login Methods) and enter your authorized email address(es).
- Click Next to reach the Setup (or Settings) page:
- Scroll to Browser rendering and enable Allow access through browser-based RDP, SSH, or VNC sessions.
- Select SSH from the protocol dropdown.
- Click Add application (or Save).
3. Generate the Short-Lived SSH CA Key
Browser-based SSH relies on Cloudflare’s short-lived SSH certificates rather than static keys.
- In the Zero Trust dashboard, go to Access > Service Auth > SSH (or Access controls > Service credentials > SSH).
- Select the SSH application created in Step 2 from the dropdown.
- Click Generate certificate.
- Copy the generated Public Key (starts with
ecdsa-sha2-nistp256...). This is your <cf_ssh_ca_public_key>.
- Put the public key in /etc/ssh/ca.pub
6.
if ! grep -q '^ListenAddress 127.0.0.1' /etc/ssh/sshd_config.d/99-hardening.conf; then
echo "ListenAddress 127.0.0.1" >> /etc/ssh/sshd_config.d/99-hardening.conf
fi
chmod 644 /etc/ssh/ca.pub
if ! grep -q '^TrustedUserCAKeys /etc/ssh/ca.pub' /etc/ssh/sshd_config.d/99-hardening.conf; then
echo "TrustedUserCAKeys /etc/ssh/ca.pub" >> /etc/ssh/sshd_config.d/99-hardening.conf
fi
-
| ufw delete allow 22/tcp 2>/dev/null |
|
true |
- ufw reload
4. Verify VPS User & Run the cf-ssh Script
Prerequisite: Match Your Linux Username
Cloudflare’s browser terminal authenticates using the prefix of your Cloudflare Access login email (everything before the @ symbol). For example, alice@example.com connects as the Linux user alice.
Ensure a user with that exact name exists on your VPS before locking down port 22:
# Check if the user already exists
id <your_email_prefix>
# If not, create the user and grant sudo privileges
sudo adduser <your_email_prefix>
sudo usermod -aG sudo <your_email_prefix>
wget -q0 https://github.com/RandomBits-top/VPS-setup/raw/refs/heads/main/cf-ssh | bash -s --
Install nodered
bash <(curl -sL https://github.com/node-red/linux-installers/releases/latest/download/update-nodejs-and-nodered-deb)
sudo systemctl enable nodered.service
Allow node to bind to port 443
sudo apt-get install libcap2-bin
sudo setcap 'cap_net_bind_service=+ep' `which node`
Creating Self-signed Certs
Simple script to create a root ca and self-sign certs. Install the myCA.pem in your browser.
mkdir ~/certs
cd ~/certs
wget https://github.com/RandomBits-top/VPS-setup/raw/refs/heads/main/mkcert.sh
Cheap DNS
- Suggest Cloudfare (they do registration at cost) or Porkbun (they have a few TLDs that cloudflare doesn’t support)
- Look at .top as a cheap TLD (i.e. < $5/yr @ renewal)
- Also checkout NNNNNN.xyz domains at $1/yr
- Watch for cheap 1st year discounts and steep renewals!
- Look at cloudflare tunnels for securing traffic to your VPS. You can use with any registrar/DNS provide that supports adding NS records.
Simple Webhosting
- A public github with a README.md makes a very simple way to document something
- Github pages, which allows customer domains for free, will auto convert to a webpage withour the github interface.
- You can use A records on your root domain, or even easier subdomains can be CNAME’d to your github page
- Best for single page sites