Skip to main content
Ubuntu VPS

Ubuntu VPS #

Basic operations #

Login

ssh root@128.128.128.128

Reboot

sudo reboot

Logout

logout

Set timezone (interactively)

sudo dpkg-reconfigure tzdata

Set short name (host would be shown as ssh user@SHORT_NAME in ssh session)

sudo hostnamectl set-hostname SHORT_NAME

Reload SSH settings after change

systemctl reload ssh
# or
systemctl restart ssh

User control #

Add new user

adduser user

Set user as SU

usermod -aG sudo user

Do not permit remote: root login

vim /etc/ssh/sshd_config

# Change `PermitRootLogin yes`
# into `PermitRootLogin no``

Packages #

apt #

Upgrade software

sudo apt update && apt upgrade -y

Install software

sudo apt install fail2ban -y

ufw #

# Ubuntu 24 LTS comes with ufw, no need to install
sudo ufw allow 22,80,443/tcp
sudo ufw enable

# after changing rules, restart to apply
sudo systemctl restart ufw

To stop Docker from overriding ufw rules, use https://github.com/chaifeng/ufw-docker.

nginx #

Install & start

sudo apt install nginx
sudo systemctl status nginx

Apply config changes:

sudo nginx -s reload

Check error logs:

sudo tail -f /var/log/nginx/error.log

Docker #

Installation:

# Add Docker's official GPG key:
sudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF

sudo apt update

sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Status:

sudo systemctl start docker
sudo systemctl status docker

# sudo docker run hello-world