Monday 27 November 2017

Install local NTP server and client configuration RHEL 6 & 7

Step 1

It's easy to install ntp server. Just enable the internet connection in the target server or client server and issue the following command in terminal.

yum install ntp -y

Step 2

Configure the ntp for server configuration. Goto the ntp configuration location and edit the ntp configuration file. /etc/ntp.conf

vi /etc/ntp.conf

If you want to use public ntp server then for your required timezone then choose it from online (http://www.pool.ntp.org/en/)

If you need local then just # all the available server list like below screenshot.

 

and allow your local or required subnets for ntp

restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap

also enable the log file on it with below line.

logfile /var/log/ntp.log

Add local clock for local ntp

server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10

save and exit

Step 3

If you have firewall or iptables must allow 123 port and ntp service.

then start the ntp server with below command

service ntpd start

and enable it with below command

chkconfig ntpd on

verify the configuration with below command.

ntpq -p

and 

date -R

Step 4

Client server configuration.

Just install ntp like above.

yum install ntp -y

add the configuration in /etc/ntp.conf

# all the public pool already available on that and add like below.

server 192.168.2.3 prefer

save and exit

now start the service with below command

service ntpd start

chkconfig ntpd on

verify the connection

ntpq -p 

you can see the remote ip of your ntp server

if it not update then update with following command

ntpdate -u 192.168.2.3

that's all



Tuesday 21 November 2017

Linux File Permissions in details

There is lot of good security features in linux build in it, one of the most very important feature that helps as from local access. That is permission based files and directories.

Basic File Permissions :

In Linux each files and directory has three user based permission groups


  1. owner - The Owner permissions will not impact the other user actions.
  2. group - The Group permission has the permission only the user in that group others action will not impact.
  3. all users - The All users permission apply to all user it will impact to all users action.
Permission Type :

In Linux each files and directories have three basic permission type
  1. read - The Read permission refers to a user's capability to read the contents of the file.
  2. write - The Write permission  refers to a users to write or modify the files and directory.
  3. execute - The Execute permission to execute a file or view the contents of a directory.
View the Permissions :

We can view the permissions of file or directory with following command ls -l 

The permission in the command line is displayes as : _rwxrwxrwx 1 owner:group

  • The first character that I marked with an _ is the special permission flag that can vary.
  • second rwx is for owner permission.
  • third rwx is for group permission.
  • forth is for all users permissions.
  • number displays the number of hard links to the file.
  • next it shows the owner and group of the file or directory.
Explicitly Defining Permissions :

To explicit define permissions you nned to reference the permission group and permission type.

The Permission Groups are :
  • u - Owner
  • g - Group 
  • o or a - All users
The potential assignment operators are + (plus) and - (minus) tells the system whether to add or remove the permissions.

The permission types are :
  • r - Read
  • w - Write
  • x - Execute
file permission example if I have test file and it has _rw_rw_rw and I want to remove the rw permission from all users for that I use the following command 

chmod a-rw test

if I want to add all user to rw then

chmod a+rw test

Binary Permissions :

Now you understand the permissions of groups and types. Now we are going to use binary permissions. We need to understand the input is have 3 binary number. That listed below.
  • r = 4
  • w = 2
  • x = 1
sample permission string is below mentioned

chmod 751 test

it means that owner has full permission, group has read and write permission and all users have execute permission.

Owner and Group :

For owner and group we need different command to assign permissions. Below I have mentioned below

chown owner:group file

chown redhat:team test

In that redhat is owner and team is group.

Advanced Permissions :

The special permissions flag can be marked with any of the following.
  • _ - no special permissions
  • d - directory
  • l - The file or directory is a symbolic link
  • s - Indicates the setuid/setgid permissions. This is not set displayed in the special permission part of the display, but it represented as a s in the read portion of the owner or group permissions.
  • t - It indicates the sticky bit permissions.
Setuid/setgid special permission

This permissions are used to run the executable file as owner with owner permission. If we assigned it wrongly then it will open your system in intrusion.

It's easy to add setuid and setgid with following command with s.

chmod g+s test.sh

chmod u+s test1.sh

Sticky Bit special permission

In this permission owner only can rename or delete the file or folder. 

We can assign this sticky bit permission by explicitly with the character of t.

we add this permission with following command.

chmod +t testdir

if we want to remove then use the following command

chmod -t testdir

If any mistakes in this please command and made this in correct. 

Thanks in advance.






bash shell script to html

Hi All,

I have searched so many website for linux command output to html out put and I didn't get much finally I got one small samble and i made that with required command output to html. 

Here I have put the details in below.

#echo "<html><head><title>Chain-Sys</title><style>body{font-family:arial;font-size:13px;background:#f8f8f8;margin:0;padding:0}body h1:first-child{text-align:center;font-size:28px;background:#fff;border-bottom:#eee 1px solid;padding:20px;color:#09c;box-shadow:0 1px 2px #e8e8e8}h1{font-weight:400;font-size:18px;padding:0 20px}pre{background:#f2f2f2;padding:20px;margin:20px;border-radius:5px;border:1px solid #e8e8e8;font-family:Courier New,arial}</style></head><body>"
echo "<h1>Informations of host  - `hostname`</h1>"
echo ""
echo "<h1>Server Details</h1>"
echo "<pre>`hostname -i && date && uptime` </pre>"
echo "<h1>top process list</h1>"
echo "<pre> `ps aux | sort -nrk 3,3 | head -n 5` </pre>"
echo "<h1>CPU utilization on current server</h1>"
echo "<pre> `top -b -n2 -p 1 | fgrep "Cpu(s)" | tail -1 | awk -F'id,' -v prefix="$prefix" '{ split($1, vs, ","); v=vs[length(vs)]; sub("%", "", v); printf "%s%.1f%%\n", prefix, 100 - v }'` </pre>"
echo "<h1>List of iptables rule</h1>"
echo "<pre> `iptables -L` </pre>"
echo "<h1>Memory Info</h1>"
echo "<pre> `free -m` </pre>"
echo "<h1>Disk Info:</h1>"
echo "<pre> `df -h` </pre>"
echo "<h1>Active Connections</h1>"
echo "<pre> `ss -s` </pre>"
echo "<h1>Logged in users</h1>"
echo "<pre> `last | tail -10` </pre>"
echo "<h1>I/N Connection</h1>"
echo "<pre> `/opt/trial/sh.sh` </pre>"
echo "<h1>Number of Process</h1>"
echo "<pre> `cat /proc/stat | grep proc*` </pre>"
echo "<h1>NFS Mount Status</h1>"
echo "<pre> `mount -l -t nfs` </pre>"
echo "<h1>Crond Status</h1>"
echo "<pre> `crontab -l` </pre>"
echo "<h1>Failed Login Attempts</h1>"
echo "<pre> `less /var/log/secure | grep Failed` </pre>"
echo "<center>Information generated on `date`</center>"
echo "</body></html>"

 

For I/N connection I have add a sh file with below script.

if ping -q -c 1 -W 1 google.com >/dev/null; then
echo "I/N is Available"
else
echo "I/N is Unavailable"
fi

 

save this script as ss.sh and put same place of this script.

Just save the file as sh and run like below and check it will work 100%.

save as sample.sh  and run

./sample.sh > sample.html

open the output in browser.  

If you have any better idea please share me the knowledge I'm having knowledge thirst or any suggestion please reply as command. 

Thanks for viewing.

Zabbix installation in RHEL 6 & 7


Step 1
We need to install all the required packages and dependencies. Below I have mentioned the detailed packages that required to install zabbix.

  • Apache above 1.3.12
  • PHP above 5.4.0 and 7 is not support for zabbix
  • Mysql above 5.0.3
  • OpenIPMI
  • libssh2 above 1.0 version - for ssh support.
  • fping - for ICMP ping items.
  • libcurl - for web monitoring
  • libiksemel - for jabber support.
  • net-snmp - for snmp support.

Step 2
Setup Apache, Mysql and PHP.
Use below command to install required package and dependencies.

yum install httpd httpd-devel -y

yum install mysql mysql-server -y

yum install php php-cli php-common php-devel php-pear php-gd php-mbstring php-mysql php-xml -y
after installation need to start the services with below command.
service httpd start
service mysqld start
Step 3
Setup mysql like below
mysql_secure_installation
it will provide the details like below and give the details that you rquired.
Now try to login mysql with given password

mysqld -u root -p

Step 4

Configure Repository for zabbix.

For CentOS/RHEL 7

rpm -Uvh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm

For CentOS/RHEL 6

rpm -Uvh http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm

Now start installing zabbix with mysql

yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent zabbix-java-gateway -y

Step 5

Setup apache for zabbix with below details.
after installing zabbix it will create by default it configuration in /etc/httpd/conf.d/zabbix.conf. edit this file and modify the timezone on your required.
php_value date.timezone Asia/Kolkata
now restart the apache service with below command
service httpd restart
Step 6
Creating database for zabbix in mysql PHP
login mysql with root
mysql -u root -p
now create database
CREATE DATABASE zabbix CHARACTER SET UTF8;
now create a user with permission
GRANT ALL PRIVILEGES on zabbix.* to user@localhost IDENTIFIED BY 'password';
now flush it
FLUSH PRIVILEGES;
quite;
after creating DB and user we need to restore the default DB of zabbix to mysql.
We can found that on /usr/share/doc/zabbix-server-mysql-3.0.0 in this location or
/usr/share/doc/zabbix-server-mysql-3.0.0/create.
on that we can found a zip file just unzip it and use it with below commands.

gunzip create.sql.gz
mysql -u user -p zabbix < create.sql
it will restore all the required details to zabbix db.  

now check the DB details in zabbix configuration in /etc/zabbix/zabbix_server.conf

add details of db

DBHost=localhost
DBName=zabbix
DBUser=user
DBPassword=password

save & exit

Configure PHP
Need to change some parameters in php for zabbix. Find the details below and modifies as per your requirement in /etc/php.ini.
vi /etc/php.ini
max_execution_time = 600
max_input_time = 600
memory_limit = 2048
post_max_size = m2M
upload_max_filesize = 16M
date.timezone = Asia/Kolkata
if you use firewall or iptables don't forget to allow following ports.
10050, 10051 and 80
Step 7
Now restart and start the required services.
service httpd restart
service zabbix-server start
and don't forget to enable it to auto start on boot
chkconfig zabbix-server on
chkconfig httpd on
chkconfig mysqld on
now open the  url in your browser

http://ipaddress/zabbix

it will lead you to installation page like below screenshot


click next

it will lead you to the prerequisites you can check if anything missing in this.

Click next
now you will lead to DB config check the details or add the details of DB that you have created for zabbix.

after fill all click next

Then give the name that show in browser tab like below screenshot.


Click next

You will redirect to installation summery screen like below.

you will got the congratulation screen that you have completed successfully on that screen.

Now click finish and it redirect you to login page. By default username is admin and passowrd is  zabbix
That's all Now you can add the client machine with  zabbix agent.

Permanent hostname setup for RHEL7

Step 1 Set the host name on NMTUI tool like following nmtui set host name   then save and exit Step 2 add the following l...