Created
June 25, 2021 17:56
-
-
Save muhammad-owais-javed/77978243f0247543d93affa8eb82cedd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Checking for the IP's Performing DDOS attack. | |
netstat -ntu|awk '{print $5}'| cut -d: -f1 -s | sort| uniq -c| sort -nk1 -r | |
#**********Compression and Decompression**********# | |
#For compressing to tar.gz file | |
tar czvf create.tar.gz /directory/to/be/compressed/ | |
#For Extracting tar.gz file in specific directory | |
tar -xzvf yourfile.tar.gz -C /extracting/directory | |
#Compressing a direcrory in zip file | |
zip -r file.zip /directory/to/be/compressed | |
#Decompressing zip file in a directory | |
unzip file.zip -d /directory/to/be/extracted | |
#*************************************************# | |
#************************************File Transferring Methods************************************# | |
#For transferring files and folders through rsync | |
rsync -avzr source_username@source_ip:/source/directory/ /destinaton/path/ | |
rsync -avzr /source/directory/ destination_username@destination_ip:/destination/directory/ | |
#Transferring file through rsync in case of any other port | |
rsync -avz -e "ssh -p $portNumber" user@remoteip:/path/to/files/ /destination/directory/ | |
#For transferring files and folders through SCP (SSH) | |
scp -i private.key -P <portnumber> -r source_username@source_ip:/path/to/the/directory/ /destination/directory/ | |
#For transferring files and folders through SFTP | |
sftp -r source_username@source_ip:/source/directory/filename.tar.gz /destination/directory/ | |
#For transferring files and folders through FTP | |
wget -m --source-user=xxxxxxx --source-password=xxxxxxx ftp://X.X.X.X/source-path-to-file/ | |
#*************************************************************************************************# | |
#***************Disk Space and Inodes***************# | |
#For checking Disk space | |
ncdu | |
du -sh * | grep G | |
#To shrink out every log files | |
truncate -s 1000 /var/log/**/*.log | |
#To check inodes: | |
for i in ./*; do echo $i; find $i |wc -l; done | |
#For deleting inodes folder or folder with too many files | |
find . -maxdepth 1 -type f -name "folder_name" -delete | |
#Deleting file or folder if name starts with "-" | |
rm -rf -- "-foldername" | |
#***************************************************# | |
#*******************************Email/Postfix*******************************# | |
#For Sending email from server | |
"Message body" | mail -s "This is Subject" [email protected] -aFrom:[email protected] | |
#For clearing Mail queue | |
postsuper -d ALL | |
#Changing state of postfix | |
/etc/init.d/postfix status | |
/etc/init.d/postfix reload | |
/etc/init.d/postfix restart | |
/etc/init.d/postfix stop | |
/etc/init.d/postfix start | |
Hostname can be change from file "/etc/postfix/main.cf" | |
myhostname = fqdn.example.com | |
Email credentials are store in file "/etc/postfix/sasl_passwd" | |
#***************************************************************************# | |
#******************Useful Redis Commands******************# | |
#For checking directory path and dbfilename | |
CONFIG GET dir | |
CONFIG GET dbfilename | |
#For checking maxmemory (it shows in bytes) | |
config get maxmemory | |
#For setting maxmemory | |
config set maxmemory 1gb | |
#For changing maxmemory policy | |
config set maxmemory-policy allkeys-lru | |
'Link for LRU-Cache and' | |
https://redis.io/topics/lru-cache | |
#If Redis shows error: | |
"2 exception(s): | |
Exception #0 (CredisException): MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk. | |
Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). | |
Please check the Redis logs for details about the RDB error." | |
Steps for the resolution: | |
1. Modify /etc/sysctl.conf and add: | |
vm.overcommit_memory=1 | |
2. redis-cli | |
3. config set stop-writes-on-bgsave-error no | |
#*********************************************************# | |
#***************Shorewall***************# | |
#For opening port in Shorewall: | |
vi /etc/shorewall/rules | |
ACCEPT net fw tcp <port-number> | |
#For Blacklisting IP's in Shorewall | |
vi /etc/shorewall/interfaces | |
net eth0 detect dhcp,tcpflags,routefilter,nosmurfs,logmartians,blacklist | |
vi /etc/shorewall/blacklist | |
'IP will be required to be added in next line' | |
#For checking shorewall rules | |
shorewall check | |
#***************************************# | |
#********************** Misc **********************# | |
#Changing Swap memory | |
(If we wish to increase for 7GB then count will be 7M) | |
dd if=/dev/zero of=/path/for/swapfile.img bs=1024 count=2M | |
mkswap /path/for/swapfile.img | |
vim /etc/fstab -C | |
/path/for/swapfile.img swap swap sw 0 0 | |
swapon /path/for/swapfile.img | |
#Turnoff Swap Memory | |
swapoff /path/to/swapfile.img | |
#For killing processes with particular pattern | |
ps -aux | grep 'pattern_here' | grep -v grep | awk '{print $2}' | xargs -r kill -9 | |
#Converting .ppk into .key format | |
puttygen my.ppk -O private-openssh -o my.key | |
#Find a string or regex from folders and files then print line number with the corresponding file name which contain regex | |
sed -n '/pattern/=' filename | |
#For checking bandwidth of the server | |
vnstat -d | |
"-d argument will shows the bandwidth for the last 30 days" | |
#For Resizing the File System Manually so that the attach storage device can be expand among it | |
resize2fs <filesystemname> | |
"Where filesystemname will be like '/dev/sda1' or '/dev/sda2'" | |
#For tracking stealth/particular process | |
/proc/<processID> | |
#For listing of file link counts | |
lsof +L1 | |
#For checking attribute of file | |
lsattr | |
"Where as i=immutable and a=append-only" | |
#For changing attributes: | |
chattr -/+i [filename] | |
chattr -/+a [filename] | |
#Add in sudoer file for Granting root privilege without password prompt | |
username ALL=(ALL) NOPASSWD:ALL | |
#For checking apache version | |
/usr/sbin/apache2 -v | |
#For changing Apache Log Format | |
/etc/apache2/apache2.conf | |
#For checking Apache modules | |
apache2ctl -t -D DUMP_MODULES | |
#For checking PHP Information and configuration | |
php -i | |
#For Checking Varnish Hit or Miss request | |
varnishlog | grep 'X-Cache:\|ReqURL' | |
#**************************************************# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment