Reset MySQL root password

Reset MySQL/MariaDB Root Password


Step 1:

Stop MySQL/MariaDB Service

CentOS/RHEL 7 Ubutu 16

systemctl stop mysqld/mariadb


CentOS/RHEL 6/5 Ubuntu 14

service mysqld stop


Step 2:


Start the MySQL daemon with “ mysqld_safe”

mysqld_safe –skip-grant-tables

Press CTRL+z to suspend a process by sending it the signal SIGSTOP

Step 3 :
Login DATABASE without Password
mysql --user=root mysql

Step 4 : 
Update Root Password
update user set Password=PASSWORD('new-password') where user='root';
OR
set password for ‘root’@’localhost’=password(‘new-password’);
flush privileges;
exit;

Step 5: 
kill all mysql Process and restart mysql/mariadb service
pkill -9 myslqd
CentOS/RHEL 7, Ubuntu 16
systemctl restart myslq/mariadb
CentOS/RHEL 7, Ubuntu 16
service mysqld/mariadb restart.





salt toturial step by step

SALT ( Port Scan Attack Detector ) Tutorial 

Q : How to configure salt
Q : Step by Step PSAD Configure

SALT : it's a automation tool like ceph, puppet , ansible
Hostname : linuxtopic.com

IP = 172.17.20.100



Step 1. A

Add Repository


A. Ubuntu 14.4 :

a. Run the following command to import the SaltStack repository key:

#wget -O - https://repo.saltstack.com/apt/ubuntu/14.04/amd64/latest/SALTSTACK-GPG-KEY.pub | sudo apt-key add -

b. Save the following file to /etc/apt/sources.list.d/saltstack.list:

deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/latest trusty main

c. Then update repository.
 apt-get update

Ubuntu 16.4 :


a. Run the following command to import the SaltStack repository key:

wget -O - https://repo.saltstack.com/apt/ubuntu/16.04/amd64/latest/SALTSTACK-GPG-KEY.pub | sudo apt-key add -
b. Add  the following line in /etc/apt/sources.list.d/saltstack.list:
deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/latest xenial main
c. Then update repository.

 apt-get update
Step 1. B

Run the following commands to install the SaltStack repository and key:


C. CentOS7 & rhel7 :


sudo yum install https://repo.saltstack.com/yum/redhat/salt-repo-latest-1.el7.noarch.rpm
D. CentOS6 & rhel6 :

sudo yum install https://repo.saltstack.com/yum/redhat/salt-repo-latest-1.el6.noarch.rpm


Step 2  


Salt general installation process is as follows:

a.Make sure that your Salt minions can find the salt master.

b..Install the Salt minion on each system that you want to manage.

c.Accept the Salt minion key after the Salt minion connects.


Step 3


Salt Master installation and configuration:

ubuntu 14&16 :


sudo apt-get install salt-master

Rhel/CentOS 6&7:


sudo yum install salt-master

Step 4

Salt master configuration file:


vi /etc/salt/master


Edit the following lines:


#interface: 0.0.0.0 (uncomment and put your system ip address)
#publish_port: 4505 (uncomment the line)
#user: root (uncomment the line)
#ret_port: 4506 (uncomment the line)
#pidfile: /var/run/salt-master.pid (uncomment the line)
#pki_dir: /etc/salt/pki/master (uncomment the line)
#cachedir: /var/cache/salt/master (uncomment the line)
#pidfile: /var/run/salt-master.pid (uncomment the line)
#verify_env: True (uncomment the line)
#keep_jobs: 24 (uncomment the line)
#sock_dir: /var/run/salt/master (uncomment the line)
#file_roots: (uncomment the line)
# base: (uncomment the line)
# - /srv/salt/ (uncomment the line)

Save  and exit 



Step 5

Start salt-master service:

Ubuntu 14 and centos/rhel6:
sudo service salt-master start
Ubuntu 16 and Centos/Rhel7
systemctl start salt-master.service

Step 6


Salt-Minion Installation And Configuration:

Ubuntu 14 & 16:
sudo apt-get install salt-minion
Centos 6 & 7 :
sudo yum install salt-minion

Step 7


Salt master configuration file:

vi /etc/salt/minion



Uncomment & edit the following lines:

master: (master ip address"172.17.20.100" or domain name )
user: root
id: (xyz)
........
.......     Save and Exit 
S

Step 8


Start the service of salt minion
service salt-minion start (ubuntu14 & centos6) 
         systemctl start salt-minion.service (ubuntu16 & centos7) 


Step 9


Create Directory In Master System:

mkdir -p /srv/salt

Now Check the minion request on master system:

salt-key -L
Accepted Keys:
Denied Keys:
Unaccepted Keys: xyz
Rejected Keys:

Accept Minion key by command:
salt-key -A

Now connection is establish between master and minion.


Step 10


Automation type of salt: 

1. CLI Module (salt bash command if you have execute limited job perform)

2. State Module ( If you have to perform multiple jobs on minions.)

CLI Module:

In this module you can perform single task on minion like you want to create directory ram on minion so 
salt ‘*’ cmd.run ‘ mkdir /tmp/ram’
Here ‘*’ = all minion

Note: if you want to execute on single minion so you have mention its client id . If you want on xyz client so you will e execute 
salt xyz cmd.run ‘mkdir /tmp/ram’
you want execute ifconfig common on every minion 
salt ‘*’ cmd.run ‘ifconfig’


Step 11

Package installation on minion:-
salt ‘*’ pkg.install vim

State Module:-

In this phase of automation you can perform multiple task on minions. You can make own cookbook for you project.

Needs for salt state module.

1. Yaml Langaguge
2. Create /srv/salt directory to store your project cookbook
3. Knowldge of salt state function (file, git, apache, firewall etc)

Note: You have add .sls extension in your salt cookbook.

I am showing you example of psad cookbook.

1.Firstly go the /srv/salt directory:
2.And create psad.sls file.
3. Open file with ant text editor (i am using vim)



# vim psad.sls

psad:
pkg:

   - installed
   - show_changes: True


function1:


file.replace:

   - name: /etc/psad/psad.conf

   - pattern: 'EMAIL_ADDRESSES [email protected];'

   - repl: 'EMAIL_ADDRESSES [email protected];'

   - show_changes: True

function2:

file.replace:

   - name: /etc/psad/psad.conf

   - pattern: '/var/log/messages'

   - repl: '/var/log/kern.log'

   - show_changes: True

function3:

file.replace:

    - name: /etc/psad/psad.conf

    - pattern: 'EMAIL_LIMIT 0;'

    - repl: 'EMAIL_LIMIT 1;'

    - show_changes: True

function4:

file.replace:

    - name: /etc/psad/psad.conf

    - pattern: 'IMPORT_OLD_SCANS N;'

    - repl: 'IMPORT_OLD_SCANS Y;'

    - show_changes: True

function5:

file.replace:

    - name: /etc/psad/psad.conf

    - pattern: 'ENABLE_AUTO_IDS N;'
    - repl: 'ENABLE_AUTO_IDS Y;'

    - show_changes: True

function6:

file.replace:

    - name: /etc/psad/psad.conf

    - pattern: 'AUTO_IDS_DANGER_LEVEL 5;'

    - repl: 'AUTO_IDS_DANGER_LEVEL 3;'

    - show_changes: True

function7:

file.replace:

    - name: /etc/psad/psad.conf

    - pattern: 'AUTO_BLOCK_TIMEOUT 3600;'

    - repl: 'AUTO_BLOCK_TIMEOUT 86400;'

    - show_changes: True


service1:  

service.running:

    - name: psad


Save  and Exit  file.




Now your PSAD project successfully install and configure..

Some Reference:


https://docs.saltstack.com/en/latest/



step by step boot Ubuntu in text mode

Q: How to boot Ubuntu 16 in by default in Text mode


Step 1:

open /etc/default/grub and change according

vi etc/default/grub

A. Remove “splash”

       GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

       GRUB_CMDLINE_LINUX_DEFAULT="quiet"

B. add 3 for text mode

       GRUB_CMDLINE_LINUX=""

       GRUB_CMDLINE_LINUX="3"

C. Uncomment this line

      #GRUB_TERMINAL=console

      GRUB_TERMINAL=console



Step 2 :

Update grub entry
 update-grub

Step 3:
reboot




how to Change default Interface name (enp0s3) to old “eth0”



Q :  how to Change default Interface name (enp0s3) to old “eth0”

Q : how to rename eth0 like interface name on centos 7 / ubuntu 16


Change default network name like enp0s3 or enp1s0 to old like eth0 / eth1 or wlan0 in Ubuntu 16 and CentOS 7

# ifconfig output




Step 1 :   open grub.cfg file

Ubutnu 16 :

vi /boot/grub/grub.cfg

Centos 7 :

vi /boot/grub2/grub.cfg


Step 2 :   

go to menu entry menuentry, find vmlinux line and add “net.ifnames=0 after the word “quiet”

Ubuntu 16 Output:



CentOS 7 Output :



Step 3: 

Reboot your system and change interface name ( enp0s3 ) to ( eth0) in network file

Ubuntu 16

vi /etc/network/interfaces












reboot

CentOS 7 : 

mv /etc/sysconfig/network-scripts/ifcfg-enp0s3 /etc/sysconfig/network-scripts/ifcfg-eth0

vi /etc/sysconfig/network-scripts/ifcfg-eth0






















Restart Network Service

systemctl restart network




Convert Partition Table GPT to MBR in Ubutnu



Q:  how to convert gpt partation table to mbr ?

Q: Convert GPT to MBR using gdisk 


Step 1: Install gdisk

apt update
apt install gdisk


Step 2: Check disk OS boot from UFI for BIOS

gdisk -l /dev/sdX



Step 3: Convert GPT to MBR
gdisk /dev/sda

Recovery and transformation options (experts only) = Press “r”


Convert GPT into MBR and exit = Press “g”


Print the MBR partition table = Press “p”


Write the MBR partition table to disk and exit = Press “w”



Step 4: Reboot Or partprobe

reboot
or
partprobe


Step 5: Re-install Grub

apt-get purge grub-common

apt-get instal grub-pc



Reboot Your System


latest kernel compile in ubuntu step by step


Q : How to Compile Kernel in Ubuntu 

Q : Latest Kernel Compilation step's in Ubuntu

Q : Atheros 5Ghz AP Channel Enable 

Q : Kernel Compile for Artheros Wifi Card to Allow 5Ghz Frequency on AP Mode


Step 1 

Install compulsory packages 
sudo apt-get update
sudo apt-get install linux-source fakeroot kernel-wedge build-essential
Step 2 Install Dependency
sudo apt-get install git-core libncurses5 libncurses5-dev libelf-dev asciidoc
sudo apt-get install binutils-dev crash kexec-tools makedumpfile kernel-wedge
  sudo apt-get install libssl-dev bc debhelper kernel-package libc6-dev
Step 3 

Download Kernel for kernel.org ( you can download latest kernel )
cd /usr/src
wget ftp://ftp.kernel.org/pub/linux/kernel/v4.x/linux-4.8.4.tar.gz tar xvf linux-4.8.4.tar.gz
Optional Steps : It's Required a approx 30-60GB disk space, if you don't have just mount external disk by following steps, best to create directory with kernel name
mkdir /usr/src/linux-4.8.4
mount /dev/sdb2 /usr/src/linux-4.8.4
here /dev/sdb2 is external hdd, and extract tar on it
tar xvf linux-4.8.4.tar.gz -C /usr/src/linux-4.8.4/
Step 4 and 5, if you don’t need 5ghz access point channel for Atheros WIFI
Card, avoid step 4 and 5 

Step 4 

Download Patch for wifi 5ghz frequency 
cd /usr/src/linux-4.8.4/drivers/net/wireless/ath/ wget --no-check- certificate https://dev.openwrt.org/export/32952/trunk/ package/mac80211/patches/403-ath_regd_optional.patch
Step 5 Apply Patch
patch -Np5 -i 403-ath_regd_optional.patch echo "#define ATH_USER_REGD 1"|cat - regd.c > /tmp/out && mv /tmp/out regd.c
 Step 6 Create .config file and make oldconfig
cd /usr/src/linux-4.8.4/ cp /boot/config-$(uname -r) .config make oldconfig
Note: choose default option just hit the enter on every prompt or choose according your need..

Step 7 

Compile, make and create .deb file
fakeroot make-kpkg --initrd --append-to-version=-linuxtopic kernel-image kernel-headers
OR

     fakeroot make -j5 deb-pkg LOCALVERSION=-linuxtopic KDEB_PKGVERSION=1

Note: Wait approx 1 to 10 hour 

Step 8 

check .deb and Install Kernel
ls ../*.deb dpkg -i ../*.deb




How To Stress Test CPU and Memory


Stress is a h/w test utility. It is a simple workload generator for POSIX systems. It imposes a configurable amount of CPU, memory, I/O, and disk stress on the system.

Step 1:

Installation Stress Package 

A: Ubuntu 16
apt-get install stress
B: CentOS 6

yum install epel*
yum install stress*

C: CentOS 7

Downolad Stress RPM
cd /tmp
wget ftp://fr2.rpmfind.net/linux/dag/redhat/el7/en/x86_64/dag/RPMS/stress-1.0.2-1.el7.rf.x86_64.rpm

yum localinstall stress-1.0.2-1.el7.rf.x86_64.rpm



          Or
rpm -ivh ftp://fr2.rpmfind.net/linux/dag/redhat/el7/en/x86_64/dag/RPMS/stress-1.0.2-1.el7.rf.x86_64.rpm



Step 2:

Below command to watch load average

watch uptime
Or
top
Or
htop

Step 3:

Open new terminal and run stress command

stress -c 4 -i 8 -m 8 --vm-bytes 256M -d 1 --hdd-bytes 10GB -t 300s

    htop command output

stress -c 4 -i 4 -m 4 --vm-bytes 1024M -d 1 --hdd-bytes 10GB -t 300s

          stress -c 4 -i 4 -m 4 --vm-bytes 256M -d 1 --hdd-bytes 10GB -t 300s

Stress : load

         CPU = 4 cpu

         I/O  = 4 

         VM = 256MB

        HDD = 10GB 

     top command output


Here :

-c,    --cpu N spawn N workers spinning on sqrt()
-i,     --io N spawn N workers spinning on sync()
-m,   --vm N spawn N workers spinning on malloc()/free()
--vm-bytes B malloc B bytes per vm worker (default is 256MB)
-d, --hdd N spawn N workers spinning on write()/unlink()
--hdd-bytes B write B bytes per hdd worker (default is 1GB)
-t,   --timeout N timeout after N seconds

See more option

stress --help