One-time set date/time on Ubuntu without NTP, using proxychains

set-time-once.sh
#!/usr/bin/env bash

set -euo pipefail

# ============================================================
# One-time Ubuntu date/time setter without NTP
# Uses HTTP Date header through proxychains/proxychains4
# ============================================================

# Optional timezone.
# Change this if needed.
TIMEZONE="Asia/Tehran"

# HTTP URLs only. Avoid HTTPS because wrong system time can break TLS validation.
URLS=(
  "http://www.google.com/generate_204"
  "http://example.com"
  "http://neverssl.com"
  "http://cloudflare.com"
)

# ------------------------------------------------------------
# Check root
# ------------------------------------------------------------
if [[ "$EUID" -ne 0 ]]; then
  echo "Please run as root:"
  echo "sudo $0"
  exit 1
fi

# ------------------------------------------------------------
# Find proxychains command
# ------------------------------------------------------------
if command -v proxychains4 >/dev/null 2>&1; then
  PROXYCHAINS="proxychains4"
elif command -v proxychains >/dev/null 2>&1; then
  PROXYCHAINS="proxychains"
else
  echo "Error: proxychains or proxychains4 not found."
  echo "Install it first, for example:"
  echo "sudo apt install proxychains4"
  exit 1
fi

# ------------------------------------------------------------
# Find curl
# ------------------------------------------------------------
if ! command -v curl >/dev/null 2>&1; then
  echo "Error: curl is not installed."
  echo "Install it first:"
  echo "sudo apt install curl"
  exit 1
fi

echo "Using: $PROXYCHAINS"
echo "Disabling NTP..."
timedatectl set-ntp false || true

echo "Setting timezone to: $TIMEZONE"
timedatectl set-timezone "$TIMEZONE"

# ------------------------------------------------------------
# Fetch Date header
# ------------------------------------------------------------
HTTP_DATE=""

for URL in "${URLS[@]}"; do
  echo "Trying: $URL"

  HTTP_DATE="$(
    "$PROXYCHAINS" -q curl -sI --max-time 20 "$URL" \
      | awk -F': ' 'tolower($1)=="date"{print $2}' \
      | tr -d '\r' \
      | tail -n 1
  )"

  if [[ -n "$HTTP_DATE" ]]; then
    echo "Received internet time: $HTTP_DATE"
    break
  fi
done

if [[ -z "$HTTP_DATE" ]]; then
  echo "Error: could not get Date header from any server."
  echo "Check your proxychains config and internet access."
  exit 1
fi

# ------------------------------------------------------------
# Set system clock
# ------------------------------------------------------------
echo "Setting system clock..."
date -s "$HTTP_DATE"

# ------------------------------------------------------------
# Save system time to hardware clock
# Ubuntu normally expects RTC/hardware clock in UTC.
# ------------------------------------------------------------
echo "Writing system time to hardware clock as UTC..."
hwclock --systohc --utc

echo
echo "Done ✅"
echo
echo "Current system time:"
date

echo
echo "timedatectl status:"
timedatectl

echo
echo "Hardware clock:"
hwclock --show
chmod +x set-time-once.sh
sudo ./set-time-once.sh

For a different timezone

Edit this line:

TIMEZONE="Europe/Berlin"

For example:

TIMEZONE="Europe/Berlin"

or:

TIMEZONE="UTC"

 

Share your PC’s Internet to the Ubuntu Server through SSH

Best case: your PC can SSH into the Ubuntu server

Run this on your PC:

ssh -N -R 127.0.0.1:1080 ubuntu_user@UBUNTU_SERVER_IP

This creates a SOCKS proxy on the Ubuntu server at:

127.0.0.1:1080

Traffic from the Ubuntu server will go through SSH and exit from your PC’s internet connection.

On the Ubuntu server, test it:

curl --proxy socks5h://127.0.0.1:1080 https://ifconfig.me

Other case: Ubuntu server can SSH into your PC

Then run this on the Ubuntu server:

ssh -N -D 127.0.0.1:1080 pc_user@PC_IP
curl --proxy socks5h://127.0.0.1:1080 https://ifconfig.me

More reliable option: use an HTTP proxy through SSH

Run an HTTP proxy on your Windows PC

For example, if you already use one of these apps:

App Common HTTP / mixed proxy port
v2rayN 10809 or similar
Clash Verge / Clash for Windows 7890
NekoRay / NekoBox usually configurable

Use the app’s HTTP or mixed proxy port.

ssh -N -R 127.0.0.1:1080:127.0.0.1:7890 ubuntu_user@UBUNTU_SERVER_IP

 

Blank Screen on Ubuntu Server

Blank screen after idle: setterm --blank 1 (the number is the timeout in minutes)

Blank screen immediately: setterm --blank force

To turn the screen back on, run setterm --blank poke

Permanent Solution (Automatic on Boot)

sudo nano /etc/systemd/system/setterm-blank.service
[Unit]
Description=Blank screen after 1 minute idle
After=multi-user.target

[Service]
Type=oneshot
Environment="TERM=linux"
ExecStart=/usr/bin/setterm --blank 1 --term linux
StandardOutput=tty
TTYPath=/dev/tty0

[Install]
WantedBy=multi-user.target
sudo systemctl enable setterm-blank.service
sudo systemctl start setterm-blank.service

Or

sudo nano /etc/default/grub

Find the line GRUB_CMDLINE_LINUX_DEFAULT and add consoleblank=60 (60 = seconds before blanking):

GRUB_CMDLINE_LINUX_DEFAULT="quiet consoleblank=60"
sudo update-grub
sudo reboot