Saturday, January 26, 2019

CentOS6 and 7 information collection script.

In case you are making major changes to the Linux systems and got multiple OS - Below script may help to enter your choice of OS to select and backup the important directories files and commands output. This is a standard layout. Where unless the right arguments are provided on the command line to the script - The The script does not give up and on providing wrong arguments script still waits for the correct argument. The script can be modified by adding your choice of application directories in the path and tar them same with the commands and other important files.

[root@desk-03 tmp]# cat osinfocollect.sh
# Author: Raj Sangvikar
# DATE:01-25-2018
# Script for saving networking configuration and system information.
# copy fstab, hosts, mount, ifcfg-* files, nsswitch.conf, sssd.conf, ldap.conf, OS version.


TODAY=`date +%Y-%m-%d.%H:%M:%S`
NEWDIR=`date +%Y-%m-%d`
DESTINATION="/var/tmp/sysbak_$NEWDIR"
#OSVERSION=$(cat /etc/redhat-release | awk '{print $7}' |  cut -f1 -d.)

# Create a new Directory in the /var/tmp

mkdir -p $DESTINATION

# Copy the important /etc directory and tar in .gz format in  above directory

tar -czvf $DESTINATION/etc.tar.gz /etc/ > /dev/null 2>&1

# We will need some inportant commands output saved in the above directory in the file named "commands_data_output.txt"

uptime >  $DESTINATION/commands_data_output.$TODAY

echo  "=============================================================================" >> $DESTINATION/commands_data_output.$TODAY

mount  >>  $DESTINATION/commands_data_output.$TODAY

echo  "=============================================================================" >> $DESTINATION/commands_data_output.$TODAY

uname -a >>  $DESTINATION/commands_data_output.$TODAY

echo "=============================================================================" >> $DESTINATION/commands_data_output.$TODAY

df -h >> $DESTINATION/commands_data_output.$TODAY

echo "=============================================================================" >> $DESTINATION/commands_data_output.$TODAY

free -m >> $DESTINATION/commands_data_output.$TODAY

echo  "=============================================================================" >> $DESTINATION/commands_data_output.$TODAY

ifconfig -a >> $DESTINATION/commands_data_output.$TODAY

echo "=============================================================================" >> $DESTINATION/commands_data_output.$TODAY

lvdisplay >> $DESTINATION/commands_data_output.$TODAY

echo "=============================================================================" >> $DESTINATION/commands_data_output.$TODAY

route -n >> $DESTINATION/commands_data_output.$TODAY

echo  "=============================================================================" >> $DESTINATION/commands_data_output.$TODAY

echo "Enter 1 for CentOS-6 And 2 for CentOS-7:"

while read num
do

if [[ $num -eq 1 ]];
then
iptables -L -t nat >> $DESTINATION/commands_data_output.$TODAY
echo "Necessary commands output files and directories are backed up in $DESTINATION"
exit 0
else
if [[ $num -eq 2 ]];
then
firewall-cmd --list-all >> $DESTINATION/commands_data_output.$TODAY
echo "Necessary commands output files and directories are backed up in $DESTINATION"
exit 0
else
echo "Please enter 1 for CentOS-6 And 2 for CentOS-7:"
 fi
fi
done

========================================================================

[root@desk-03 tmp]# ./osinfocollect.sh

Enter 1 for CentOS-6 And 2 for CentOS-7:
5
Please enter 1 for CentOS-6 And 2 for CentOS-7:
3
Please enter 1 for CentOS-6 And 2 for CentOS-7:
1
Necessary commands output files and directories are backed up in /var/tmp/sysbak_2019-01-26


Happy Scripting!


Disclaimer: This is for my reference only - Use at your own discretion.

Friday, January 25, 2019

lsb_release package install with script.

[root@desk-03 tmp]# cat lsb_pkginstall.sh

#!/bin/bash

FILENAME=/usr/bin/lsb_release

if [ ! -f  $FILENAME ]

then

echo "Installing lsb_release on the system please wait....."

yum repolist > /dev/null 2>&1  ; sleep 3 ;  yum -y install redhat-lsb-core > /dev/null 2>&1

echo `ls -l /usr/bin/lsb_release`

else

echo "lsb_release command exists nothing changed"

fi


Happy Scripting!


Disclaimer: This is for my reference only - Use at your own discretion.

Use RDP to connect to CentOS 7 GUI.

Follow below steps to get this going...


#  rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm
# rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm
# yum -y install xrdp tigervnc-server
# systemctl start xrdp.service
# ifconfig
# systemctl status firewalld
#  firewall-cmd –permanent –zone=public –add-port=3389/tcp
# firewall-cmd --add-port=3389/tcp --permanent
# firewall-cmd --reload
# firewall-cmd --list-all

[Next]

Open Remote desktop - punch in IP/Hostname and enter user/password once prompted.



Disclaimer: This is for my reference so use at your own discreet.

Happy Linux!


CentOS7 GUI installation.

To access desktop in CentOS7: As root

  • Make sure yum repository is active and running
# yum repolist
 
# yum groupinstall "Server with GUI"

 # systemctl isolate graphical.target

 # systemctl set-default graphical.target

 # systemctl get-default

 # graphical.target . --> 

You should see this after reboot or not required in some cases. Mine got switched to GUI without reboot so looks like the above command takes care of that and not like old times.



Happy Linux!




Friday, January 11, 2019

Few Linux System Administrator "One Liners"


Some common frequently needed commands:


  • Change the hostname everywhere in CentOS/RHEL7:

# hostnamectl --static set-hostname idm-auth-admin-lkf-noc03

# systemctl restart systemd-hostnamed

  • To update the ntpd with the timeserver:
# ntpdate -u  time_server_ip

# ntpq -np

  • RHEL7 client registration with RHN network.
# subscription-manager register --username --password  secret --auto-attach

  • DNS record queries - forward and reverse

DNS records quarry for Linux host:

[root@idm ~]# dig +short idm.lab.example.com A
172.25.250.8

[root@idm ~]# dig +short -x 172.25.250.8
idm.lab.example.com.

grep -w(hostname) /etc/hosts




How to create IPA External and IPA POSIX Groups.

Creating RHEL7 IdM Groups for Active directory users :

This is a four step process after the AD external trust is established with the RHEL7 IdM. Which is Authentication part where you can login as an AD user via IdM to the Linux clients/hosts. But to get authorized to be able to execute root level command and to be a root user. Where access like -
"sudo su -" is required as a Linux Administrator.


  • # ipa group-add --desc='AD users external map' ad_users_external --external
  • # ipa group-add --desc='AD users' ad_users
  • # ipa group-add-member ad_users_external --external "AD_DOMAIN\Administrator"
  • # ipa group-add-member ad_users --groups ad_users_external

Happy Linux!

ipa-client-install --enable-dns-updates --domain domain_name fails with LDAP Connect Error.

LDAP Error: Connect error: Start TLS request accepted.Server willing to negotiate SSL

During reinstalling the spa client as a part of migrating the host/client from Free IPA to RHEL7 IdM
Client is - CentOS 6.6
IdM is - FreeIPA, version: 4.6.4

Cause of the issue: Looks like this is a bug.

Details:

The host had old ldap configuration and old /etc/ipa/ca.crt  was forcing ipa-client-install script to use cert as there was remnant configuration hanging around. But after running below command  the spa client install went fine.

mv /etc/ipa/ca.crt /etc/ipa/ca.crt.Orig

As per RHEL7 - ipa-client-install --uninstall do not remove DNS entries from IPA server.

But in this case this was not applicable as the issue was totally client side one as it was using openldap server for authentication and authorization!

[root@idm-client ~]# ipa-client-install --enable-dns-updates --domain
Discovery was successful!

Happy Linux!