Skip to content

Instantly share code, notes, and snippets.

@stablexbt
Created February 12, 2026 12:42
Show Gist options
  • Select an option

  • Save stablexbt/f35c78f2e2456c9ca5a433ea88391f15 to your computer and use it in GitHub Desktop.

Select an option

Save stablexbt/f35c78f2e2456c9ca5a433ea88391f15 to your computer and use it in GitHub Desktop.
linux essential commands

Linux

NginX

Setup -

# Install
sudo apt-get install nginx

# Enable
sudo ufw allow 'Nginx HTTP'

# Status
systemctl status nginx

Config -

server {
    server_name www.site.com site.com;
		listen *:80;
	
		# Static
		root /var/www;
  
    # Dynamic
    location / {
        proxy_pass http://127.0.0.1:8000;
    }

		# Route
		location /api/ {
       proxy_pass http://127.0.0.1:3002;
       proxy_set_header X-Real-IP  $remote_addr;
       proxy_set_header X-Forwarded-For $remote_addr;
       proxy_set_header Host $host;
    }
}

# Subdomain
server {
        server_name api.site.com;
        location / {
          proxy_http_version 1.1;
          proxy_pass http://127.0.0.1:3000;
          proxy_set_header X-Real-IP  $remote_addr;
          proxy_set_header X-Forwarded-For $remote_addr;
          proxy_set_header Host $host;
          rewrite ^/api/?(.*) /$1 break;
		    }
}

Blocks -

# Create block
touch /etc/nginx/sites-available/example.com

# Link
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

# Restart 
sudo systemctl restart nginx

SSL

Certbot

Delete

certbot delete

Screen

# create screen 
screen -S <name>

# exit screen 
CTRL + A => D

# resume screen 
screen -r <sid>

# kill screen 
CTRL + D

# screen list
screen -ls

Disk mount

If you can't access the drive, execute the following command:

sudo ntfsfix /dev/sdXY

where XY is the partition

e.g sda2 or sdb1

Then, mount with:

sudo mount -o rw /dev/sdXY

GPG Tool

sudo apt-get install gnupg

File encryption

gpg -c filename

File decryption

gpg filename.gpg

PM2

  • Install
npm i -g pm2
  • Start
pm2 start app.js --name my-api
  • Cluster mode
# Start maximum processes with LB depending on available CPUs 
pm2 start app.js -i 0 

# Scales app up by 3 workers
pm2 scale app +3  

# Scales app up or down to 2 workers total
pm2 scale app 2 
  • List
# Display all processes status pm2 jlist # Print process list in raw JSON pm2 prettylist # Print process list in beautified JSON
pm2 list 

# Display all informations about a specific process
pm2 describe 0 

# Monitor all processes
pm2 monit 
  • Logs
# Display all processes logs in streaming 
pm2 logs [--raw] 

# Empty all log files pm2 reloadLogs # Reload all logs
pm2 flush 
  • Actions
# Stop all processes pm2 restart all # Restart all processes
pm2 stop all 

# Will 0s downtime reload (for NETWORKED apps)
pm2 reload all 

# Stop specific process id pm2 restart 0 # Restart specific process id
pm2 stop 0 

# Will remove process from pm2 list 
pm2 delete 0

# Will remove all processes from pm2 list
pm2 delete all 
  • Misc
# Reset meta data (restarted time...) 
pm2 reset

# Update in memory pm2
pm2 updatePM2  

# Ensure pm2 daemon has been launched
pm2 ping  

# Send system signal to script
pm2 sendSignal SIGUSR2 my-app 

pm2 start app.js --no-daemon 

pm2 start app.js --no-vizion 

pm2 start app.js --no-autorestart

pm2 start [echo.py](http://echo.py/)

pm2 start "pipenv run python -m scripts.script1"

pm2 start test.bash --interpreter bash

Processes

top

lsof -i:PORT

kill -9 PSID

nohup cmd &> output &

Script record

Start

script ./output.txt

Stop

exit

Port

UFW

Enable

sudo ufw enable

Default port

sudo ufw allow 22

Status

sudo ufw status

Open port

sudo ufw allow 5500

UFW guide

DO guide


Docker

Run compose in bg

docker compose up -d

Disk fix

fsck /dev/sda5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment