Sunday, September 8, 2019

How to setup and install Windows 7, 8, 10 VHD Dual Boot

References: 


######## Step 1: Create a VHD from diskpart ######## 
CMD Run as Administrator:
C:\Windows\system32>diskpart
DISKPART> create vdisk file="C:\win10.vhd" maximum=95000 type=expandable 
DISKPART> attach vdisk
DISKPART> clean
DISKPART> create partition primary
DISKPART> active
DISKPART> format fs=ntfs label=win10vhd quick
DISKPART> assign letter=v
DISKPART> exit


######## Step 2: Apply a Windows image to the VHD,  Detach the VHD ######## 
Mount windows 10 iso in Drive (D) to copy and extract (D:\sources\install.wim) to “win10vhd” partition, list image info with index number:
C:\Windows\system32>Dism /Get-ImageInfo /ImageFile:D:\sources\install.wim


(Windows 10 VHD Support: Set-Edition:Professional  index:6)
C:\Windows\system32>Dism /Apply-Image /ImageFile:D:\sources\install.wim /index:6 /ApplyDir:V:\ /Set-Edition:Professional /AcceptEula /Set-AllIntl:en-US /NoRestart


(Windows 8 VHD Support: Set-Edition:Professional  index:1)
C:\Windows\system32>Dism /Apply-Image /ImageFile:D:\sources\install.wim /index:1 /ApplyDir:V:\ /Set-Edition:Professional /AcceptEula /Set-AllIntl:en-US /NoRestart


(Windows 7 VHD Support: Set-Edition:Ultimate index:4)
C:\Windows\system32>Dism /Apply-Image /ImageFile:D:\sources\install.wim /index:4 /ApplyDir:V:\ /Set-Edition:Ultimate /AcceptEula /Set-AllIntl:en-US /NoRestart


C:\Windows\system32>diskpart
DISKPART> select vdisk file="C:\win10.vhd"
DISKPART> detach vdisk
DISKPART> exit


######## Step 3: Copy it to the destination PC device, and attach it (optional) ######## 
C:\Windows\system32>diskpart
DISKPART> select vdisk file="C:\win10.vhd"
DISKPART> attach vdisk
DISKPART> list volume
DISKPART> select volume 3 (Volume with Label win10vhd)
DISKPART> assign letter v
DISKPART> exit


######## Step 4: Add a boot entry ######## 
C:\Windows\system32>diskpart
DISKPART> list volume
DISKPART> exit


- Add VHD windows to bootloader startup menu:
C:\Windows\system32> V:
V:\ cd v:\windows\system32
V:\Windows\system32> bcdboot v:\windows /v
V:\Windows\system32> bcdedit /v


- Restart the destination PC.


######## Step 5: Delete VHD Dual boot ######## 
Boot destination PC with another windows 
RUN (windows + R) > msconfig > boot (Tab) > Select Windows 10 (V:\windows) : Default OS > Delete (Button)


or using CMD Run as Administrator:
C:\Windows\system32> bcdedit /v
device                  partition=V:
osdevice              partition=V:
systemroot          \windows
resumeobject     {752e9dcc-a0fa-11e9-8b5b-b7e48a5b481d}
C:\Windows\system32> bcdedit /delete {752e9dcc-a0fa-11e9-8b5b-b7e48a5b481d} 

- Restart the destination PC.

Saturday, June 22, 2019

How to Setup Mysql Replication on Ubuntu 18.04 (Master-Master)


How to Setup Mysql Replication on Ubuntu 18.04 (Master-Master)
#===============================================================================

Server1:
OS: Ubuntu 18.04
DB: MySQL-Server-5.7
Hostname: db1
IPAddress: 1.0.8.11

Server2:
OS: Ubuntu 18.04
DB: MySQL-Server-5.7
Hostname: db2
IPAddress: 1.0.8.12


# MySQL 5.7 Non-interactive (silent) install of MySQL 5.7 on Ubuntu
MYSQL_ROOT_PASSWORD=root
echo "mysql-server mysql-server/root_password password $MYSQL_ROOT_PASSWORD" | debconf-set-selections
echo "mysql-server mysql-server/root_password_again password $MYSQL_ROOT_PASSWORD" | debconf-set-selections
DEBIAN_FRONTEND=noninteractive apt install -y mysql-server-5.7

Step 1. Edit & Modify the Configuration file of MySql  Server.
# nano /etc/mysql/mysql.conf.d/mysqld.cnf
bind-address = 0.0.0.0     #comment this line if you want to access mysql remotly

,Add below lines at the end of the file.
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
log_bin_index =/var/log/mysql/mysql-bin.log.index
relay_log = /var/log/mysql/mysql-relay-bin
relay_log_index = /var/log/mysql/mysql-relay-bin.index
log_slave_updates = 1
auto-increment-increment = 2
auto-increment-offset = 1

Step 2. Restart Mysql Server.
# systemctl restart mysql.service

Step 3. Login to Mysql Server.
# mysql -u root -proot

Step 4.  Create a new user for Replication & specify the Password to that user.
mysql > create user 'replica1'@'%' identified by 'replica1pass';
mysql > GRANT REPLICATION SLAVE ON *.* TO 'replica1'@'%';
mysql > FLUSH PRIVILEGES;

Step 5. Execute below command to view the File & Position of Master Server 1.
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000003 |      219 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+


################# Login to Master Server 2.#################
Step 6. Edit & Modify the Configuration file of MySql Server.
nano /etc/mysql/mysql.conf.d/mysqld.cnf
# bind-address = 0.0.0.0

,Add below lines at the end of the file.
server-id = 2
log_bin = /var/log/mysql/mysql-bin.log
log_bin_index =/var/log/mysql/mysql-bin.log.index
relay_log = /var/log/mysql/mysql-relay-bin
relay_log_index = /var/log/mysql/mysql-relay-bin.index
log_slave_updates = 1
auto-increment-increment = 2
auto-increment-offset = 2

Step 7. Restart Mysql Server.
# systemctl restart mysql.service

Step 8. Login to Mysql Server.
# mysql -u root -p

Step 9.  Create a new user for Replication & Specify the Password to that user.
mysql > create user 'replica2'@'%' identified by 'replica2pass';
mysql > GRANT REPLICATION SLAVE ON *.* TO 'replica2'@'%';
mysql > FLUSH PRIVILEGES;

Step 10. Specify the following details as given below & make sure to Replace the following settings with your settings.
MASTER_HOST     :   IP Address of Master server 1
MASTER_USER     :   Replication User of Master server 1 that we had created in previous steps.
MASTER_PASSWORD :   Replication User Password of Master server 1 that we had created in previous steps.
MASTER_LOG_FILE :   Your Value of Master Log File of Master server 1.
MASTER_LOG_POS  :   Your Value of Master Log Position of Master server 1.
mysql> stop slave;
mysql> CHANGE MASTER TO MASTER_HOST = '1.0.8.11', MASTER_USER = 'replica1', MASTER_PASSWORD = 'replica1pass', MASTER_LOG_FILE = 'mysql-bin.000003', MASTER_LOG_POS = 219;
mysql> start slave;

Step 11. Execute below command to view the File & Position of Master Server 2.
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000002 |      154 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+

################# Login to Master Server 1. #################
Step 12. Specify the following details as given below & make sure to Replace the following settings with your settings.
MASTER_HOST     : IP Address of Master server 2.
MASTER_USER     : Replication User of Master server 2 that we had created in previous steps.
MASTER_PASSWORD : Replication User Password of Master server 2 that we had created in previous steps.
MASTER_LOG_FILE : Your Value of Master Log File of Master server 2.
MASTER_LOG_POS  : Your Value of Master Log Position of Master server 2.
mysql> stop slave;
mysql> CHANGE MASTER TO MASTER_HOST = '1.0.8.12', MASTER_USER = 'replica2', MASTER_PASSWORD = 'replica2pass', MASTER_LOG_FILE = 'mysql-bin.000002', MASTER_LOG_POS = 154;
mysql> start slave;

Step 13. For testing a Replication we need to create a new database, it will automatically replicate on Master Server 2.
mysql > create database demo;

################# Login to Master Server 2.#################
Step 14. Login to Mysql Server
# mysql -u root -p

Step 15. View your Replicated Database by using below command.
mysql > show databases;


Monday, June 10, 2019

How to Create Multiple User Accounts in Linux




Method-1: "newusers" linux command

, First create a user list with passwords, id, groupid, firstname , lastname, home directory, shell
$ nano userslist.txt
user1:user1pass:1001:1001:User1 Lastname:/home/user1:/bin/bash
user2:user2pass:1002:1002:User2 Lastname:/home/user2:/bin/bash
user3:user3pass:1003:1003:User3 Lastname:/home/user3:/bin/bash
user4:user4pass:1004:1004:User4 Lastname:/home/user4:/bin/bash
user5:user5pass:1005:1005:User5 Lastname:/home/user5:/bin/bash

, Save the file and set the required permissions on it.
$ sudo chmod 0600 users.txt

, Now run the newusers command with the input file to add the above user accounts at once.
$ sudo newusers users.txt


Method-2: shell script to create users with passwords 

, First create a user list file
$ nano userlist.txt
user1
user2
user3
user4
user5

, create shell script that add users with passwords "username@123"

$ nano user-add.sh
#!/bin/sh
for user in `more userlist.txt`
do
echo "$user"
useradd $user -m -s /bin/bash
echo "$user:$user@123" | chpasswd
chage -d 0 $user
done

, Set an executable permission to user-add.sh file.
$ chmod +x user-add.sh

, Finally run the script to achieve this.
$ sudo bash user-add.sh

, Verify user creation
$ grep "user1\|user2\|user3" /etc/passwd


Friday, June 7, 2019

Setup SSH Passwordless Certificate for login to Linux servers

- Generate SSH key using RSA Algorithm within 4096 bytes and compatible with PEM certificate 
$ ssh-keygen -t rsa -b 4096 -m PEM
Enter file in which to save the key (/home/user/.ssh/id_rsa): server-key

- Then you can get pem from your rsa private key.
$ openssl rsa -in server-key -outform pem > server-key.pem

, change permissions to private key in local machine
$ chmod 0400 server-key.pem

- Copy SSH Public key to your server
$ ssh-copy-id -i server-key.pub user@Sever-IP-OR-Domain

- Login using SSH Key 
$ ssh -i server-key.pem user@Sever-IP-OR-Domain

- Create SSH config file
$ nano ~/.ssh/config
# Server @datacenter1
Host web1
Hostname mydomain.com
User username
Port 1234
IdentityFile /path-to-private-key/server-key.pem

- Login using SSH config details 
$ ssh web1 
- Change SSH service settings to disable root login and prevent using passwords (remote server)

$ sudo nano /etc/ssh/sshd_config
# change default ssh port
Port 1234

# use two method authentication: publickey, password
AuthenticationMethods publickey,password

# disable root login
PermitRootLogin no

# disable login using password only
#PasswordAuthentication yes

# Allowed Users only to login
AllowUsers user1@192.168.1.0/24 user2@10.10.10.0/16

- Apply ssh new settings by restart service
$ sudo systemctl restart ssh.service

, change permissions to authorized_keys file
$ chmod 0400 ~/.ssh/authorized_keys

Thursday, June 21, 2018

Installing PHP 5.6 on Ubuntu LTS


- php5.6 install, Add the PPA repo
sudo add-apt-repository ppa:ondrej/php
sudo apt-get install software-properties-common
sudo apt-get update
sudo apt-get install php5.6 php5.6-mbstring php5.6-curl php5.6-mcrypt php5.6-mysql php5.6-xml php5.6-fpm php5.6-zip php5.6-ldap

- From php7.x to php5.6:

    Apache:
sudo a2dismod php7.x ; sudo a2enmod php5.6 ;

    CLI:
sudo update-alternatives --config php
sudo update-alternatives --set php /usr/bin/php5.6

- some modules required to be enabled
sudo a2enconf php5.6-fpm
sudo a2enmod proxy_fcgi setenvif

- Restart Apache server
sudo systemctl restart apache2

- Test PHP current version

$ php -v

httpL//localhost/phpinfo.php

sudo nano /var/www/html/phpinfo.php
<?php
      //outputs php configuration info
      phpinfo();
?>