Posts

Showing posts from January, 2020

iptables check every hour

Always use full path i.e /sbin/iptables for setting iptables in crontab 0 * * * * /bin/sh /bum/iptables_check.sh #!/bin/bash # #Check if firewall is up ISUP=`/sbin/iptables -L -n | grep DROP` if [ -z "$ISUP" ] then echo "Firewall is down on `hostname`" | mail -s "Firewall Status" linux@drushti.in fi chmod 700 iptables_check.sh

shell scripting

Conditionals let us decide whether to perform an action or not, this decision is taken by evaluating an expression. Expressions An expression can be: String comparison, Numeric comparison, File operators and Logical operators and it is represented by [expression]: String Comparisons: --------------------------------- = compare if two strings are equal != compare if two strings are not equal -n evaluate if string length is greater than zero -z evaluate if string length is equal to zero = is equal to - if [ "$a"= "$b" ] == is equal to -f if [ "$a"=="$b" ] != is not equal to if [ "$a" !="$b" ] < is less then ,in ASCII alphabetical order if [["$a" < "$b"]] > is greater than, in ASCII alphabetical order if [[ "$a" > "$b"]] -z string is null, that is has zero length Examples: [ s1 = s2 ] (true if s1 same as s2, else false) [ s1 != s2 ] (true if s1 not s

reset root password of mysql

Reference taken from this blog: Step 1: Stop MySQL Service. sudo service mysql stop Step 2: Kill all running mysqld. sudo killall -9 mysqld Step 3: Starting mysqld in Safe mode. sudo mysqld_safe --skip-grant-tables --skip-networking & Step 4: Start mysql client mysql -u root Step 5: After successful login, please execute this command to change any password. FLUSH PRIVILEGES; Step 6: You can update mysql root password . UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root'; for mysql > 5.7 use this instead of above: UPDATE mysql.user SET authentication_string=PASSWORD('newpwd') WHERE User='root'; Step 7: Please execute this command. FLUSH PRIVILEGES; Step 8: Exit mysql console exit Step 9: Kill mysqld_safe and start mysql sudo killall mysqld_safe && sudo service mysql start

Linux: Recovering deleted /etc/shadow password file

Linux: Recovering deleted /etc/shadow password file Linux: Recovering deleted /etc/shadow password file Sometime by accident you may delete  /etc/shadow  file. If you boot into single user mode, system will ask root password for maintenance, and just imagine you do not have a backup of /etc/shadow file. How do you fix such problem in a production environment where time is critical factor? I will explain how to recover deleted /etc/shadow file in five easy steps. It will take around 10 min. to fix the problem. Well all it started when one of our client accidentally deleted /etc/shadow file from co-located Debian Linux server. As a result, all account login disabled. However, ftp was working fine because proftpd was build using MySQL database for authentication and quota management. BOOT SERVER INTO SINGLE USER MODE 1) Reboot server 2) Next, you will see grub-boot loader screen. Select Recovery mode the version of the kernel that you wish to boot and type e for edit. Select

phpmyadmin internal server error Access denied with code 44

[Mon Jan 20 13:22:35.175688 2020] [:error] [pid 35609] [client 117.248.109.14] ModSecurity: Access denied with code 44 (phase 2). Match of "eq 0" against "MULTIPART_UNMATCHED_BOUNDARY" required. [file "/etc/httpd/conf/extra/modsecurity.conf"] [line "79"] [msg "Multipart parser detected a possible unmatched boundary."] [hostname "115.112.176.43"] [uri "/phpmyadmin/import.php"] [unique_id "XiVcQ1j4kVXKj7EM10XaZQAAAAA"] ModSecurity: Access denied with code 44 -- Multipart parser detected a possible unmatched boundary SecRule MULTIPART_UNMATCHED_BOUNDARY "!@eq 0" \ "phase:2,t:none,log,status:44,msg:'Multipart parser detected a possible unmatched boundary.'" just remove the deny and save it and restart httpd If you want to be able to access your phpMyAdmin installation from any location add  Require all granted  before the  Require ip  line.

Nginx CORS error

Request header field Access-Control-Allow-Headers is not allowed by Access-Control-Allow-Headers add these lines in server part of the config file    add_header 'Access-Control-Allow-Origin' * always;         add_header 'Access-Control-Allow-Headers' * ; xmlhttprequest-ajax-set-content-type  location ~* \.(?:ico|css|js|gif|jpe?g|png|woff|application/json)$ {             try_files $uri @blogcssjs;             expires 30d;             add_header 'Access-Control-Allow-Origin' * always;             add_header Pragma public;             add_header Cache-Control "public";         }

awstats installation

Set Up AWStats for Nginx on Ubuntu sudo apt-get install awstats add access log file to generate stats using this server { # ... all your other config ... access_log /var/log/nginx/yourdomain.com.access.log ; # ... all your other config ... } /etc/nginx/sites-available vi awstats.parleproducts.com.conf cd /etc/awstats/ vi awstats.parleproducts.com.conf #path to your nginx log file LogFile="/var/log/nginx/parleproducts.com.access.log" # Domain of your vhost SiteDomain="parleproducts.com" # Directory where to store the awstats data DirData="/var/lib/awstats/" # Other domains/subdomain you want included from your logs, for example the www subdomain HostAliases="www.parleproducts.com" # If you customized your log format above add this line: LogFormat = ""%host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot"" # If you did not, uncomment and use this line: #

Disk commands

[root@vps /]# lsblk NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT sda      8:0    1 223.6G  0 disk ├─sda1   8:1    1   768M  0 part /boot ├─sda2   8:2    1   217G  0 part / └─sda3   8:3    1   5.9G  0 part [SWAP] sdb      8:16   1   1.8T  0 disk └─sdb1   8:17   1   1.8T  0 part /allbackup sdc      8:32   1   3.7T  0 disk /backup3 /usr/bin/mount  /dev/sdb1 /allbackup /usr/bin/mount  /dev/sdc  /backup3 resize2fs: Bad magic number in super-block while trying to open use xfs_growfs xfs  file system support only extends not reduce. So if you want to resize the filesystem use xfs_growfs rather than resize2fs. lsblk blkid xfs_growfs /dev/xvda2 Identifying the File System for a Volume To verify the file system in use for each volume on your instance,  connect to your instance  and run the  file -s  command. Example: File Systems on a Nitro-based Instance The following example shows a  Nitro-based instance  that has a boot volume with an XFS file system and an addi