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. calcurse :  terminal-based organizer
  15. ccze : log colorizer 
  16. darkhttpd : simple web server
  17. date : check date 
  18. ddrescue
  19. dnf : a package manager for RPM-based Linux distributions
  20. du 
  21. dvd-slideshow 
  22. exim : mail server
  23. fcron: job scheduler 
  24. feh : image viewer
  25. forwardemail : email forwarder service 
  26. freechess : play chess online
  27. find
  28. firewalld 
  29. flexbackup
  30. fping
  31. gpg :  encryption and signing tool
  32. grub 
  33. iptables
  34. journalctl : systemd logs 
  35. mailman : mail distribution list
  36. monitorix :  a lightweight system monitoring tool
  37. mutt : email client
  38. nc : network cat
  39. netcat
  40. nikto : web server scanner 
  41. nmap : port scanner
  42. nnn : File manager for terminal
  43. noss : terminal rss reader 
  44. nweb : simple web server 
  45. pac: GUI to manage/launch connections to remote machines 
  46. pass : Password manager
  47. pax : Archiving and copying utility.
  48. postfix
  49. rclone : data transfer to cloud 
  50. ripgrep :  line oriented search tool
  51. robocopy : File copier for Windows
  52. rsync
  53. sbopkg : Install slackware packages from slackbuilds.org
  54. scalc
  55. sed
  56. sent : plaintext presentation tool
  57. sfdisk
  58. sl :  ls with enhancements
  59. split
  60. ss
  61. stow : symlink farm manager 
  62. tar
  63. tcpdump : packet analyzer
  64. TermRecord : terminal recorder
  65. tmpwatch : clean tmp directories 
  66. tmux : terminal multiplexer 
  67. tr
  68. ufw
  69. utimer : command line timer 
  70. vim
  71. whatweb :  Next generation web scanner version
  72. wordpress : permissions on linux vm
  73. 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.

 

ccze

 ccze - log colorizer  sudo tail -f /var/log/syslog | ccze