bashoneliners.com

Welcome to bashoneliners.com, a curated collection of practical and well-explained Bash one-liners, snippets, tips and tricks. We aim to make each published one-liner to be of high quality: useful, easy to read, follows best practices, with clear, detailed, accurate explanation. These one-liners should help you automate tasks, troubleshoot problems, whether it be in system administration, file management, networking or programming.

Check if an SSL private key matches a certificate

{ openssl x509 -noout -modulus -in server.crt | openssl md5; openssl rsa -noout -modulus -in server.key | openssl md5; } | uniq

September 20, 2023but-i-am-dominator

Generate a random 32 characters password

tr -dc 'a-zA-Z0-9~!@#$%^&*_()+}{?></";.,[]=-' < /dev/urandom | fold -w 32 | head -n 1

March 24, 2019cheuv25

List top 10 IP addresses connected to your server on port 80 with the number of connections

netstat -tn 2>/dev/null | awk '/:80\>/ {print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head

September 26, 2018Goeks1

Scan entire Git repo for dangerous Amazon Web Service IDs

git grep -Ew '[A-Z0-9]{20}'

September 5, 2018bashoneliners

Scan entire Git repos for dangerous Amazon Web Service IDs

git ls-tree --full-tree -r --name-only HEAD | xargs egrep -w '[A-Z0-9]{20}'

August 31, 2018johntellsall

Ban all IPs that attempted to access phpmyadmin on your site

grep "phpmyadmin" $path_to_access.log | grep -Po "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" | sort | uniq | xargs -I% sudo iptables -A INPUT -s % -j DROP

April 2, 2015openiduser187