How to find process listening over a port

List all tcp ports using netstat -at

netstat -at
 netstat -ltnp 

-p means list all the programs run over the port

List all udp ports using netstat -au

netstat -aup

List only listening ports using netstat -l

netstat -lp

List only the listening UNIX Ports using netstat -lx

netstat -lxp

lsof command (LiSt Open Files) is used to list all open files on a Linux system. To install it on your system, type the command below.

$ sudo yum install lsof	        #RHEL/CentOS 
$ sudo apt install lsof		#Debian/Ubuntu
$ sudo dnf install lsof		#Fedora 22+

To find the process/service listening on a particular port, type (specify the port).

$ lsof -i :80

Create bootable USB stick from ISO in Mac OS X

Convert the ISO to UDRW format

Mac OS X provides all the tools needed to convert the ISO image to UDRW. The following command will convert the ISO image to the UDRW format.

hdiutil convert -format UDRW -o destination_file.img source_file.iso

You will notice that the destination_file.img from the command will create the file destination_file.img.dmg really. This is because the hdiutil program automatically adds the dmg file extension. This is not a problem as the file extension won’t affect the format of the image.

Prepare the USB stick

Check your USB stick and make a backup if there is any important data on it, as the next steps are going to delete everything on it.

To prepare the USb stick we are going to delete all the partitions on the stick and create an empty partition. To do this we need to know the device name of the USB stick. Open a terminal and execute the following command:

$ diskutil list

You will see a list of disks and partitions. The goal is to identify the USB stick in this output. Depending on your system configuration your output might look different from this one. This appears to show 3 physical discs but it does not. The /dev/disk1 is a virtual disk created because of the partition encryption (FileVault 2) I enabled in Mac OS X.

/dev/disk0
#:                       TYPE NAME                    SIZE       IDENTIFIER
0:      GUID_partition_scheme                        *500.1 GB   disk0
1:                        EFI                         209.7 MB   disk0s1
2:          Apple_CoreStorage                         399.5 GB   disk0s2
3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
5:                 Apple_Boot Boot OS X               134.2 MB   disk0s5
/dev/disk1
#:                       TYPE NAME                    SIZE       IDENTIFIER
0:                  Apple_HFS MacOSX                 *399.2 GB   disk1
/dev/disk2
#:                       TYPE NAME                    SIZE       IDENTIFIER
0:      GUID_partition_scheme                        *2.0 GB     disk2
1:       Microsoft Basic Data UNTITLED 1              2.0 GB     disk2s1

As shown in the output above, the connected USB stick is a small 2.0 GB drive with a FAT partition on it. We are now going to remove this partition in the next step. For the following steps we will need the name of the disk which in this case is “/dev/disk2”.

With the following command the data on the disk (your USB stick) will be deleted!

$ diskutil partitionDisk /dev/disk2 1 "Free Space" "unused" "100%"

With this command the USB stick was re-partitioned to have 1 partition without formatting and 100% of the size of the stick. If you check it again with “diskutil list” you will see the changes already, also the USB stick will no longer be shown in the Finder.

Copy the image to the USB stick

Now we can copy the disk image we created to the USB stick. This is done via the dd(1)command. This command will copy the image to the disk (substitute the appropriate disk name for your USB stick here, as with the re-partitioning command):

$ sudo dd if=destination_file.img.dmg of=/dev/disk2 bs=1m

The dd command does not show any output before it has finished the copy process, so be patient and wait for it to complete.

$ diskutil eject /dev/disk2

To eject the USB stick, use the above command. After this is done, the bootable USB stick is ready to be used.

Original link

IspConfig migration from one server to other.

Usefull link 

You need to backup /var/vmail, /var/www (or the place where you stored the websites), the ispconfig database, all mysql databases of the websites incl. the “mysql” database, the users and passwords in /etc/passwd and /etc/group. Make sure that you backup the directories with preserved permoissions.

We must backup:
c. /var/www (web content)
b. /var/vmail (mail content)
a. /etc/passwd and /etc/group (users)
d. MySQL databases (is it better to stop mysql and tar.gz the /var/lib/mysql?)
e. All /etc/
f. /var/log

MY migration script

#!/bin/bash

#database root password
export username=
export password=
NOW=$(date +”%d-%m-%Y”)

ssh root@IP_OLD rm -rf /root/BACKUP_SERVER/vmail.tar.gz
ssh root@IP_OLD tar -zcvf /root/BACKUP_SERVER/vmail.tar.gz /var/vmail
scp root@IP_OLD:/root/BACKUP_SERVER/vmail.tar.gz ./BACKUP_SERVER/
cd ./BACKUP_SERVER
tar -zxvf vmail.tar.gz
cd ..
rm -rf /var/vmail
mv ./BACKUP_SERVER/var/vmail /var/

ssh root@IP_OLD rm -rf /root/BACKUP_SERVER/www.tar.gz
ssh root@IP_OLD tar -zcvf /root/BACKUP_SERVER/www.tar.gz /var/www
scp root@IP_OLD:/root/BACKUP_SERVER/www.tar.gz ./BACKUP_SERVER/
cd ./BACKUP_SERVER
tar -zxvf www.tar.gz
cd ..
rm -rf /var/www
mv ./BACKUP_SERVER/var/www /var/

ssh root@IP_OLD rm -rf /root/BACKUP_SERVER/log.tar.gz
ssh root@IP_OLD tar -zcvf /root/BACKUP_SERVER/log.tar.gz /var/log
scp root@IP_OLD:/root/BACKUP_SERVER/log.tar.gz ./BACKUP_SERVER/
cd ./BACKUP_SERVER
tar -zxvf log.tar.gz
cd ..
rm -rf /var/log
mv ./BACKUP_SERVER/var/log /var/

ssh root@IP_OLD rm -rf /root/BACKUP_SERVER/opt.tar.gz
ssh root@IP_OLD tar -zcvf /root/BACKUP_SERVER/opt.tar.gz /var/opt
scp root@IP_OLD:/root/BACKUP_SERVER/opt.tar.gz ./BACKUP_SERVER/
cd ./BACKUP_SERVER
tar -zxvf opt.tar.gz
cd ..
rm -rf /var/opt
mv ./BACKUP_SERVER/var/opt /var/

NOW=”03-12-2017″
export NOW

array=(mydb1 mydb2)
for DATABASE in “${array[@]}”
do

export DATABASE

echo “BACKUP MYSQL OF $DATABASE for $NOW”

echo “COPY FILE”
scp root@IP_OLD:/root/BACKUP_SQL/$DATABASE$NOW.sql ./BACKUP_SQL/

echo “DROP DB $DATABASE”
mysql -u $username -p”$password” -e “DROP DATABASE IF EXISTS $DATABASE”

echo “CREATE DB $DATABASE”
mysql -u $username -p”$password” -e “CREATE DATABASE $DATABASE”

echo “RESTORE”
mysql -u $username -p”$password” $DATABASE < ./BACKUP_SQL/$DATABASE$NOW.sql

echo “FINE”
done

export password=”

export PGPASSWORD=”

array=( pgdb1 pgdb2 )

for DATABASE in “${array[@]}”
do

export DATABASE

echo “BACKUP POSTGRES OF $DATABASE for $NOW”

echo “COPY FILE”

scp root@IP_OLD:/root/BACKUP_SQL/$DATABASE$NOW.backup ./BACKUP_SQL/

dropdb –host 127.0.0.1 –port 5432 –username “postgres” –no-password $DATABASE

createdb –host 127.0.0.1 –port 5432 –username “postgres” –no-password $DATABASE

pg_restore –host 127.0.0.1 -U postgres -d $DATABASE –verbose ./BACKUP_SQL/$DATABASE$NOW.backup
done

Increase space Virtual Box and Linux Partition

Clone the disk

VBoxManage clonehd “path/WebServer.vmdk” “path/WebServer.vdi” –format vdi

resize 20*1024 = 20GB

VBoxManage modifyhd “path/WebServer.vdi” –resize 20480

reconvert into vmdk

VBoxManage clonehd “path/WebServer.vdi” “path/WebServer.vmdk” –format vmdk

File -> Virtual Media Manager -> Removed existing images (note, I removed them only from the registry).

1. Open the Oracle VM VirtuaBox Manager
Click on File -> Virtual Media Manager (or Ctrl+D)
2. Delete the hard disk entry in question (select and press “Del” on keyboard)
3. Open “Settings” of the Virtual Machine, go to “Storage”, click “Add Attachment”, select “Add Hard Disk” and “Choose existing disk“, then selected the vdi file and you are done.

  1. Download “gparted-live-x.xx.x-x-ixxx.iso” file from http://gparted.sourceforge.net/download.php. Mount this iso file as CD. Virtual Machine -> Settings -> Storage -> Controller IDE (Right Click) -> Add CD/DVD -> Select gparted-live-x.xx.x-x-ixxx.iso file
  2. Run virtual machine, Virtual Machine will boot from this CD. Choose default values with pressing “Enter”, “Enter” … until Gpart ISO GUI starts. Select tool gpart program and start.
  3. Extend disk size as below;
    • Right click on partitions and if “possible” click on “Disable Active Partion”.
    • Extend Partition as much as possible from GUI (for this case 500GB).
    • Right click the partition which is disabled and select “Enable Active Partion”.
    • Apply and wait until the operations finished.
    • Shut down virtual machine.
    • Unmount gparted-live-x.xx.x-x-ixxx.iso.
      $ Virtual Machine -> Settings -> Storage-> Controller IDE (Right Click on gparted-live-x.xx.x-x-ixxx.iso) -> Remove Attachement
    • Start the virtual machine.

vgdisplay

df -h

File system              Dim. Usati Dispon. Uso% Montato su
/dev/mapper/centos-root   19G  6,2G     13G  34% /
devtmpfs                 910M     0    910M   0% /dev
tmpfs                    920M     0    920M   0% /dev/shm
tmpfs                    920M  8,6M    912M   1% /run
tmpfs                    920M     0    920M   0% /sys/fs/cgroup
/dev/sda1               1014M  188M    827M  19% /boot
tmpfs                    184M     0    184M   0% /run/user/0

 

resize2fs /dev/mapper/centos-root

lvextend -l+100%FREE /dev/mapper/centos-root

resize2fs /dev/mapper/centos-root

xfs_growfs /dev/mapper/centos-root

df -ha

—– what did the provider to remeber—-

First step extend last partition:
fdisk /dev/sda
p > take note of beginning of sda4 just in case
d > 4
n > 4 > > >
t > 4 > e8 (to mark it as LVM partition)
w

reboot

Resize the lvm :
pvscan > to make sure we have free space
pvresize /dev/sda4

lvscan > to take note of lv path
lvextend -l +100%FREE /dev/centos/root

xfs_growfs /dev/mapper/centos-root -d