Monday, July 28, 2025

Join an Ubuntu Machine to Active Directory and Configure Cisco DUO MFA

 

Join Ubuntu VM to Domain

Step 1: Check and correct the VM name


hostnamectl set-hostname FQDN-HOSTNAME

hostname FQDN-HOSTNAME


vi /etc/hosts

Step 2: Install Required Packages


apt update && apt upgrade -y

apt install realmd sssd sssd-tools libnss-sss libpam-sss adcli samba-common-bin oddjob oddjob-mkhomedir packagekit -y


systemctl enable --now oddjobd


reboot

Step 3: Discover the Domain


realm discover domain.local

Step 4: Join the Domain


realm join --user=vishal.rajput domain.local


realm list

Step 5: Create a Local Linux Group


groupadd ssh-admins

Step 6: Add Domain Users to the Local Group


usermod -a -G ssh-admins 'vishal.rajput@domain.local'

Step 7: Restrict Logins to Local Group Only


vi /etc/sssd/sssd.conf


[sssd]

domains = DOMAIN.LOCAL

config_file_version = 2

services = nss, pam, ssh


[domain/DOMAIN.LOCAL]

ad_domain = DOMAIN.LOCAL

krb5_realm = DOMAIN.LOCAL

realmd_tags = manages-system joined-with-adcli 

id_provider = ad

access_provider = simple

simple_allow_groups = domain admins, ssh-admins


# Recommended for login experience

use_fully_qualified_names = False

fallback_homedir = /home/%u@%d

default_shell = /bin/bash

ldap_id_mapping = True

cache_credentials = True

krb5_store_password_if_offline = True


systemctl restart sssd

Step 8: Check & Configure the NSSSWICTH settings


vi /etc/nsswitch.conf


passwd:         compat systemd sss

group:          compat systemd sss

shadow:         compat sss

Step 9: Grant sudo Access to Local Group


visudo


%ssh-admins ALL=(ALL:ALL) ALL

Step 10: Update /etc/ssh/sshd_config


vi /etc/ssh/sshd_config

UsePAM yes

Step 11: Enable Home Directory Creation


pam-auth-update  --force

Ensure the following are checked:

"SSSD"
"Create home directory on login" (pam_mkhomedir)
"Unix authentication"
"Unix account"

After this, the following PAM files should have references to pam_sss.so:


grep sss /etc/pam.d/common-*


You should see lines like:


/etc/pam.d/common-auth:auth    [success=1 default=ignore] pam_sss.so use_first_pass

/etc/pam.d/common-account:account [success=1 new_authtok_reqd=done default=ignore] pam_sss.so

Step 12: Restart All Related Services

systemctl restart sssd


systemctl restart ssh

Step 13: Test the Setup


ssh 'vishal.rajput'@10.50.2.122

Step 14: verify user group membership with:


id 'vishal.rajput@domain.local’

Step 15: update membership for users in the machine and try the sudo access.


usermod -a -G ssh-admins vishal.rajput

Step 16: To leave the domain, execute the below command.


realm leave DOMAIN.LOCAL




































Configure DUO authentication


One the Domain login works fine with the above steps, make the below changes in configuration files to make the DUO working.

Installation of prerequisites for DUO configuration.


Create a file in the system.


vi /etc/apt/sources.list.d/duosecurity.list


deb [arch=amd64] https://pkg.duosecurity.com/Ubuntu jammy main


curl -s https://duo.com/DUO-GPG-PUBLIC-KEY.asc | sudo gpg --dearmor -o  /etc/apt/trusted.gpg.d/duo.gpg


apt-get update && apt-get install duo-unix -y


Update the key details in DUO configuration files. (These details can be obtained from the DUO portal for application, all key details will be different according to the application) 


vi /etc/duo/pam_duo.conf


[duo]

; Duo integration key

ikey = DIPZKZT8H9ELTTTVLFE2 

; Duo secret key

skey = AHZoYq7j9197Bgf9bWFl1QUdLy6smEPGsFAR6pvD

; Duo API host

host = api-cf60925f.duosecurity.com

; `failmode = safe` In the event of errors with this configuration file or connection to the Duo service

; this mode will allow login without 2FA.

; `failmode = secure` This mode will deny access in the above cases. Misconfigurations with this setting

; enabled may result in you being locked out of your system.

failmode = safe

; Send command for Duo Push authentication

pushinfo = yes

autopush = yes

prompts = 1


cp /etc/duo/pam_duo.conf /etc/duo/login_duo.conf

Working “/etc/pam.d/sshd” file content:


Before adding the content make sure to find the pam_duo.so file location and update content accordingly in the file.


vi /etc/pam.d/sshd


# First, perform system password-based auth (local or SSSD)

@include common-auth

# Conditionally apply DUO for domain users only (UID >= 1000000 for SSSD)

auth [default=1 success=ok] pam_succeed_if.so uid >= 1000000


# Then trigger Duo MFA (only after password is verified)

auth    required    /usr/lib64/security/pam_duo.so


# Check for login restrictions (nologin, etc.)

account required    pam_nologin.so


# Include account handling (local and AD)

@include common-account


# Session setup

session [success=ok ignore=ignore module_unknown=ignore default=bad] pam_selinux.so close

session required     pam_loginuid.so

session optional     pam_keyinit.so force revoke


@include common-session

session optional     pam_motd.so motd=/run/motd.dynamic

session optional     pam_motd.so noupdate

session optional     pam_mail.so standard noenv

session required     pam_limits.so

session required     pam_env.so

session required     pam_env.so user_readenv=1 envfile=/etc/default/locale

session [success=ok ignore=ignore module_unknown=ignore default=bad] pam_selinux.so open


# Password updates

@include common-password

Working “/etc/pam.d/common-auth” file content:


vi /etc/pam.d/common-auth


# /etc/pam.d/common-auth - authentication settings common to all services


auth [success=2 default=ignore] pam_unix.so nullok

#auth  [success=1 default=ignore] pam_duo.so


auth [success=1 default=ignore] pam_sss.so use_first_pass

# here's the fallback if no module succeeds


auth requisite pam_deny.so

# prime the stack with a positive return value if there isn't one already;

# this avoids us returning an error just because nothing sets a success code

# since the modules above will each just jump around


auth required pam_permit.so

# and here are more per-package modules (the "Additional" block)

auth optional pam_cap.so 


# end of pam-auth-update config


Enable settings in sshd_config file.


vi /etc/ssh/sshd_config


KbdInteractiveAuthentication yes

PubkeyAuthentication yes


Restart all required services and check the SSH access.


systemctl restart sshd

systemctl restart sssd



Monday, July 24, 2023

How to Update CentOS IP and Hostname via Bash Script

I have created below mentioned bash script which will help you to update the IP Address and the hostname of the CentOS machines via this bash script.

#!/bin/bash


read -p "Enter the new IP address i.e: 10.50.4.243/20 : " ip_address


read -p "Enter the new gateway i.e:- 10.50.0.1 : " gateway


read -p "Enter the new hostname i.e: co7-50-4-243 : " hostname


# Get the interface name

interface=$(ip route | awk '/default/ { print $5 }')


# Get the ip address

ipa=$(hostname -I | awk '{ print $1 }')


# Update the IP address and gateway

echo "Updating IP address and gateway..."

nmcli con mod "$interface" ipv4.address "$ip_address"

nmcli con mod "$interface" ipv4.gateway "$gateway"


# Update the hostname

echo "Updating hostname..."

hostnamectl set-hostname "$hostname"


# Update the /etc/hosts file

echo "Updating /etc/hosts file..."

echo "$ipa $hostname" >> /etc/hosts


# Restart the network service

echo "Restarting network service..."

systemctl restart NetworkManager


echo "IP address, gateway, hostname, and /etc/hosts file updated successfully."

Friday, April 15, 2022

Configure bonding/teaming on Redhat Linux

Having a multiple network card will not give any redundancy.In redhat Linux you need to configure bonding to accomplish the network level redundancy.Once you have configured the bonding/teaming by using two NIC cards,kernel will automatically detect the failure of any NIC and work smartly according to that without any riot.Bonding can be used for load sharing as well between two physical links.



NIC Details:

[root@mylinz2 network-scripts]# ifconfig -a |grep eth
eth2      Link encap:Ethernet  HWaddr 00:0C:29:79:17:FA  
eth4      Link encap:Ethernet  HWaddr 00:0C:29:79:17:04  
eth3      Link encap:Ethernet  HWaddr 00:0C:29:79:17:F0 

[root@mylinz2 network-scripts]#

Goal:

Configure bonding between eth2 and eth4 with name of bond0.


Step 1:

Add the below line in /etc/modprobe.conf to load the bonding module in to kernel.

# alias bond0 bonding

In redhat 6.3 , you need to create new file called “bonding.conf” under /etc/modprobe.d/ with below mentioned line.

# cat /etc/modprobe.d/bonding.conf

alias bond0 bonding

Step 2:

Now time to create a bonding interface configuration file in /etc/sysconfig/network-scripts/ directory like the below one.

[root@mylinz2 network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@mylinz2 network-scripts]# cat ifcfg-bond0 
#This is congiguration file for bond0.Used NIC's eth2 & eth4
DEVICE=bond0
IPADDR=192.168.10.25
NETMASK=255.255.255.0
USRCTL=no
ONBOOT=yes
BOOTPRO=none
BONDING_OPTS="mode=0 miimon=100"

[root@mylinz2 network-scripts]#

Step:3

Create a configuration files under “/etc/sysconfig/network-scripts/” for network interfaces if not exists.If exists,have a contents like the below one.

[root@mylinz2 network-scripts]# cat ifcfg-eth2
DEVICE=eth2
HWADDR=00:0C:29:79:17:FA
BOOTPRO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes

USERCTL=no

[root@mylinz2 network-scripts]# cat ifcfg-eth4
DEVICE=eth4
HWADDR=00:0C:29:79:17:04
BOOTPRO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes

USERCTL=no

Note:Do not copy paste the content from above output.MAC and DEVICE name will differ for each system.

Step:4


Now restart the network service to load the configuration.

Note:Do not restart the network service without server maintenance window.


[root@mylinz2 ~]# service network restart
Shutting down interface eth2:  Device state: 3 (disconnected) [  OK  ]
Shutting down interface eth4:  Device state: 3 (disconnected) [  OK  ]
Shutting down loopback interface:                             [  OK  ]
Bringing up loopback interface:                               [  OK  ]
Bringing up interface bond0:  Active connection state: activated
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/15
[  OK  ]
Bringing up interface eth3:  Active connection state: activated
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/16
[  OK  ]
[root@mylinz2 ~]#

Step:5

Verify whether “bond0” has come up with IP or not .


[root@mylinz2 Desktop]# ifconfig -a
bond0     Link encap:Ethernet  HWaddr 00:0C:29:79:17:FA  
inet addr:192.168.10.25  Bcast:192.168.10.255  Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe79:17fa/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
RX packets:22 errors:0 dropped:0 overruns:0 frame:0
TX packets:27 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0 
RX bytes:3843 (3.7 KiB)  TX bytes:4169 (4.0 KiB)
eth2      Link encap:Ethernet  HWaddr 00:0C:29:79:17:FA  
UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
RX packets:11 errors:0 dropped:0 overruns:0 frame:0
TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000 
RX bytes:2031 (1.9 KiB)  TX bytes:2064 (2.0 KiB)
eth4      Link encap:Ethernet  HWaddr 00:0C:29:79:17:FA  
UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
RX packets:11 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000 
RX bytes:1812 (1.7 KiB)  TX bytes:2105 (2.0 KiB)

In the above output,you can see NIC eth2 and eth4 have flag “SLAVE” and interface “bond0” has flag MASTER.Another thing you note both, the NIC interface will show same MAC address.

Step:6
Performing the live test to ensure bonding is providing the fault tolerance.
First i am removing the LAN cable from eth4 and let see what happens.


[root@mylinz2 Desktop]# ifconfig -a
bond0     Link encap:Ethernet  HWaddr 00:0C:29:79:17:FA  
inet addr:192.168.10.25  Bcast:192.168.10.255  Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe79:17fa/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
RX packets:22 errors:0 dropped:0 overruns:0 frame:0
TX packets:27 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0 
RX bytes:3843 (3.7 KiB)  TX bytes:4169 (4.0 KiB)
eth2      Link encap:Ethernet  HWaddr 00:0C:29:79:17:FA  
UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
RX packets:11 errors:0 dropped:0 overruns:0 frame:0
TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000 
RX bytes:2031 (1.9 KiB)  TX bytes:2064 (2.0 KiB)
eth4      Link encap:Ethernet  HWaddr 00:0C:29:79:17:FA  
UP BROADCAST SLAVE MULTICAST  MTU:1500  Metric:1
RX packets:11 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000 
RX bytes:1812 (1.7 KiB)  TX bytes:2105 (2.0 KiB)

Still the bond0 interface is UP and RUNNING fine.At the same time,”RUNNING” flag has disappear from eth4.

Now i have connected LAN cable back to eth4 and pulling out from eth2.


[root@mylinz2 Desktop]# ifconfig -a
bond0     Link encap:Ethernet  HWaddr 00:0C:29:79:17:FA  
inet addr:192.168.10.25  Bcast:192.168.10.255  Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe79:17fa/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
RX packets:22 errors:0 dropped:0 overruns:0 frame:0
TX packets:27 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0 
RX bytes:3843 (3.7 KiB)  TX bytes:4169 (4.0 KiB)
eth2      Link encap:Ethernet  HWaddr 00:0C:29:79:17:FA  
UP BROADCAST SLAVE MULTICAST  MTU:1500  Metric:1
RX packets:11 errors:0 dropped:0 overruns:0 frame:0
TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000 
RX bytes:2031 (1.9 KiB)  TX bytes:2064 (2.0 KiB)
eth4      Link encap:Ethernet  HWaddr 00:0C:29:79:17:FA  
UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
RX packets:11 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000 
RX bytes:1812 (1.7 KiB)  TX bytes:2105 (2.0 KiB)

Still “bond0” interface running with UP & RUNNING flag.So you have successfully configured bonding on Redhat Linux 6.

To see complete bonding info,use below command.

[root@mylinz2 Desktop]# cat /proc/net/bonding/bond0 
Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)
Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 0
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth2
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:79:17:fa
Slave queue ID: 0
Slave Interface: eth4
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:79:17:04
Slave queue ID: 0
[root@mylinz2 Desktop]#
To verify the current bonding mode,use below command. 
[root@mylinz2 Desktop]# cat /sys/class/net/bond0/bonding/mode
balance-rr 0

You can modify the bonding mode by editing “mode” in the ifcfg-bond0  configuration file.

[root@mylinz2 Desktop]# cat /etc/sysconfig/network-scripts/ifcfg-bond0 |grep -i mode
BONDING_OPTS="mode=0 miimon=100"
POLICY DETAILS

Ploicy NameCodeDescription
balance-rr0Round-Robin policy for fault tolerance
active-backup1Active-Backup policy for fault tolerance
balance-xor2Exclusive-OR policy for fault tolerance
broadcast3All transmissions are sent on all slave interfaces.
802.3ad4Dynamic link aggregation policy
balance-tlb5Transmit Load Balancing policy for fault tolerance
balance-alb6Active Load Balancing policy for fault tolerance
To list the currently configured bonds,


[root@mylinz2 Desktop]# cat /sys/class/net/bonding_masters 
bond0

How to configure SSL in vCenter 6.7

First take vCenter VM snapshot for backup purpose.

Take note of host where the vCenter VM resides while starting the activity.

Take Access of vCenter Shell to create a certificate CSR request.

root@prod-vcsa71 [ ~ ]# /usr/lib/vmware-vmca/bin/certificate-manager

Now copy the CSR file content in notepad file and save as .txt or .csr

Once have the CSR, generate a certificate by using this CSR.



Now copy the certificate file to the vcenter along with the RootCA certificate.


Start process for Import the certificate.

root@prod-vcsa71 [ ~ ]# /usr/lib/vmware-vmca/bin/certificate-manager



Provide certificate file location as per below the snip, Once all details provided it will take around 20-30 mins depending on the vCenter performance.



Once all required services started properly it will give the status as mentioned below.



Now try to access the vCenter from WebGUI, It is now secure.



Also try to access the vCenter Appliance Management Interface, It will still show the certificate error, to resolve this, restart the vami https service as mentioned below.



root@prod-vcsa71 [ /opt ]# /sbin/service vami-lighttpd restart



Now again try to access the vCenter Appliance Management Interface, It will also start with SSL certificate.




To check service status: 

root@prodvcenter [ ~ ]# service-control --status --all

To check logs if anything fails.

root@prodvcenter [ ~ ]# tail -f /var/log/vmware/vmcad/certificate-manager.log

If Certificate import files due to content-library service fails to start, increase Start time in below mentioned file from 300 to 600sec.

root@prodvcenter [ ~ ]# vi /etc/vmware/vmware-vmon/svcCfgfiles/vdcs.json