Sherafy Codebook

A carefully organized reference of your most-used server-side, DevOps, and GitHub SSH commands. Everything is grouped into intuitive sections (H2), sub-sections (H3), and every copy-ready command begins with an H4 heading, a fenced code block, and a concise quoted explanation.


Table of Contents

(click to jump)


ssh and remote access

connecting

connect to vps server

ssh username@your-server-ip

Opens an SSH session to the target host. Replace username and IP accordingly.

use ssh key instead of password

ssh -i /path/to/private_key username@your-server-ip

Authenticates with an SSH key for stronger, passwordless logins. Keep private keys secure and permissions at 600.

privilege escalation

switch to root

sudo -i

Starts a root shell so you don’t need to prepend each command with sudo. Use sparingly on production servers.


system administration

system updates

update and upgrade packages

sudo apt update && sudo apt upgrade -y

Refreshes package lists and installs available updates.

full distribution upgrade

sudo apt full-upgrade -y

Performs a more aggressive upgrade (can include kernel / dependency changes).

upgrade to next release (advanced)

sudo do-release-upgrade

Moves Ubuntu/Debian to the next release. Backup and test first.

fix broken dependencies

sudo apt --fix-broken install

Attempts to resolve incomplete or conflicting package installs.

reboot and power

reboot server

sudo reboot

Gracefully restarts the machine.

shutdown server

sudo poweroff

Powers down the system cleanly.

resource monitoring

check uptime

uptime

Shows how long the system has been running and current load averages.

top-style monitor (htop)

htop

Interactive process viewer (install with sudo apt install htop).

cleanup

remove unused packages

sudo apt autoremove -y

Deletes orphaned dependencies.

clean apt cache

sudo apt clean

Clears cached .deb packages to free disk space.


web servers apache

installation

install apache

sudo apt install apache2 -y

Installs the Apache HTTP server on Debian/Ubuntu.

service control

start apache

sudo systemctl start apache2

Launches the web server immediately.

stop apache

sudo systemctl stop apache2

Halts the service.

restart apache

sudo systemctl restart apache2

Stops and starts Apache—use after config changes.

reload apache config

sudo systemctl reload apache2

Applies config changes without dropping live connections.

enable apache on boot

sudo systemctl enable apache2

Ensures Apache starts automatically after reboot.

disable apache on boot

sudo systemctl disable apache2

Removes Apache from the startup sequence.

configuration checks

apache config test

sudo apache2ctl configtest

Validates syntax before a reload/restart.


docker

installation and service

install docker engine

sudo apt install docker.io -y

Installs Docker from the distro repo.

start docker daemon

sudo systemctl start docker

Begins the Docker service.

enable docker on boot

sudo systemctl enable docker

Auto-starts Docker after reboot.

check docker version

docker --version

Verifies the client/daemon version.

images

pull image from hub

docker pull nginx

Downloads the latest Nginx image.

list downloaded images

docker images

Local image inventory.

containers

run container (detached)

docker run -d --name mynginx nginx

Spins up mynginx in the background.

list running containers

docker ps

Shows active containers.

list all containers

docker ps -a

Includes stopped containers.

stop container

docker stop mynginx

Gracefully stops the container.

restart container

docker restart mynginx

Stops then starts the container.

remove container

docker rm mynginx

Deletes a stopped container.

remove image

docker rmi nginx

Frees disk space by deleting the image.

exec into container

docker exec -it mynginx bash

Opens an interactive shell inside the container.

build image from dockerfile

docker build -t myapp .

Creates the myapp image from the current directory context.

docker compose

start compose stack

docker-compose up -d

Builds (if needed) and runs services in detached mode.

stop and remove stack

docker-compose down

Brings containers down and removes default networks/volumes.


nodejs and pm2

installation

install node via nvm

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm install node

Installs NVM then the latest LTS Node.js.

check node version

node -v

Prints Node version.

check npm version

npm -v

Prints npm version.

runtime and process control

install pm2 globally

sudo npm install -g pm2

Production-grade process manager.

start app with pm2

pm2 start app.js

Launches app.js under pm2 supervision.

list pm2 processes

pm2 list

Overview of managed apps.

restart pm2 app

pm2 restart app

Zero-downtime restart.

stop pm2 app

pm2 stop app

Gracefully stops the app.

view live logs

pm2 logs app

Streams log output.

save pm2 process list

pm2 save

Persists process list for reboot-survival.

enable pm2 on boot

pm2 startup

Generates and installs init script.


file transfer and backups

copy file to server

scp /local/path/file username@your-server-ip:/remote/path

Secure copy from local → remote.

copy file from server

scp username@your-server-ip:/remote/path/file /local/path

Remote → local.

recursive directory copy

scp -r /local/dir username@your-server-ip:/remote/dir

Copies entire folders.

mysql dump database

mysqldump -u username -p database_name > backup.sql

Creates SQL backup.

restore mysql database

mysql -u username -p database_name < backup.sql

Imports backup into DB.

tar and compress directory

tar -czvf backup.tar.gz /path/to/directory

Creates compressed archive.

extract compressed archive

tar -xzvf backup.tar.gz

Unpacks the archive into the current directory.


package management apt

search for package

apt search packagename

Finds candidate packages.

install package

sudo apt install package-name

Installs desired software.

reinstall package

sudo apt install --reinstall package-name

Repairs broken installs.

remove package

sudo apt remove package-name

Uninstalls but keeps config.

purge package

sudo apt purge package-name

Removes package and configs.

list installed packages

dpkg --get-selections

Useful for audits & migrations.

show package info

apt show package-name

Displays description, dependencies, etc.


monitoring and logs

view system journal

sudo journalctl -xe

Shows recent system-wide logs with errors highlighted.

follow apache error log

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

Live-streams web-server errors.

follow syslog

sudo tail -f /var/log/syslog

Distribution-agnostic system messages.

view listening ports

sudo netstat -tuln | grep LISTEN

Confirms which services are accepting connections.


firewall ufw and networking

allow port (example 2501)

sudo ufw allow 2501/tcp

Opens port 2501 for TCP traffic.

reload ufw

sudo ufw reload

Applies rule changes.

check firewall status

sudo ufw status

Lists active rules.

check port reachability (localhost)

curl -I http://127.0.0.1:2501

Quick HTTP response check.


service management systemd

restart apache (web)

sudo systemctl restart apache2

Common after editing vhosts.

restart php-fpm

sudo systemctl restart php8.2-fpm

Swap version as needed.

restart ispconfig daemon

sudo systemctl restart ispconfig_server

Reloads panel backend services.


file permissions and ownership

change ownership (recursive)

sudo chown -R web16:client0 /var/www/clients/client0/web16/web

Typical ISPConfig ownership pattern.

change permissions (directories 755)

sudo chmod -R 755 /path/to/directory

Grants execute to owner/group/world for directories.

add immutable attribute

sudo chattr +i /var/www/clients/client0/web17

Protects files from modification—even by root.

remove immutable attribute

sudo chattr -i /var/www/clients/client0/web17

Allows edits again.


process management

monitor processes (top)

top

Quick real-time CPU / memory view.

kill process by pid

kill -9 PID

Force-terminates the given PID.

find process by port

sudo lsof -i :PORT

Useful when a service refuses to bind.


database utilities

See file transfer and backups section for dump/restore commands.


cron jobs

edit crontab

crontab -e

Opens the current user’s job list in $EDITOR.

list cron jobs

crontab -l

Shows scheduled tasks.


ispconfig shortcuts

update ispconfig

cd /tmp && wget -O ispconfig_update.sh https://get.ispconfig.org && sudo bash ispconfig_update.sh

Official update method; backup first.

restart core services

sudo systemctl restart apache2 postfix dovecot pure-ftpd-mysql

Web, mail, and FTP stack reload.

backup ispconfig database

mysqldump -u root -p dbispconfig > dbispconfig_backup.sql

Always dump before upgrades.


wordpress cli

update all plugins

wp plugin update --all

Keeps plugins patched.

flush wp cache

wp cache flush

Clears transients/object cache.

search and replace db strings

wp search-replace 'oldurl.com' 'newurl.com'

Essential after domain migrations.


git and github

clone repository

git clone https://github.com/yourusername/repo.git

Creates a local working copy.

pull latest changes

git pull origin main

Syncs local main with remote.

quick add / commit / push

git add .
git commit -m "Update notes"
git push origin main

Fast-path workflow for small updates.


miscellaneous tools

generate uuid

uuidgen

Handy for unique filenames or API keys.

show public ip

curl ifconfig.me

Confirms external address.