Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Friday, 18 October 2019

Install Mariadb/Mysql 10.3 on centos8

yum install mariadb mariadb-server

systemctl enable mariadb

systemctl start mariadb

Friday, 30 August 2019

update to kernel 5.2 on linux centos7

Note: Take a snapshot  before doing kernel update.

1. Install binaries required to compile Kernel

yum install gcc ncurses-devel make bc bison flex elfutils-libelf-devel openssl-devel grub2 -y

2. Download the latest kernel from https://kernel.org and extract it

curl -O https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.2.11.tar.xz

tar -xf linux-5.2.11.tar.xz


3. Copy the current Kernel configuration (.config) from the /boot to /root/linux-5.2.11

cp /boot/config-3.10.0-862.el7.x86_64 /root/linux-5.2.11

make menuconfig

save and exit





4. Make kernel and install

make
make install

5. Reboot

Thursday, 8 November 2018

Why should i use docker? container?

Docker is operating-system-level virtualization also know as containers.

Why should i use docker?

Ans: It's gives you want you want ( literally ). It run all application as an instance.


How to use Docker? ( eg if you want to run httpd on docker)

1. Install Docker on linux or windows box ( Linux preferred )

2. docker pull httpd

3. docker run -p 80:80 -d -v /var/www/html:/usr/local/apache2/htdocs:Z httpd
    (This will mount your local /var/www/html to /usr/local/apache2/htdocs of docker instance)



Other useful commands :

 ls -l /var/lib/docker/
 ls -l /var/lib/docker/containerd/

docker pull centos
docker run -it -d centos
docker container ls
docker commit 4f0b435cdbd7 man-centos
docker kill container_id
docker rm  container_id
docker exec -it [container-id] bash
docker run -p 80:80 -d -v /var/www/html:/usr/local/apache2/htdocs:Z httpd   - :Z

docker run ubuntu:14.04 echo "hola"


Tuesday, 14 February 2017

SCP secure copy directly between linux machines

SCP : secure copy directly between linux servers. SCP runs on port 22 by default.

server1 = 192.168.0.10
server2 = 192.168.0.11


Syntax : scp -[options] username@server1:/path  /local_path

Options :

p = Speed of connection
r = Recursive
v = Verbose details
C = Compression
l = Bandwidth Limit (l -500)
p= Port

root@server2:/tmp# scp -pr root@server1:/root/test /tmp
test1                                         100%    0     0.0KB/s   00:00
test2                                         100%    0     0.0KB/s   00:00


Friday, 2 December 2016

Password less authentication in linux

Source : host A
Destination: host B


1. Run the below command for generating public and private key( host A)

ssh-keygen -t rsa

/home/username/id_rsa (private key)
/home/username/id_rsa.pub (public key)

2. ssh-copy-id -i  /home/username/id_rsa.pub host_B_ip_address



Alternate way:

* Copy the text inside id_rsa.pub file .

* Login into host B and go to /root/username/

and create new file "authorized_keys" and paste text copied from step 2.

*  Login into Host A to Host B password less.(ssh host B)


Simple:

Put public key(host A) to authorized_keys(host B)

Now Host A can login into host B without any password.



Wednesday, 21 September 2016

Linux user management commands

Create user in linux :

root@test2:~# useradd test1
root@test2:~# passwd test1
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

Note : we can also create user with adduser command.

-Whenever user is created in linux the default access is assigned to user via /etc/profile file.
-Username is added to /etc/passwd file.
-Same as username one group is created in /etc/group file.
-Encrypted password save into /etc/shadow file.


Delete user in linux:

root@test2:~# userdel test1


Lock user account in linux:

root@test2:~# passwd -l test1
passwd: password expiry information changed.

when user will try to login he will get below message.

login as: test1
test1@192.168.0.10's password:
Access denied

When the user account is locked we can see sign after username in /etc/shadow file.

root@test2:~# cat /etc/shadow | grep test
test1:!$6$prWdpshs$A0WNBzbHC5sEke7hatNq8lFaB/Ux.SQ3vRc1.If4joDTD/AMpsuPYT.1mCmfBDUCoh6ND7izfcT9buo1wiZ581:17066:0:99999:7:::


Unlock user account in linux:

root@test2:~# passwd -u test1

passwd: password expiry information changed.

You can also unlock by editing /etc/sadow file. remove the ! sign from locked account.


Linux user account details :

root@test2:~# chage -l test1
Last password change                                    : Sep 22, 2016
Password expires                                        : never
Password inactive                                       : never
Account expires                                         : never
Minimum number of days between password change          : 0
Maximum number of days between password change          : 99999
Number of days of warning before password expires       : 7

See process run by user :

root@test2:~# ps  -u test1
  PID TTY          TIME CMD
 2442 ?        00:00:00 systemd
 2443 ?        00:00:00 (sd-pam)
 2463 ?        00:00:00 sshd
 2464 pts/0    00:00:00 sh

Root access to test1 user :

Edit the /etc/sudoers and add the below line.

%test1  ALL=(ALL:ALL) ALL

Switch to another user :

sudo su - username

root@test2:~# sudo su - test1
No directory, logging in with HOME=/
$ bash
test1@test2:/$




Monday, 5 September 2016

Simple linux boot process

When you press the power button of linux system these six steps are followed by linux system.

1. BIOS
  • BIOS stands for Basic Input/Output System
  • Performs some system integrity checks
  • Searches, loads, and executes the boot loader program.
  • It looks for boot loader in floppy, cd-rom, or hard drive. You can press a key (typically F12, F2, DEL,  but it depends on your motherboard) during the BIOS startup to change the boot sequence.
  • Once the boot loader program is detected and loaded into the memory, BIOS gives the control to it.
  • So, in simple terms BIOS loads and executes the MBR boot loader.

2. MBR

  • MBR stands for Master Boot Record.
  • It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda
  • MBR is 512 bytes in size. It has three components 1) primary boot loader info in 1st 446 bytes 2) partition table info in next 64 bytes 3) MBR validation check in last 2 bytes.
  • It contains information about GRUB (or LILO in old systems).
  • MBR loads and executes the GRUB boot loader.

3. GRUB

  • GRUB stands for Grand Unified Bootloader.
  • If you have multiple kernel images installed on your system, you can choose which one to be executed.
  • GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it loads the default kernel image as specified in the grub configuration file.
  • GRUB has the knowledge of the filesystem (the older Linux loader LILO didn’t understand filesystem).
  • Grub configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this). The following is sample grub.conf of CentOS.
  • #boot=/dev/sda
    default=0
    timeout=5
    splashimage=(hd0,0)/boot/grub/splash.xpm.gz
    hiddenmenu
    title CentOS (2.6.18-194.el5PAE)
              root (hd0,0)
              kernel /boot/vmlinuz-2.6.18-194.el5PAE ro root=LABEL=/
              initrd /boot/initrd-2.6.18-194.el5PAE.img
  • As you notice from the above info, it contains kernel and initrd image.
  • GRUB just loads and executes Kernel and initrd images.

4. Kernel

  • Mounts the root file system as specified in the “root=” in grub.conf
  • Kernel executes the /sbin/init program
  • Since init was the 1st program to be executed by Linux Kernel, it has the process id (PID) of 1. Do a ‘ps -ef | grep init’ and check the pid.
  • initrd stands for Initial RAM Disk.
  • initrd is used by kernel as temporary root file system until kernel is booted and the real root file system is mounted. It also contains necessary drivers compiled inside, which helps it to access the hard drive partitions, and other hardware.

5. Init

  • Looks at the /etc/inittab file to decide the Linux run level.
  • Following are the available run levels
    • 0 – halt
    • 1 – Single user mode
    • 2 – Multiuser, without NFS
    • 3 – Full multiuser mode(mostly default)
    • 4 – unused
    • 5 – X11
    • 6 – reboot
  • Init identifies the default initlevel from /etc/inittab and uses that to load all appropriate program.
  • Run ‘grep initdefault /etc/inittab’ on your system to identify the default run level
  • If you want to get into trouble, you can set the default run level to 0 or 6. Since you know what 0 and 6 means, probably you might not do that.
  • Typically you would set the default run level to either 3 or 5.

6. Runlevel programs

  • When the Linux system is booting up, you might see various services getting started. For example, it might say “starting sendmail …. OK”. Those are the runlevel programs, executed from the run level directory as defined by your run level.
  • Depending on your default init level setting, the system will execute the programs from one of the following directories.
    • Run level 0 – /etc/rc.d/rc0.d/
    • Run level 1 – /etc/rc.d/rc1.d/
    • Run level 2 – /etc/rc.d/rc2.d/
    • Run level 3 – /etc/rc.d/rc3.d/
    • Run level 4 – /etc/rc.d/rc4.d/
    • Run level 5 – /etc/rc.d/rc5.d/
    • Run level 6 – /etc/rc.d/rc6.d/
  • Please note that there are also symbolic links available for these directory under /etc directly. So, /etc/rc0.d is linked to /etc/rc.d/rc0.d.
  • Under the /etc/rc.d/rc*.d/ directories, you would see programs that start with S and K.
  • Programs starts with S are used during startup. S for startup.
  • Programs starts with K are used during shutdown. K for kill.
  • There are numbers right next to S and K in the program names. Those are the sequence number in which the programs should be started or killed.
  • For example, S12syslog is to start the syslog deamon, which has the sequence number of 12. S80sendmail is to start the sendmail daemon, which has the sequence number of 80. So, syslog program will be started before sendmail.
  • First it Kills the Program then Start the Program

Monday, 1 August 2016

Iptables linux firewall simple command

What is Iptables ?

Iptables is a rule based firewall and it is pre-installed on Linux operating system which control the incoming and outgoing traffic. We can create chain rule and block black listed IP.

For example:

Block IP:

If we got DDOS attack on web server from 192.168.1.10 now we can block the inbound traffic from this IP using Iptabes.

iptables -D INPUT -s 192.168.1.10 -j DROP

or range of IP

iptables -A INPUT -s 192.168.0.0/24 -j DROP

Now from 192.168.1.10 will not able to access anything on your server.

Restricting access with mac address :

iptables -A INPUT -m mac --mac-source 0E:0F:EA:91:04:08 -j DROP

iptables -A INPUT -m mac --mac-source 0E:0F:EA:91:04:08 -j ACCEPT


Restricting access on port:

iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 22 -j ACCEPT

iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 25-j ACCEPT

Port 22(SSH) and 25(SMTP)  is accessible only from 192.168.1.0/24

List of rule :

iptables -L -n -v

-L : List rules.
-v : Display detailed information. 
-n : Display IP address and port in numeric format.

Deleting rule :

iptables -D INPUT -s 192.168.0.10 -j DROP

iptables -D INPUT -m mac --mac-source 0E:0F:EA:91:04:08 -j DROP

iptables -D INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 22 -j ACCEPT







Monday, 4 July 2016

Run sudo command with php or Apache in linux

Ubuntu run apache as the www-data user and sudo command ask for password everytime you run sudo command. If you want to use sudo without a password from a web page, you need to allow www-data user to run sudo command with no password.

Steps:

1. Run  sudo visudo  command.

2. add below lines at the end of the file.

www-data ALL=NOPASSWD: ALL

3. or you can specify only for specific program.

www-data ALL=NOPASSWD: /sbin/iptables


Below PHP code to ban ip using ufw firewall in Linux ubuntu.


 <form action="" method="post">  
 Enter IP : <input type="text" name="ip">  
 <input type="submit" value="Ban IP">  
 </form>  
   
 <?php  
   
 if(isset($_POST["ip"]))  
 {  
 $ip= $_POST["ip"];  
 echo "$ip";  
 $ban = shell_exec("sudo ufw deny from $ip");  
 echo "Banned".$ban;  
 }  
   
 ?>

4. Done 

Thursday, 1 October 2015

Slow motion video using ffmpeg

Speeding up/slowing down video using ffmpeg:

-i = input file(mov,mp4,avi,mkv,flv)
-filter:v= video filter
-filter:a= audio filter(The atempo filter is limited to using values between 0.5 and 2.0)
setpts= set presentation timestamp
-r = frame rate

Slowing down:

Video:
ffmpeg -i input.mp4 -filter:v "setpts=2.0*PTS" output.mp4  //half speed

ffmpeg -i input.mp4 -filter:v -r 30 "setpts=2.0*PTS" output.mp4  //half speed with fps 30
(Note: More fps= Large video size)

Audio:
ffmpeg -i input.mkv -filter:a "atempo=2.0" -vn output.mkv

Speeding up:

Video:
ffmpeg -i input.mp4 -filter:v "setpts=2.0*PTS" output.mp4  //2xfaster

Audio:
ffmpeg -i input.mkv -filter:a "atempo=0.5" -vn output.mkv

Download ffmpeg https://www.ffmpeg.org/download.html

More info :ffmpeg.org


Thursday, 27 August 2015

Simple photo upload and share code in php

Features:
-Upload, compress, share
-Album, blog, hash tag
-Search

Live code: http://photo.initedit.com 



more opensource code: http://opensource.initedit.com

Installation steps:
Now get started with how to install photo.initedit.com .

- First you need to have an server which support php and mysql(LAMP).
- Now Unzip the downloaded folder.(downlaod)
- Go to "mysql" directory inside the extracted directory.
- Now After confirming table.sql file go to phpmyadmin panel(or import using mysql console).
- Create a new database using phpmyadmin
- Now Click on import to import tables.sql file from our "mysql" directory.
- Now go to extracted folder inside php/class/ folder.
- Open common.php file in text editor.
- Change username ,password, and databases accordingly .
- Done.

Note : You also have to install Imagick for optimizing image loading
(http://php.net/manual/en/imagick.installation.php)

Tuesday, 11 August 2015

simple Load balancer using Nginx web server

Nginx Load balancing on linux ubuntu 14.04

Loadbalancer(lb):192.168.0.10(Nginx)
webserver(web1):192.168.0.11(apache)
webserver(web2):192.168.0.12(apache)
webserver(web3):192.168.0.13(apache)
database server(db):192.168.0.14(mysql)

note:we can increase web server for load balancing.

1.Install nginx webserver on Loadbalancer(lb)

apt-get install nginx

2.Edit the nginx default file.

 nano /etc/nginx/nginx.conf

note:you can use any text editor vi or pico.

events {
        worker_connections  1024;
        use                 epoll;
        multi_accept        on;
}

upstream backend  {
  server 192.168.0.11;
  server 192.168.0.12;
  server 192.168.0.13;
}

server {
  location / {
    proxy_pass  http://backend;
  }
}

3.Restart nginx webserver

sudo service nginx restart

4.Install apache webserver on web1, web2 and web3.

apt-get install apache2


5.Goto var/www/html folder of webserver respectively and remove index.html .
add new index.html and write web1 for web1 apache server.

6.Install mysql server on db

apt-get install mysql-server


7.To allow mysql accessible to all webserver run bellow command.


$ mysql -u root -p
Enter password:


mysql> GRANT ALL ON *.* to root@'192.168.0.11' IDENTIFIED BY 'your-root-password';


mysql> GRANT ALL ON *.* to root@'192.168.0.12' IDENTIFIED BY 'your-root-password';


mysql> GRANT ALL ON *.* to root@'192.168.0.13' IDENTIFIED BY 'your-root-password';


Note:I didnot add mysql server in above example but you can add .


8.Open your browser goto url http://192.168.0.10 and refresh the page.

you will see whenever you refresh the page it will show you from which webserver your page is loaded.(because we have added html file in step 5). It will distribute web request equally across the apache Webserver.


Nginx also have diffrent type of load balancing:

1.Session persistence

2.Weighted load balancing

3.Max Fails, etc.


for more:http://nginx.org/en/docs/http/load_balancing.html

Saturday, 30 August 2014

Hack Windows password using backtrack

NOTE : Backup all your data first

Watch Video : http://youtu.be/BlOtqwbZagE

All windows-os encrypted password is stored in SAM(Security Accounts Manager) file . Which is present in "C:\Windows\System32\config" folder.

What we have to do to hack password is copy the all "config" folder of computer which don't have any password to the other computer have the password.
(I have tried on windows7 ultimate,windows-xp works 100%)

The question is how to paste the "config"  folder into computer which have the password ?
(we can do this thing by using Backtrack live cd or other live cd like fedora,etc)

Step 1:
Insert the backtrack live cd into computer which don't have the password and restart the computer.choose "Text mode". It will about 2 min to start backtrack-os from CD,[Default backtrack password is "toor"].
when the text mode is started type "Startx" command to run graphical view of backtrack.

Step 2:
Now you will see your "C: drive"(actually not c: drive you have to search which drive have the windows folder) in Backtrack "computer" . copy the "config" folder from "Windows\System32\" to any pendrive .
Now you have the "config" folder of computer which don't have any password into your pendrive.

Step 3:
Follow the "Step 1" on other computer who have the password. Now copy the "config" folder which you have in the pendrive to "Windows\System32\".

Step 4:
Done. Restart the other computer which have the password. you will see no password is asked.
(if linux live run doesnot start,then goto bios setting and change the sata mode=AHCI)

Watch Video : http://youtu.be/BlOtqwbZagE

Wednesday, 12 March 2014

simple linux commands basic

Linux commands :

1.add user in linux
useradd user_name

2.change password
passwd user_name

3.removing user/group
userdel/groupdel user_name/group_name

4.show all process
  ps 

5. Delete  running process
kill p_id    ( -9 for force quit )

6.Show user details 
 id user_name

7.How to find particular word in file

grep "find_String" file_name
egrup -r "s1|s2" file_name

8.show open ports in linux
netstat --listen OR netstat

9.show how many file are open
lsof

10.memory status
 free