Using SSH to Check Services

1.25 hours
  • 8 Learning Objectives

About this Hands-on Lab

You need to connect to and perform a check on a client machine from the Nagios server. Due to your university’s firewall rules (port 5666 is not allowed for NRPE), you will need to use SSH. In this hands-on lab, we will configure an SSH check on a client and the Nagios server.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Generate SSH Keys for the nagios User
  1. On the Nagios server, become the nagios user.

    sudo su nagios
  2. Generate SSH keys for the nagios user.

Copy the Public Key from the Nagios Server to the Client
  1. Run the following command from the Nagios server:
    vim /home/nagios/.ssh/
  2. Select the SSH key, and copy it to your clipboard.
  3. On the client, open the authorized_keys file.
    sudo vim /home/cloud_user/.ssh/authorized_keys
  4. Paste the SSH key at the end of the file, then save and exit.
Test the SSH Connection
  1. From the Nagios server, run the following command:
    ssh cloud_user@CLIENT_IP
Copy the check_disk Binaries from the Nagios Server to the Client
  1. Run the following command from the Nagios server:
    sudo -i scp /usr/local/nagios/libexec/check_disk cloud_user@CLIENT_IP:/home/cloud_user/
Define an SSH Check Command Object on the Nagios Server
  1. From the Nagios server, change to the /usr/local/nagios/etc/objects/ directory.
    cd /usr/local/nagios/etc/objects/
  2. Open the commands.cfg file.
    sudo vim commands.cfg
  3. Add the following to the file:

    define command {
       command_name    ssh_check_disk
       command_line    /usr/local/nagios/libexec/check_by_ssh -H $HOSTADDRESS$ -i /home/nagios/.ssh/id_rsa -l cloud_user -C "/home/cloud_user/check_disk -w 10% -c 5% -p /"
Create the Host, Host Group, and Service Object Definitions
  1. Create a new file named linux-server.cfg in the /usr/local/nagios/etc/objects/ directory.
    sudo touch /usr/local/nagios/etc/objects/linux-server.cfg
  2. Open the file.
    sudo vim /usr/local/nagios/etc/objects/linux-server.cfg
  3. Add the following to the file:

    define host {
       use                     linux-server
       host_name               Linux Server
       alias                   linuxSrv
       address                 CLIENT_IP
    define hostgroup {
       hostgroup_name          my-linux-servers
       alias                   Linux Servers
       members                 Linux Server
    define service {
       use                     generic-service
       host_name               Linux Server
       service_description     Check DISK
       check_command           ssh_check_disk
Inform Nagios of the New File, Perform a Preflight Check, and Restart Nagios
  1. Run the following command:
    sudo vim /usr/local/nagios/etc/nagios.cfg
  2. Add the following to the file:
    Definitions for monitoring a network printer
  3. Save and exit the file.
  4. Run a preflight check.
    sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
  5. Restart Nagios.
    sudo systemctl restart nagios
  6. Check the status of Nagios.
    sudo systemctl status nagios
Log In to the Nagios Web Interface and Reschedule a Check for the Check DISK Service
  1. In a private browser tab, navigate to http://NAGIOS_SERVER_IP/nagios.
  2. Log in with the following credentials:
    • User Name: nagiosadmin
    • Password: BlaBla321
  3. Click Services > Check DISK.
  4. Under Service Commands, click Re-schedule the next check of this service.
  5. Next to Check Time, enter a time approximately 10-20 seconds from now (you can check the current time using the date command in your terminal window).
  6. Click Commit, then Done.
  7. Click Services in the left sidebar.
  8. Verify that there are no errors for the Check DISK service under Status Information.

Additional Resources

  • Log in to the Nagios server via SSH, and configure key-based authentication between the Nagios server and the client. Then, define a command in commands.cfg that will conduct a disk check via SSH.
  • Create the host, hostgroup, and service object definitions, and create a new file to store them.
  • After everything has been configured, log in to the Nagios server web interface, and reschedule a check for the service that you defined. Then verify that it works.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?