11 Feb

Integrate Linux & Active Directory using Kerberos, WinBind, Samba

Integrate Linux & Active Directory using Kerberos, WinBind, Samba

We can integrate Linux & Active Directory using Kerberos, Winbind, Samba. Prerequisites to join an Ubuntu Server to Windows Active Directory,

  1. Your Ubuntu server should be able to reach AD server.
  2. Active Directory Domain administrator account or an account in Active Directory’s ‘Domain Admins’ group or an account, that has sufficient privilege to join your Ubuntu server to Active Directory domain.

Configure Hosts

The first step of Active Directory join is to edit the /etc/hosts file. Set your machine’s IP address and hostname in /etc/hosts file.

In the hosts file, please enter the below values,

Example :-

In the hosts file, please enter the below values,

Configure Local Resolver

Next you need to setup the /etc/resolv.conf with your name server entries and search domain entry. Usually, the AD server IP itself will be the name server IPs, since DNS role may be installed in the same server.

In the resolv.conf file, please enter the below values

Example :-

Edit the resolv.conf file and please enter the below values

Install the Utilities

Install the required packages,

During the Kerberos installation, you will see a pink screen. Just enter your full domain name in CAPITAL LETTERS,

Eg : DOMAIN.COM

select OK by pressing TAB

You may keep it as BLANK and press OK, if you wish to configure Kerberos later.

Configure NTP Settings

The date and time of your Ubuntu server\host must synchronize with Active Directory  server. Add your active directory’s ntp hostname in the /etc/ntp.conf file,

You can also keep it as Ubuntu’s NTP servers, provided your active directory server’s time and Ubuntu NTP server time are in sync.

In that case, add the below values, instead of above values,

Now sync the Ubuntu host machine’s date and time with NTP server and then start the NTP service,

If you are using your Active Directory’s NTP service, then execute the below commands,

or

or

Configure Kerberos Settings

Create a file named krb5.conf,

Enter the below values in the kerberos config file,

Now, try to get a valid Kerberos ticket for your active directory administrator account,

Configure NSSwitch

To configure the NSSwitch configuration, please edit the file /etc/nsswitch.conf

Now enter the below values into your configuration file.

 

Configure SAMBA Service

To configure the SAMBA service in your Ubuntu box, edit the samba configuration file  /etc/samba/smb.conf

To edit the file, execute the command,

Replace the DOMAIN with your domain name(without .com) and DOMAIN.COM with your complete domain name.

Restart the Samba & Winbind

To restart the Samba and Winbind service, you may execute the below commands,

or

or

Verify krb5.keytab

To list the content of /etc/krb5.keytab file, please execute the below command,

To show the available kerberos tickets, please execute the command,

SUDOER Configuration

To enable a particular AD group to have admin privilege in the Ubuntu box, you need to edit the sudoer configuration. The sudo file is located at /etc/sudoers. The members of AD groups added in sudoers can perform sudo.

To edit the sudoers, please execute,

Configure LightDM

To configure the lightDM, create the lightDM configuration file “/etc/lightdm/lightdm.conf“.

Once the file is saved, restart the lightDM service by executing the below command,

Join the Ubuntu Host to Active Directory Domain

To join the Linux Host to Active Directory Domain, please execute the below command,

Verify the AD connectivity

To verify the active directory connectivity, please execute the below commands.

To test the AD join, please execute the below command,

If the result is ‘Join is OK‘ , then  test the winbind. To test the winbind service, please execute the below commands.

To list the AD users

To List the AD groups,

If it is displaying your AD group and Username details, then it means, your linux box is successfully integrated into the AD domain.

Now try a server reboot. Also try to access using the server via SSH from an another host and perform sudo.

11 Feb

Integrate Ubuntu & Active Directory using Kerberos, Realmd, SSSD

Integrate Ubuntu & Active Directory using Kerberos, Realmd, SSSD

We can integrate Ubuntu & Active Directory using Kerberos, Realmd, SSSD. Prerequisites to join an Ubuntu Server to Windows Active Directory,

  1. Your Ubuntu server should be able to reach AD server.
  2. Active Directory Domain administrator account or an account in Active Directory’s ‘Domain Admins’ group or an account, that has sufficient privilege to join your Ubuntu server to Active Directory domain.

Configure Hosts

The first step of Active Directory join is to edit the /etc/hosts file. Set your machine’s IP address and hostname in /etc/hosts file.

In the hosts file, please enter the below values,

Example :-

In the hosts file, please enter the below values,

Configure Local Resolver

Next you need to setup the /etc/resolv.conf with your name server entries and search domain entry. Usually, the AD server IP itself will be the name server IPs, since DNS role may be installed in the same server.

In the resolv.conf file, please enter the below values

Example :-

Edit the resolv.conf file and please enter the below values

Install the Utilities

Install the required packages,

During the Kerberos installation, you will see a pink screen. Just enter your full domain name in CAPITAL LETTERS,

Eg : DOMAIN.COM

select OK by pressing TAB

You may keep it as BLANK and press OK, if you wish to configure Kerberos later.

Configure NTP Settings

The date and time of your Ubuntu server\host must synchronize with Active Directory  server. Add your active directory’s ntp hostname in the /etc/ntp.conf file,

You can also keep it as Ubuntu’s NTP servers, provided your active directory server’s time and Ubuntu NTP server time are in sync.

In that case, add the below values, instead of above values,

Now sync the Ubuntu host machine’s date and time with NTP server and then start the NTP service,

If you are using your Active Directory’s NTP service, then execute the below commands,

Configure RealMD Settings

Create a file named realmd.conf,

Enter the below values in the realmd config file,

Now, try to get a valid Kerberos ticket for your active directory administrator account,

Join the Ubuntu Host to Active Directory Domain

To join the Ubuntu Host to Active Directory Domain, please execute the below command,

Access Control using REALM

To deny all Active Directory user or group access to your Ubuntu host, please execute the below command,

Once all the access is denied, now we can permit selected active directory user groups or users. To permit selected user groups, please execute the below command,

To permit selected users, please execute the below command,

This will permit two users administrator and george.

Configure SSSD Service

Edit the file sssd.conf. If the file is not existing, you may need to create it,

Enter the below configuration values in the sssd config file. Replace domain.com & domain with your domain name

Now restart the SSSD service by executing the below command,

Edit PAM.D Configuration

To enable the users to auto create home directory upon a successful login to your ubuntu box, you need to edit the /etc/pam.d/common-session file.

Add the line,

below the line\entry

So that, the session config file should look like,

Configure SAMBA Service

To configure the SAMBA service in your Ubuntu box, edit the samba configuration file  /etc/samba/smb.conf

To edit the file, execute the command,

Replace the DOMAIN with your domain name(without .com) and DOMAIN.COM with your complete domain name.

Verify krb5.keytab

To list the content of /etc/krb5.keytab file, please execute the below command,

To show the available kerberos tickets, please execute the command,

SUDOER Configuration

To enable a particular AD group to have admin privilege in the Ubuntu box, you need to edit the sudoer configuration. The sudo file is located at /etc/sudoers. The members of AD groups added in sudoers can perform sudo.

To edit the sudoers, please execute,

Configure LightDM

To configure the lightDM, create the lightDM configuration file “/etc/lightdm/lightdm.conf“.

Once the file is saved, restart the lightDM service by executing the below command,

Verify the AD connectivity

To verify the active directory connectivity, please execute the below commands. You will see the AD user and group information.

Now try a server reboot. Also try to access using the server via SSH from an another host and perform sudo.

11 Feb

Skip interactive post install configuration

Skip interactive post install configuration

To skip interactive post install configuration in linux, you can do it by setting up the DEBIAN_FRONTEND variable to noninteractive. Then use the -y flag in apt-get install command.

Method 1 : Without using sudo. If this does not work, please try with sudo.

Method 2 : Try with sudo,

Example : –

Skip interactive post install configuration

09 Feb

Execute command on remote machine as different user via SSH

Execute command on remote machine as different user via SSH

To execute command on remote machine as different user via SSH, you may need to run the below command

In our example, we are executing the script.sh as root after login to the server as testuser

If you are trying to execute a command to action a file on remote machine as a different user, you need to run the below command,

In our example, we are executing the script.sh as root after login to the server as testuser

If you wish to reboot a remote server as a different user, please execute,

To execute multiple commands via SSH, please execute,

Example script below,

 

06 Feb

Persist Azure Linux virtual machine’s hostname

Persist Azure Linux virtual machine’s hostname

To persist Azure Linux virtual machine’s hostname permanently for an Azure Linux Virtual Machine, you need to ensure that, you have an Azure Linux agent installed in this machine. To install WA Linux Agent in your virtual machine, please refer the link http://blog.admindiary.com/install-microsoft-azure-linux-agent-waagent/

Once the WA Linux Agent or WAAGENT is installed in your machine, you may need to modify the WAAGENT configuration to monitor hostname changes and update the network. To save or persist your hostname permanently, edit the file /etc/waagent.conf and modify the below line,

Provisioning.MonitorHostName=y

Once done, please proceed to restart the WAAGENT service.

For Ubuntu,please execute the below command,

For CoreOS, please execute the command,

If the above steps does not work, you may need to try to install the service by executing the below command,

Now you can change the hostname and it will be updated, both locally and and also at the Azure Portal.

You can execute the below command to change your machine’s hostname.

The command to change the hostname is mentioned in the doc – https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-linux-intro-on-azure?toc=%2fazure%2fvirtual-machines%2flinux%2ftoc.json#hostnamechanges

Even after executing the above steps, if the hostname change is not persisting, you may need to edit the file /var/lib/waagent/ovf-env.xml and update the hostname.

Then look for the below line and change your hostname.

Sample File is pasted below ,

 

05 Feb

Create SWAP partition – Azure Linux Virtual Machine

Create SWAP partition – Azure Linux Virtual Machine

The swap partition created using the standard methods may not persist after a machine reboot, for a linux virtual machine hosted in Microsoft Azure environment. The Microsoft Azure provide the option to create SWAP partition – Azure Linux Virtual Machine,  using the /dev/sdb partition and WAAGENT service.  The  WAAGENT service is an Azure Linux agent for Microsoft Azure environment and will be present in Azure Linux virtual machines by default on each VM. The /dev/sdb partition is a volatile partition(similar to RAM). The data stored in this partition will be lost after each machine reboot. So we can make use of this partition as our swap partition.

To enable the swap in Azure linux VM, you need to do edit the file, that is located at /etc/waagent.conf. Look for the below two lines,

Change the ResourceDisk.EnableSwap=y and ResourceDisk.SwapSizeMB=10240, the value 10240 = 10GB. This will create a /swapfile in the resource disk and persistent system swap space will be created. By default the resource disk in an Azure Virtual Machine will be /mnt/resource(/dev/sdb)

After the change is made, please unmount /mnt and restart the waagent service.

To unmount /mnt, please execute the below command,

Once the /mnt is unmounted, please execute the below command to restart the WAAGENT service.

For Ubuntu,please execute the below command,

For CoreOS, please execute the command,

For other linux distributions, please execute the command,

https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-linux-agent-user-guide

 

05 Feb

Extend-Resize Microsoft Linux Azure Data Disk & OS Disk

Extend-Resize Microsoft Linux Azure Data Disk & OS Disk

To extend-resize Microsoft Linux Azure Data Disk & OS Disk,  the Powershell method can be used for both Classic and ARM models. By default, the OS disk will be 30 GB for Virtual Machines, which may not be sufficient as the ore data is started to get saved into the OS drive.

PLEASE MAKE SURE THAT, YOU ARE HAVING A VALID BACKUP AVAIALABLE FOR YOUR VIRTUAL MACHINE BEFORE EXECUTING THE BELOW STEPS

Extend Data Disk using Powershell – Classic Mode

To extend a Data disk in an Azure Virtual Machine in Classic Mode, we need to perform the below steps,

  1. Open the Windows Powershell ISE and execute the below script

Extend Data Disk using powershell – ARM Mode

To extend a Data disk in an Azure Virtual Machine in ARM Mode, we need to perform the below steps,

  1. Open the Windows Powershell ISE and execute the below script

Extend OS Disk using Powershell – Classic Mode

To extend a OS disk in an Azure Classic Mode Virtual Machine, we need to perform the below steps,

Open the Windows Powershell ISE and execute the below script

Extend OS Disk using Powershell – ARM Mode

To extend a OS disk in an Azure ARM mode Virtual Machine, we need to perform the below steps,

Open the Windows Powershell ISE and execute the below script

Extend the File System Volume Size of Linux VM

Login to your Azure VM using SSH via putty or terminal

By default, in Azure the linux virtual machines will have an OS disk of size 30GB. To resize the OS disk(root drive), please execute the below command

1) Run the command,

Extend-Resize Microsoft Linux Azure Data Disk & OS Disk2) Press the letter ‘u’ to change the units to sectors.

Extend-Resize Microsoft Linux Azure Data Disk & OS Disk3) Now type the letter ‘p’ to list the partition infomormation. Note the starting sector (e.g. 2048).

Extend-Resize Microsoft Linux Azure Data Disk & OS Disk4) Now we can proceed with deleting the partition table. From the fdisk window, delete the partition.  Press the letter ‘d’ and then select the partition by entering the partition number. By default, it will choose the number  1(Assuming you are modifying OS drive).

In reality, you are not deleting the DATA, but rather modifying the partition table

Extend-Resize Microsoft Linux Azure Data Disk & OS Disk5) Now we need to create a new partition. To create a new partition press the letter ‘n’.

6) Type the letter ‘p’ to create a primary partition.

7) Now you enter the partition number. Type 1 to create the first partition (or another partition number, if required). Use the same starting sector from step 3 and enter a end sector value of your wish or just accept the default end sector value to select the entire disk.

Extend-Resize Microsoft Linux Azure Data Disk & OS Disk8) Type the letter ‘p’ to to ensure all settings are correct. It will print the values to screen.

9)  To save your changes and write to the disc, press ‘w’.

Note : You may get a warning that says:

WARNING: Re-reading the partition table failed with error 16: Device or resource busy. 

Ignore the message, since it is not critical

10) Reboot the vitual machine using by typing the command,

11) Once the VM is up and running, login to your Azure VM using SSH and type “sudo resize2fs /dev/sdaX” to resize the filesystem for CentOS/RHEL 6.x (where X is the partition number you created in step 7. In CentOS/RHEL 7.x the command is “xfs_growfs -d /dev/sdaX”. This may take some time to complete.

Extend-Resize Microsoft Linux Azure Data Disk & OS Disk12) Verify the new size with df -h

04 Feb

Extend Microsoft Azure Data Disk & OS Disk

Extend Microsoft Azure Data Disk & OS Disk

To extend Microsoft Azure Data Disk & OS Disk,  the Powershell method can be used for both Classic and ARM models. By default, the OS disk will be 30 GB for Virtual Machines, which may not be sufficient as the ore data is started to get saved into the OS drive.

Extend Data Disk using Powershell – Classic Mode

To extend a Data disk in an Azure Virtual Machine in Classic Mode, we need to perform the below steps,

  1. Open the Windows Powershell ISE and execute the below script

Extend Data Disk using powershell – ARM Mode

To extend a Data disk in an Azure Virtual Machine in ARM Mode, we need to perform the below steps,

  1. Open the Windows Powershell ISE and execute the below script

Extend OS Disk using Powershell – Classic Mode

To extend a OS disk in an Azure Classic Mode Virtual Machine, we need to perform the below steps,

Open the Windows Powershell ISE and execute the below script

Extend OS Disk using Powershell – ARM Mode

To extend a OS disk in an Azure ARM mode Virtual Machine, we need to perform the below steps,

Open the Windows Powershell ISE and execute the below script

Extend the File System Volume of Extended Data or OS Disk – Windows

Once the data disk is extended, the next step is to extend the file system volume on that data disk. For Windows based virtual machines, You can do the volume extension from Server Manager -> Tools -> Computer Management -> Disk Management

Step 1. Open the Server Manager Window

Extend Microsoft Azure Data Disk & OS Disk

Step 2 : Click Tools and then click Computer Management

Extend Microsoft Azure Data Disk & OS Disk

It will open up a window similar to the below picture. Click the Disk Management menu. It will list all the available volumes.

Extend Microsoft Azure Data Disk & OS Disk

Select the Volume, that you wish to extend. Right click the volume to open the menu. Click the Extend Volume option.

Extend Microsoft Azure Data Disk & OS Disk

Click Next button as shown below

Extend Microsoft Azure Data Disk & OS Disk

Then select the size as shown below. Here, we are using a sample volume to extend. So we are extending by 397 MB. After the size is selected, click “Next

Extend Microsoft Azure Data Disk & OS Disk

Now click “Finish” to complete the volume resize.

Extend Microsoft Azure Data Disk & OS Disk

Now you will see the extended volume under Disk Management.
Extend Microsoft Azure Data Disk & OS Disk

https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-windows-expand-os-disk

https://blogs.msdn.microsoft.com/cloud_solution_architect/2016/05/24/step-by-step-how-to-resize-a-linux-vm-os-disk-in-azure-arm/

28 Jan

Create Firewall Rule in Google Cloud Platform

Create Firewall Rule in Google Cloud Platform

A firewall rule is required to access the resources in a network. To create firewall rule in Google Cloud Platform, please login to your GCP portal. Go to the Networking section of the portal and click the “Firewall rules“. Under the “Firewall rules” page, click the “CREATE FIREWALL RULE” link.

Create Firewall Rule in Google Cloud Platform

Once you are in the “Create a firewall rule” page, provide a name for your firewall rule. In our case, we are giving it as ssh-rdp. Under the description, provide a snippet that describes your firewall rule.

Create Firewall Rule in Google Cloud Platform

Select the network from the drop down menu, for which you wish to create the firewall rule. In the Source Filter drop down menu, select the IP ranges. Then  under the Source IP ranges, enter the IP address with its corresponding mask, so that only those IPs will be allowed to access your resources in this network. Under the Allowed protocols and ports section, mention the ports to be opened. If you wish allow TCP port 3389, then mention as tcp:3389. For an udp port 755, mention it as udp:755. Click the button “Create” to create the firewall rule.

Create Firewall Rule in Google Cloud Platform

Once the rule is created, the Firewall rules page will list the rule created, like the one below.

Create Firewall Rule in Google Cloud Platform

gshell method to create firewall rule in GCP

Easiest way of creating a firewall rule in Google Cloud Platform, is to use the gshell. Gshell is fairly easy to use and work with. Please use the below command after connecting to gshell prompt.

1
gcloud compute --project "<Your GCP project ID>" firewall-rules create "<Provide the firewall name>" --allow <Provide ports with protocols to be allowed> --description "<Description of firewall rule here>" --network "<Provide the network name here>" --source-ranges "<Provide the IP range to be allowed here>"

Example :

1
gcloud compute --project "composite-drive-123456" firewall-rules create "ssh-rdp" --allow tcp:3389,tcp:22 --description "Allow SSH and RDP Access to front end network" --network "frontend-network" --source-ranges "123.456.789.123/32"

Create Firewall Rule in Google Cloud Platform

28 Jan

Create network in Google Cloud Platform

Create network in Google Cloud Platform

To create network in Google Cloud Platform, step 1 is to Logon to your Google Cloud account.

Move on to the Networking section under the portal. Then click the link “Networks“. It will open up a window for creating the network. Click the “CREATE NETWORK” to start creating your network.

Create network in Google Cloud Platform

Under the “CREATE NETWORK” page, choose a name for your network. Also provide a description which will help you to identify your new network.

Create network in Google Cloud Platform

You can create the subnets under your network from the same page. Provide a “Name” & “Description” for your subnet. Select the “Region” from the drop down menu. Next step is to provide an IP address range for your subnet.  Provide the subnet mask also, when you provide your IP address range. You can create additional subnets by clicking the “+ Add subnetwork“.

Create network in Google Cloud Platform

Gshell Method to create the Network

Open the gshell window. Once it is “connected”, then enter the below code as shown in the picture. Replace the Then press “Enter” to start the code execution.

1
gcloud compute --project "<project name>" networks create "<network-name>" --description "<Description of your network>" --mode "custom" && gcloud compute --project "<project name>" networks subnets create "<subnet-name>" --network "<network-name>" --region "<Region-Name>" --range "<IP-Address-Range>"

Sample

1
gcloud compute --project "composite-drive-123456" networks create "backend-network" --description "Back End Network for Databases" --mode "custom" && gcloud compute --project "composite-drive-123456" networks subnets create "backend-subnet" --network "backend-network" --region "us-central1" --range "10.2.0.0/24"

Create network in Google Cloud Platform

Once the Network creation is done, it will show an output like the one below.

Create network in Google Cloud Platform

The next step is to create firewall rule. Please refer the below link to create a firewall rule in GCP.

Create Firewall Rule in Google Cloud Platform