Friday, May 25, 2018

how to force user to change their password on next login in linux ?


Method 1:
To force a user to change his/her password, first of all the password must have expired and to cause a user’s password to expire, you can use the passwd command, which is used to change a user’s password by specifying the -e or --expire switch along with username as shown.
#passwd --expire ravi
#chage -l ravi
Last password change                                                           : password must be changed
Password expires                                                                    : password must be changed
Password inactive                                                                   : password must be changed
Account expires                                                                       : never
Minimum number of days between password change    : 0
Maximum number of days between password change    : 99999
Number of days of warning before password expires       : 7
After running the passwd command above, you can see from the output of thechage command that the user’s password must be changed. Once the userravi tries to login next time, he will be prompted to change his password before he can access a shell .
Method 2:
Using chage command:
chage command – Change user password expiry information
Use the following syntax to force a user to change their password at next logon on a Linux:
# chage -d 0 user-name
In this example, force ravi to change his password at next logon, enter:
# chage -d 0 ravi
  • -d 0 : Set the number of days since January 1st, 1970 when the password was last changed. The date may also be expressed in the format YYYY-MM-DD. By setting it to zero, you are going to force user to change password upon first login.


Friday, March 16, 2018

how to check physical network cable connection status on linux ?

Method 1

Using dmesg

Using dmesg is one of the 1st things to do for inquiring current state of system:

Example:

dmesg | sed '/eth.*Link is/h;${x;p};d'
[1667676.292871] e1000e: eth0 NIC Link is Up 100 Mbps Full Duplex, Flow Control: Rx/Tx

Method 2

/sys/class/net/

cat /sys/class/net/eth0/carrier
1

The number 1 in the above output means that the network cable is connection physically
to your's network card slot.

Or

cat /sys/class/net/eth0/operstate
up


Method 3

Using ethtool command

Syantax : ethtool interface_name | grep Link\ d

Example:

ethtool eth0 | grep Link\ d

Link detected: yes

we can use bash for loop again to check all network interfaces it once:

for i in $( ls /sys/class/net ); do echo -n $i; ethtool $i | grep Link\ d; done

Sample output:

eth0 Link detected: yes
eth1 Link detected: no
lo Link detected: yes
wlan0 Link detected: no

NOTE:

The only problem with the above ethtool output is that it will not detect connected
cable if your network interface is down. Consider a following example:
# ethtool eth0 | grep Link\ d
       Link detected: yes
# ifconfig eth0 down
# ethtool eth0 | grep Link\ d
       Link detected: no
# ifconfig eth0 up
# ethtool eth0 | grep Link\ d
       Link detected: yes



Tuesday, February 27, 2018

How to tune the NIC Ring Buffers (RX,TX) on network interface ?


Modern and performance/server grade network interface have the capability of using transmit and receive buffer description ring into the main memory. They use direct memory access (DMA) to transfer packets from the main memory to carry packets independently from the CPU.
The usual default buffering values for regular desktop NICs are 256 or 512 bytes. High performances NICs can achieve up to 4096 and/or 8192 bytes.
To view the capability and the current values of your interface, you’ll need “ethtool”. Simply do the following command :
ethtool -g interfacename
           g  --show-ring
ethtool -g eth0

This will output something like this :

ethtool -g eth0
Ring parameters for eth0:
Pre-set maximums:
RX: 4096
RX Mini: 0
RX Jumbo: 0
TX: 4096
Current hardware settings:
RX: 256
RX Mini: 0
RX Jumbo: 0
TX: 256

Here we have two sections in our output. The first section is “Pre-set maximums” which tells us the maximum values that could be set for each available parameter. The second section shows us to what each parameter is currently set. We are most interested in the top most parameter labeled simply “RX” which is our receive ring buffer.
Buffers are generally tuned small for latency reasons. The smaller the buffer the lower the latency. But low latency comes at a price and that price is maximum throughput. For greater throughput we need a larger buffer. Factory defaults are good, generally, for most systems but don’t be afraid to tune this for your own scenario.


We can see here that both RX and TX values are set to 256 but the interface have the capability of 4096 bytes.
To increase the buffers, do the following :
ethtool -G|--set-ring devname [rx N] [rx-mini N] [rx-jumbo N] [tx N]
ethtool -G eth0 rx 4096 tx 4096

This will output something like this :

ethtool -g eth0
Ring parameters for eth0:
Pre-set maximums:
RX: 4096
RX Mini: 0
RX Jumbo: 0
TX: 4096
Current hardware settings:
RX: 4096
RX Mini: 0
RX Jumbo: 0
TX: 4096





Thursday, February 22, 2018

what is the difference between zabbix passive checks & active checks ?

Zabbix agents support both passive (polling) and active checks (trapping). Zabbix may perform checks based on an interval, however, it is also possible to schedule specific times for item polling.

Passive checks (polling):

  • Zabbix server (or proxy) requests a value from Zabbix agent
  • Agent processes the request and returns the value to Zabbix server (or proxy)
Zabbix server or proxy asks for some data (for example, CPU load) and Zabbix agent sends back the result to the server.
Example: agent ping
  1. Server opens a TCP connection
  2. Server sends agent.ping\n
  3. Agent reads the request and response with <HEADER><DATALEN>1
  4. Server processes data to get the value, ‘1’ in our case
  5. TCP connection is closed
Active checks (trapping):
  • Zabbix agent requests from Zabbix server (or proxy) a list of active checks
  • Agent sends the results in periodically

Active checks require more complex processing. The agent must first retrieve from the server(s) a list of items for independent processing.

For example:
  1. Agent opens a TCP connection
  2. Agent asks for the list of checks
  3. Server responds with a list of items (item key, delay)
  4. Agent parses the response
  5. TCP connection is closed
  6. Agent starts periodical collection of data

Zabbix Trapper

Trapper items accept incoming data instead of querying for it.It is useful for any data you might want to “push” into Zabbix.

To use a trapper item you must:

  1. have a trapper item set up in Zabbix
  2. send in the data into Zabbix(with zabbix_sender)

How to install zabbix agent on windows ?


Zabbix Agent is installed on remote systems needs to monitor through Zabbix server. The Zabbix agent collects resource utilization and applications data on client system and provide such information to zabbix server on their requests.
install Zabbix agent service on windows system
Step 1 – Download Agent Source Code

Download latest windows zabbix agent source code from zabbix official site or use below link to download zabbix agent 3.0.0.
After downloading the zipped archive of zabbix client, extract its content under c:\zabbix directory.
Step 2 – Create Agent Configuration File
Now make of copy of sample configuration file c:\zabbix\conf\zabbix_agentd.win.conf to create zabbix agent configuration file at c:\zabbix\zabbix_agentd.conf. Now edit configuration and update following values.
#Server=[zabbix server ip]
#Hostname=[Hostname of client system ]

Server=192.168.1.26
Serveractive=192.168.1.26
Hostname=linuxforfreshers.com
Step 3: Install Zabbix Agent as Windows Service
Lets install zabbix agent as windows server by executing following command from command line.
c:\zabbix\bin\win64> zabbix_agentd.exe -c c:\zabbix\zabbix_agentd.conf --install

zabbix_agentd.exe [9084]: service [Zabbix Agent] installed successfully
zabbix_agentd.exe [9084]: event source [Zabbix Agent] installed successfully
Step 4 – Start/Stop Agent Service
Use following command to start zabbix agent service from command line
c:\zabbix\bin\win64> zabbix_agentd.exe --start

zabbix_agentd.exe [7048]: service [Zabbix Agent] started successfully
c:\zabbix\bin\win64> zabbix_agentd.exe --stop

zabbix_agentd.exe [9608]: service [Zabbix Agent] stopped successfully
Uninstalling agent
c:\zabbix\bin\win64> zabbix_agentd.exe -c c:\zabbix\zabbix_agentd.conf --uninstall