Saturday, 31 May 2025

awstats

  • For new site : cp /etc/awstats/awstats.<existing website>.conf /etc/awstats/awstats.<new website>.conf
  • Edit the /etc/awstats/awstats.<new website>.conf to configure DOMAIN etc
  • Run manually to test : /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -update -config=<new website>
  • Add entry in crontab to update stats daily
  • @daily /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -update -config=<new website>

pass

 pass
    Create a gpg key
        gpg --gen-key
        gpg --list-keys
    Export gpg to gpg2
        gpg2 --export-secret-keys > keyfile
        gpg2 --import keyfile
        gpg2 --edit-key D3B0B515 trust & save
    Setting it up
        pass init "ZX2C4 Password Storage Key"
        pass git init : git repo for entries
    Usage
        pass : show all entries
        pass Email/zx2c4.com : show password of entry
        pass -c Email/zx2c4.com : don't show and copy to clipboard
        pass insert Business/cheese-whiz-factory : insert new entry
        pass edit Business/cheese-whiz-factory : edit entry
        pass rm Business/cheese-whiz-factory : remove entry
        pass generate Email/jasondonenfeld.com 15 : generate password
    Export & Import
        export_import
    Change password of key
        gpg2 --list-keys
        gpg2 --edit-key 77316AB19A2366268B1CBE7FD5DF8174ED02B7CE

Friday, 30 May 2025

badblocks

Read only test

  • sudo badblocks -v /dev/sdb -s

Write test non-destructive

  • sudo badblocks -v /dev/sdb -n -s

 

fping

Ping in loop every 10 seconds.

  • fping --interval=10000 -l 192.168.1.81 192.168.1.42

Thursday, 29 May 2025

postfix

# Monitor postfix mail log
journalctl -u postfix -f

# list queue
postqueue -p

# Flush queue
postqueue -f

# Postfix rewrite from

  • cat /etc/postfix/sender_canonical_maps /.+/ email@yandex.com
  • cat /etc/postfix/header_check /From:.*/ REPLACE From: email@yandex.com
  • add to /etc/postfix/main.cf
    	sender_canonical_classes = envelope_sender, header_sender
    	sender_canonical_maps =  regexp:/etc/postfix/sender_canonical_maps
    	smtp_header_checks = regexp:/etc/postfix/header_check
    


ddrescue

ddrescue

Disk image creation

  1. cd /mnt/tmp/backupsdb
  2. sudo ddrescue /dev/sdb2 sdb2.img sdb2_log.txt -n -r 5 -c 64

 

sfdisk

Disk partition tool

    Backup partition table of first disk. Verify partition name

        sfdisk -d /dev/sda > sda_partition_table.txt

    Restore partition table to second disk. Verify partition name

        sfdisk /dev/sdb < sda_partition_table.txt

Wednesday, 28 May 2025

ufw

Frontend for iptables aiming to make configuration of a firewall easier.
More information: <https://wiki.ubuntu.com/UncomplicatedFirewall>. 

Show ufw rules, along with their numbers:
        ufw status numbered

Enable ufw:
        ufw enable

Disable ufw:
        ufw disable 

Deny all incoming traffic
        ufw default deny incoming comment 'deny all incoming traffic'
Allow ssh incoming traffic
        ufw limit in ssh comment 'allow SSH connections in'
Allow outgoing traffic
        ufw allow out 53 comment 'allow DNS calls out'
        ufw allow out 123 comment 'allow NTP out'
        ufw allow out http comment 'allow HTTP traffic out'
        ufw allow out https comment 'allow HTTPS traffic out'
        ufw allow out 68 comment 'allow the DHCP client to update'
To deny any traffic on port 99, use the command below:
        ufw deny 99
Add new rule
        ufw allow from 1.2.3.4 app WWW
check added rule
        ufw status verbose
Delete rule
        ufw delete 1
start UFW
        ufw enable
status of UFW
        ufw status verbose
check logs
        grep -i ufw /var/log/syslog

Allow incoming traffic on port 5432 on this host with a comment identifying the service:
        ufw allow 5432 comment "Service"

Allow only TCP traffic from 192.168.0.4 to any address on this host, on ports 22 & 80:
        ufw allow proto tcp from 192.168.0.4 to any port 22,80

Deny traffic on port 80 on this host:
        ufw deny 80

Deny all UDP traffic to ports in range 8412:8500:
        ufw deny proto udp from any to any port 8412:8500

Delete a particular rule. The rule number can be retrieved from the `ufw status numbered` command:
        ufw delete rule_number

Tuesday, 27 May 2025

awk

 # To sum integers from a file or stdin, one integer per line:
printf '1\n2\n3\n' | awk '{ sum += $1} END {print sum}'

# To use a specific character as separator to sum integers from a file or stdin:
printf '1:2:3' | awk -F ":" '{print $1+$2+$3}'

# To print a multiplication table:
seq 9 | sed 'H;g' | awk -v RS='' '{for(i=1;i<=NF;i++)printf("%dx%d=%d%s", i, NR, i*NR, i==NR?"\n":"\t")}'

# To specify an output separator character:
printf '1 2 3' | awk 'BEGIN {OFS=":"}; {print $1,$2,$3}'

# To execute commands only on rows that satisfy a certain condtion
printf "george jetson\nolive oyl\nbeetle bailey" | awk '$2=="bailey"{print $0}'
#
# To execute commands only on matching rows using regex
printf "george jetson\nolive oyl\nbeetle bailey" | awk '/ley$/{print $0}'

tr

 # To replace : with a new line:
echo $PATH | tr ":" "\n"
echo $PATH | tr -t ":" \n

# To remove all occurance of "ab":
echo aabbcc | tr -d "ab"         # ouput: cc

# To complement "aa":
# ("Complement" means to keep "aa", and replace all others with "x")
echo aabbccd | tr -c "aa" x       # output: aaxxxxx (no newline)

# To complement "ab\n":
echo aabbccd | tr -c "ab\n" x    #output: aabbxxx (with newline)

# To preserve all alpha(-c). ":-[:digit:] etc" will be translated to "\n". sequeeze mode:
echo $PATH | tr -cs "[:alpha:]" "\n"

# To convert an ordered list to an unordered list:
echo "1. /usr/bin\n2. /bin" | tr -cs " /[:alpha:]\n" "+"

# To remove all NULLs:
tr < file-with-nulls -d '\000' > file-without-nulls

Monday, 26 May 2025

sed

 # To replace all occurrences of "day" with "night" and write to stdout:
sed 's/day/night/g' <file>

# To replace all occurrences of "day" with "night" within <file>:
sed -i 's/day/night/g' <file>

# To replace all occurrences of "day" with "night" on stdin:
echo 'It is daytime' | sed 's/day/night/g'

# To remove leading spaces:
sed -i -r 's/^\s+//g' <file>

# To remove empty lines and print results to stdout:
sed '/^$/d' <file>

# To replace newlines in multiple lines:
sed ':a;N;$!ba;s/\n//g' <file>

# To insert a line before a matching pattern:
sed '/Once upon a time/i\Chapter 1'

# To add a line after a matching pattern:
sed '/happily ever after/a\The end.'

Home

  1. 7z : Compression utility
  2. aa :  a simple utility to help create backups
  3. ab : Apache HTTP server benchmarking tool 
  4. aespipe : AES encrypting or decrypting pipe
  5. at : Task scheduler
  6. atop
  7. awk
  8. aws cli : copy data from s3 bucket 
  9. awstats : Site statistics
  10. badblocks
  11. bash
  12. bc : Calculator for terminal
  13. btop : resource monitor 
  14. darkhttpd : simple web server
  15. date : check date 
  16. ddrescue
  17. dnf : a package manager for RPM-based Linux distributions
  18. du 
  19. dvd-slideshow 
  20. exim : mail server
  21. feh : image viewer
  22. forwardemail : email forwarder service 
  23. freechess : play chess online
  24. find
  25. firewalld 
  26. flexbackup
  27. fping
  28. gpg :  encryption and signing tool
  29. grub 
  30. iptables
  31. journalctl : systemd logs 
  32. mailman : mail distribution list
  33. monitorix :  a lightweight system monitoring tool
  34. mutt : email client
  35. nc : network cat
  36. netcat
  37. nikto : web server scanner 
  38. nmap : port scanner
  39. nnn : File manager for terminal
  40. nweb : simple web server 
  41. pac: GUI to manage/launch connections to remote machines 
  42. pass : Password manager
  43. pax : Archiving and copying utility.
  44. postfix
  45. rclone : data transfer to cloud 
  46. robocopy : File copier for Windows
  47. rsync
  48. sbopkg : Install slackware packages from slackbuilds.org
  49. scalc
  50. sed
  51. sent : plaintext presentation tool
  52. sfdisk
  53. split
  54. ss 
  55. tar
  56. tcpdump : packet analyzer
  57. TermRecord : terminal recorder 
  58. tmux : terminal multiplexer 
  59. tr
  60. ufw
  61. utimer : command line timer 
  62. vim
  63. whatweb :  Next generation web scanner version
  64. wordpress : permissions on linux vm
  65. xrandr : configure display output 

vim

Cut/Delete

  1. dG delete from current line to end of file.
  2. dgg delete from current line to beginning of file.
  3. d`a delete from current character upto location marked by a
  4. d% delete upto matching pairs () {} []
  5. ce delete till end of word and change to Insert mode.

 

TermRecord

TermRecord is a simple terminal session recorder with easy-to-share self-contained HTML output! TermRecord -o /tmp/session.html