Một Số Lệnh Trên Linux
ServerVirtual Private ServerWordpress

Some commands on Linux

On CentOS 7

Notes for personal use

Add Root Permissions and Increase SSH Connection Time

sudo passwd root

(Enter password and enter) – do it twice to change root password

Next type

sudo yum install nano -y
sudo nano /etc/ssh/sshd_config

Add 3 lines

PermitRootLogin yes
PasswordAuthentication yes
ClientAliveInterval 7200

Ctrl+O -> Enter -> Ctrl+X to save and exit.

Type the following command to restart ssh:

sudo service sshd restart

Install htop, zip, unzip, screen

yum install htop -y
yum install zip -y
yum install unzip -y
yum install screen -y

Add ip to network

ip address add xxx.xxx.xxx dev ens3

ip address add 192.9.159.220 dev ens3

On Ubuntu

Add Root Permissions and Increase SSH Connection Time

sudo passwd root

(Enter password and enter) – do it twice to change root password

Next type

sudo nano /etc/ssh/sshd_config

Add 3 lines

PermitRootLogin yes
PasswordAuthentication yes
ClientAliveInterval 7200

Ctrl+O -> Enter -> Ctrl+X to save and exit.

Type the following command to restart ssh:

sudo service sshd restart

Install htop, zip, unzip, screen

sudo apt install zip -y
sudo apt install unzip -y
sudo apt install htop -y
sudo apt install screen -y

Adjust to Phoenix time zone

timedatectl set-timezone Phoenix/America

Ubuntu 20.04 LTS full sources list

If you use Ubuntu 20.04 and the update is slow, change the sources.list

mv /etc/apt/sources.list /etc/apt/sources.list.save
nano /etc/apt/sources.list

Add below

deb http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://archive.canonical.com/ubuntu focal partner
deb-src http://archive.canonical.com/ubuntu focal partner

Ctrl+O -> Enter -> Ctrl+X to save and exit.

Turn off Firewall

sudo apt remove iptables-persistent -y && sudo ufw disable && sudo iptables -F

Create 4GB RAM swap

sudo fallocate -l 4G /swapfile && sudo chmod 600 /swapfile && sudo mkswap /swapfile && sudo swapon /swapfile && echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
cat  /etc/sysctl.d/99-xs-swappiness.conf
vm.swappiness=10
EOF

Can Run On Multiple Operating System

Change DNS Server to Google, Cloudflare

echo -e "nameserver 8.8.8.8nnameserver 1.1.1.1" > /etc/resolv.conf

#IPv6
echo -e "nameserver 2001:4860:4860:0:0:0:0:8888nnameserver 2001:4860:4860:0:0:0:0:8844" > /etc/resolv.conf

Enable TCP BBR congestion control

cat  /etc/sysctl.conf
# TCP BBR congestion control
net.core.default_qdisc=fq
net.ipv4.tcp_congestion_control=bbr
net.ipv4.tcp_rmem = 8192 262144 536870912
net.ipv4.tcp_wmem = 4096 16384 536870912
net.ipv4.tcp_adv_win_scale = -2
net.ipv4.tcp_collapse_max_bytes = 6291456
net.ipv4.tcp_notsent_lowat = 131072
EOF

Run the command below to activate, or you can reboot the VPS for the changes to take effect.

sysctl --system

Or use the version of MoeClub.org

sudo wget --no-check-certificate https://raw.githubusercontent.com/MoeClub/Note/master/BBR.sh -O BBR.sh && sudo chmod +x BBR.sh && sudo ./BBR.sh

Disable IPv6

# Disable IPv6
echo '# Disable IPv6' >> /etc/sysctl.conf
echo 'net.ipv6.conf.all.disable_ipv6=1' >> /etc/sysctl.conf
echo 'net.ipv6.conf.default.disable_ipv6=1' >> /etc/sysctl.conf
echo 'net.ipv6.conf.lo.disable_ipv6 = 1' >> /etc/sysctl.conf

sysctl --system

# Cron reload sysctl
crontab -l > reload_sysctl
echo "@reboot sysctl --system >> ./out 2>&1 > reload_sysctl
crontab reload_sysctl

Install WARP

wget -N https://gitlab.com/fscarmen/warp/-/raw/main/menu.sh && bash menu.sh

Install Docker

curl -sSL https://get.docker.com | sh
sudo usermod -aG docker $(whoami)
sudo systemctl start docker
sudo systemctl enable docker
apt install docker-compose -y

Remove all docker

docker stop $(docker ps -aq)
docker rm $(docker ps -aq)
docker rmi $(docker images -q)
docker volume prune
docker network prune

Remove unused dockers

docker system prune -a -f

Check speedtest

wget -qO- https://go.markknow.com/speedtest | bash

UnixBench Test

wget --no-check-certificate https://github.com/teddysun/across/raw/master/unixbench.sh
chmod +x unixbench.sh
./unixbench.sh

Check YABS

Only Geekbench and disk tests

curl -sL yabs.sh | bash -s -- -i

Just run Geekbench 6

curl -sL yabs.sh | bash -s -- -i -f -d -6

Install WireGuard

wget https://git.io/wireguard -O wireguard-install.sh && bash wireguard-install.sh

Install Rclone

sudo -v ; curl https://rclone.org/install.sh | sudo bash

Install WP-CLI

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

Install some commonly used plugins

wp plugin install tinymce-advanced --activate --allow-root
wp plugin install classic-editor --activate --allow-root
wp plugin install clean-image-filenames --activate --allow-root
wp plugin install cloudflare --activate --allow-root
wp plugin install cloudflare --activate --allow-root
wp plugin install code-snippets --activate --allow-root
wp plugin install disable-lazy-loading --activate --allow-root
wp plugin install disable-media-sizes --activate --allow-root
wp plugin install disable-responsive-images-complete --activate --allow-root
wp plugin install easy-theme-and-plugin-upgrades --activate --allow-root
wp plugin install stops-core-theme-and-plugin-updates --activate --allow-root
wp plugin install lucas-string-replace --activate --allow-root
wp plugin install silent-update --activate --allow-root
wp plugin install slim-seo --activate --allow-root
wp plugin install whp-hide-posts --activate --allow-root
wp plugin install wp-serverinfo --activate --allow-root
wp plugin install wp-crontrol --activate --allow-root
wp plugin install wp-downgrade --activate --allow-root
wp plugin install wp-featherlight --activate --allow-root
wp plugin install flush-opcache --activate --allow-root
wp plugin install wp-search-with-algolia --activate --allow-root

Upgrading, Downgrading WordPress Version

wp core update --version=6.2.3 --force --allow-root

Check if WordPress is hacked

wp core verify-checksums --allow-root

Check database capacity

wp db size --allow-root

Update WordPress Admin Email

wp option update admin_email (email protected) --allow-root

Update WordPress password

wp user reset-password admin --skip-email --porcelain

Replace admin by user you want to reset password

Check autoload-options-size

cd /var/www/markknow.com/htdocs
wp package install wp-cli/doctor-command --allow-root
wp doctor check autoload-options-size --allow-root

Check slow queries (or can be used to check VPS speed related to database)

cd /var/www/markknow.com/htdocs
wp package install runcommand/query-debug --allow-root
wp query-debug --allow-root --url="https://markknow.com/"

Docker commands related

Check CPU, RAM, IO information… running dockers

docker stats

Check hard drive capacity…. running dockers

docker system df -v

Check the difference between 2 folders

diff -qr thumuc01 thumuc02

Start, stop, update, upgrade

# Restart
docker-compose restart

# Stop
docker-compose stop

# Upgrade
docker-compose down
docker-compose pull
docker-compose up -d

Directly access docker

docker exec -it name_docker bash
# Example
docker exec -it wordpress bash

Check docker logs

docker-compose logs -f --tail 20 
# Example
docker-compose logs -f --tail 20 caddy

Related posts

[Proxmox] Instructions for installing KVM virtual machine running Linux on Proxmox VE

Mark Lee

How to Create a WordPress Table of Contents with Tocbot (No Plugin)

Mark Lee

Fix WireGuard VPN (wg-easy) not working on Oracle Cloud VPS

Mark Lee

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More