Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon

Using SSH to Check Services

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.

Google Cloud Platform icon

Path Info

Clock icon Intermediate
Clock icon 1h 15m
Clock icon Jul 19, 2019

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Generate SSH Keys for the nagios User

    1. On the Nagios server, become the nagios user.
    sudo su nagios
    1. Generate SSH keys for the nagios user.
  2. Challenge

    Copy the Public Key from the Nagios Server to the Client

    1. Run the following command from the Nagios server:
    vim /home/nagios/.ssh/
    1. Select the SSH key, and copy it to your clipboard.
    2. On the client, open the authorized_keys file.
    sudo vim /home/cloud_user/.ssh/authorized_keys
    1. Paste the SSH key at the end of the file, then save and exit.
  3. Challenge

    Test the SSH Connection

    1. From the Nagios server, run the following command:
    ssh cloud_user@CLIENT_IP
  4. Challenge

    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/
  5. Challenge

    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/
    1. Open the commands.cfg file.
    sudo vim commands.cfg
    1. 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 /"
  6. Challenge

    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
    1. Open the file.
    sudo vim /usr/local/nagios/etc/objects/linux-server.cfg
    1. 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
  7. Challenge

    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
    1. Add the following to the file:
    Definitions for monitoring a network printer
    1. Save and exit the file.
    2. Run a preflight check.
    sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
    1. Restart Nagios.
    sudo systemctl restart nagios
    1. Check the status of Nagios.
    sudo systemctl status nagios
  8. Challenge

    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.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

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.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans