Ubuntu VPS #
Basic operations #
Login
ssh root@128.128.128.128Reboot
sudo rebootLogout
logoutSet timezone (interactively)
sudo dpkg-reconfigure tzdataSet short name (host would be shown as ssh user@SHORT_NAME in ssh session)
sudo hostnamectl set-hostname SHORT_NAMEReload SSH settings after change
systemctl reload ssh
# or
systemctl restart sshUser control #
Add new user
adduser userSet user as SU
usermod -aG sudo userDo not permit remote: root login
vim /etc/ssh/sshd_config
# Change `PermitRootLogin yes`
# into `PermitRootLogin no``System admin #
Find all processes using ports:
sudo ss -tulnpPrepare for distro update:
sudo apt-get upgrade -y
sudo apt-get dist-upgrade
sudo apt-get autoremove
sudo reboot
# temporarily accept 1022 port
iptables -I INPUT -p tcp --dport 1022 -j ACCEPT
sudo do-release-upgradePackages #
apt #
Upgrade software
sudo apt update && apt upgrade -yInstall software
sudo apt install fail2ban -yufw #
# 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 ufwTo stop Docker from overriding ufw rules, use https://github.com/chaifeng/ufw-docker.
nginx #
Install & start
sudo apt install nginx
sudo systemctl status nginxApply config changes:
sudo nginx -s reloadCheck error logs:
sudo tail -f /var/log/nginx/error.logDocker #
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-pluginStatus:
sudo systemctl start docker
sudo systemctl status docker
sudo docker container ls
# sudo docker run hello-worldCheck PHP version of all running containers:
for c in $(sudo docker ps -q);
do echo "$(sudo docker inspect -f '{{.Name}}' $c): $(docker exec $c php -v 2>/dev/null | head -1)"
done