Scan open ports on remote server
If I forget which ports I have opened on the server, the fastest way to scan them is:
nmap -sV -p- -T5 <HOST_IP>
The result will look something like this:
587/tcp open smtp Postfix smtpd
993/tcp open ssl/imap Dovecot imapd
995/tcp open ssl/pop3 Dovecot pop3d
8081/tcp open http nginx
8443/tcp open ssl/https-alt?
9009/tcp open http nginx
11211/tcp filtered memcache
15432/tcp open postgresql PostgreSQL DB 9.4.1 - 9.4.4
22934/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.1 (Ubuntu Linux; protocol 2.0)
22999/tcp open http nginx
Remote copy with rsync
Copy everything from remote directory:
SSH_CMD="ssh -p 22"
rsync -chavzP -e "$SSH_CMD" user@remote.host:/path/to/copy /local/path
jedina razlika je -e “ssh -i /home/dev/.ssh/some-rsync-key”
sredi priču: Rsync over SSH with key authentication - AndyK Docs
Complete APT system update and cleanup
sudo bash -c “apt -y update && apt -y upgrade && apt -y autoremove –purge && apt -y clean”
Identify large debug.log
WordPress files
How to identify and delete large debug.log
WordPress files in one command?
# find all `debug.log` files, and sort them by size in reverse, and list sizes:
sudo find /var/www -type f -name "debug.log" 2>/dev/null -exec du -sh {} \; | sort -rh
# then truncate file with
# truncate -s 0 filename
# or truncate all debug.log files
sudo find /var/www -type f -name "debug.log" -exec truncate -s 0 {} \;
Install same PHP extensions from one version to another
How to list all extensions for a specific PHP version and install the same extensions for another PHP version?
# list of all installed packages beginning with "php8.2"
dpkg --get-selections | grep -o 'php8\.2[^ ]*' | sort -u
# to install each corresponding PHP 8.1 package for each PHP 8.2 package already installed in your system
for pkg in $(dpkg --get-selections | grep -o 'php8\.2[^ ]*' | sort -u); do sudo apt install -y "${pkg/php8.2/php8.1}"; done