Yash Verma / Cloud runbook

Security commands

16 commands from the cloud runbook. Fill in a placeholder once and every command uses it.

Generate CSR and private key

Creates a new 2048-bit RSA private key and a Certificate Signing Request.

openssl req -new -newkey rsa:2048 -nodes -keyout mydomain.key -out mydomain.csr

The private key is written unencrypted (-nodes); keep mydomain.key private.

ssl, openssl, csr

Read a local certificate file

Reads an x509 certificate file and outputs its details.

openssl x509 -in certificate.crt -text -noout

ssl, openssl, verify

Scan open ports with Nmap

Performs a fast network scan to find open ports on a target IP.

Caution. Scan only hosts and networks you own or have written permission to test.

nmap -F 192.168.1.1

nmap, scan, ports

Fix SSH key permissions

Secures a private SSH key file so only the owner can read it.

chmod 600 ~/.ssh/id_ed25519

ssh, permissions

Check fail2ban status

Shows the status of fail2ban jails and banned IPs.

sudo fail2ban-client status sshd

fail2ban, brute-force, ssh

Encrypt file with GPG

Encrypts a file using symmetric encryption with GPG.

gpg -c sensitive-file.txt

gpg, encrypt, files

Find SUID binaries

Finds all binaries with the SUID bit set (potential privilege escalation vectors).

find / -perm -4000 -type f 2>/dev/null

suid, audit, privilege

Show recent logins

Displays the last 20 user login records.

last -n 20

login, audit, users

Generate bcrypt password hash

Prompts for a password and prints its bcrypt hash, so the password never lands in your shell history.

python3 -c "import bcrypt, getpass; print(bcrypt.hashpw(getpass.getpass().encode(), bcrypt.gensalt()).decode())"

Needs the bcrypt package: pip install bcrypt.

bcrypt, hash, password

Copy SSH key to server

Installs your public key on a remote server for passwordless login.

ssh-copy-id -i ~/.ssh/id_ed25519.pub user@remote-host

ssh, key, auth

Scan infrastructure code for misconfigurations

Checks Terraform, Kubernetes manifests and Dockerfiles in the current directory against security rules.

trivy config .

trivy, iac, terraform

Scan a repository for leaked secrets

Searches the git history of the current repository for keys, tokens and passwords.

gitleaks git -v .

Versions before 8.19 use gitleaks detect instead.

secrets, git, scan

Download the IAM credential report

Generates and saves a CSV of every IAM user with password, access key and MFA status.

aws iam generate-credential-report && aws iam get-credential-report --query Content --output text | base64 --decode > credential-report.csv

If the report is not ready yet, wait a few seconds and run the second command again.

iam, audit, access-keys

List what a service account can do

Shows every action a Kubernetes service account is allowed to perform in a namespace.

kubectl auth can-i --list -n <namespace> --as=system:serviceaccount:<namespace>:<service-account>

Needs permission to impersonate service accounts.

rbac, kubernetes, audit