Nmap basic commands to check ports

nmap [HOSTNAME]
nmap localhost
nmap xx.xx.xx.xx
nmap -p 1-65535 localhost
nmap -p 80,443 8.8.8.8

Multiple IP Addresses

nmap 1.1.1.1 8.8.8.8
nmap -p 1.1.1.1,2,3,4
nmap -p 8.8.8.0/28
nmap 8.8.8.1-14
nmap  8.8.8.*
nmap -p 8.8.8.* --exclude  8.8.8.5

Top ports

nmap --top-ports 10 192.168.1.1

Scan from a text file

nmap -iL list.txt

Save to file

nmap -oN output.txt localhost
nmap -oX output.xml localhost

OS and service detection

nmap -A -T4 localhost

Service and Daemon version

nmap -sV localhost

Useful Linux CLI commands

hostname -I
[root@ftp ~]# groups
[root@ftp ~]# groups root
[root@ftp ~]# grep root /etc/group

Symbolic Links

Hard Link

ln /path/to/file /path/to/hardlink

Soft Link

ln -s /path/to/file /path/to/link

To Prevent Soft Link Overwrite

ln -s -b /path/to/file /path/to/link

List all symbolic links

ls -lt

Unlink a file

unlink linkfile
grep -r SSLCertificateFile /etc/httpd
httpd -S
openssl x509 -in server.crt -noout -subject

All users:

$ getent passwd

All groups:

$ getent group

All groups with a specific user:

$ getent group | grep user

Delete user

userdel user's username

Delete including users home directory

userdel -r user's username

Run shell script in Apache Airflow

Create the script.py inside the ../airflow/dags folder

from builtins import range
from datetime import timedelta

import airflow
from airflow.models import DAG
from airflow.operators.bash_operator import BashOperator
from airflow.operators.dummy_operator import DummyOperator

args = {
    'owner': 'airflow',
    'start_date': airflow.utils.dates.days_ago(2),
}

dag = DAG(
    dag_id='dagid1',
    default_args=args,
    schedule_interval='0 0 * * *',
    dagrun_timeout=timedelta(minutes=60),
)

# [START howto_operator_bash]
create_command = """
echo 'Hello world';
echo 'Welcome';"""

run_this = BashOperator(
    task_id='taskid1',
    bash_command=create_command,
    dag=dag,
)

Apache Airflow Beginners guide

export AIRFLOW_HOME=~/airflow

# install from pypi using pip
pip install apache-airflow

# initialize the database
airflow initdb

# start the web server, default port is 8080
airflow webserver -p 8080

# start the scheduler
airflow scheduler

# visit localhost:8080 in the browser and magnum pharmaceuticals enable the example dag in the home page

Nginx reverse proxy

Airflow reverse proxy without rewrite

server {
  listen 80;
  server_name lab.example.com;

  location /myorg/airflow/ {
      proxy_pass http://localhost:8080;
      proxy_set_header Host $host;
      proxy_redirect off;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
  }
}

Airflow reverse proxy with rewrite

server {
    listen 80;
    server_name lab.example.com;

    location /myorg/workflow/ {
        rewrite ^/myorg/workflow/(.*)$ /$1 break;  # remove prefix from http header
        proxy_pass http://localhost:5555;
        proxy_set_header Host $host;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}