Page 2 of 6

Re: Check_by_ssh issue

Posted: Wed Aug 24, 2016 11:36 am
by lmiltchev
command_line /usr/local/nagios/libexec/check_by_ssh -i /home/nagios/.ssh/id_dsa -H '$HOSTADDRESS$' -E 1 -C "/usr/lib/nagios/plugins/check_disk -w $ARG1$ -c $ARG2$ -e -p '$ARG3$'"
I believe you are missing the "identity" file in the "/home/nagios/.ssh" directory on the remote server.
nagios@remoteserver:~$ ls -la /home/nagios/.ssh
total 12
drwx------ 2 nagios nagios 4096 May 3 16:36 .
drwxr-xr-x 4 nagios nagios 4096 May 3 16:37 ..
-rw------- 1 nagios nagios 604 May 3 16:36 authorized_keys
I ran a "similar" command, and it is working for me whether or not I am connected to the remote box via ssh session. Here's what I have on the remote machine:

Code: Select all

[root@192 ~]# ls -la /home/nagios/.ssh/
total 20
dr-xr-xr-x  2 nagios nagios 4096 Nov  9  2015 .
dr-xr-xr-x. 5 nagios nagios 4096 Nov  9  2015 ..
-rw-------  1 nagios nagios  410 Apr 13 10:49 authorized_keys
-rw-------  1 nagios nagios 1671 Nov  9  2015 id_rsa
-rw-r--r--  1 nagios nagios  410 Nov  9  2015 id_rsa.pub
and here's my command run on the nagios server along with the output:

Code: Select all

[nagios@localhost root]$ /usr/local/nagios/libexec/check_by_ssh -H x.x.x.x -i /home/nagios/.ssh/id_rsa -E 1 -C "/usr/local/nagios/libexec/check_disk /"
DISK OK - free space: / 3109 MB (32% inode=82%);| /=6405MB;;;0;9612

Re: Check_by_ssh issue

Posted: Thu Aug 25, 2016 5:06 am
by MarMottE
I have added the ida_dsa key on my remote server but it's not very secure to have the private key localy on the remote server.

But I have the same problem, when i'm closing my ssh connection the check goes down.

And from my server without the private key on the remote server the check is working

nagios@:~$ /usr/local/nagios/libexec/check_by_ssh -i /home/nagios/.ssh/id_dsa -H xxxx -E 1 -C "/usr/lib/nagios/plugins/check_disk /"
DISK OK - free space: / 7582 MB (63% inode=77%);| /=4437MB;;;0;12687


root@remoteserver:/home/nagios# cd /home/nagios/.ssh/
root@remoteserver:/home/nagios/.ssh# ls -la
total 12
drwx------ 2 nagios nagios 4096 Aug 25 11:59 .
drwxr-xr-x 4 nagios nagios 4096 May 3 16:37 ..
-rw------- 1 nagios nagios 604 May 3 16:36 authorized_keys


I think it's not a problem of ssh because my check is working when I'm connected on the server by SSH, SCP or console, but when i'm closing the session those check goes down ...

Re: Check_by_ssh issue

Posted: Thu Aug 25, 2016 4:19 pm
by ssax
Please attach your /etc/ssh/sshd_config so that we may review it.

Thank you

Re: Check_by_ssh issue

Posted: Fri Aug 26, 2016 1:31 am
by MarMottE
Please find bellow the sshd_config

cat /etc/ssh/sshd_config

Code: Select all

# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 1024

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
PermitRootLogin without-password
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile     %h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

Subsystem sftp /usr/lib/openssh/sftp-server

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes

Re: Check_by_ssh issue

Posted: Fri Aug 26, 2016 2:06 pm
by tgriep
The check_by_ssh is using a passwordless ssh session to connect to that host and this setting in the sshd_config may be causing that to fail.
Try changing it to yes and see if that helps.

Code: Select all

PermitEmptyPasswords no
Also, to you see and errors on the remote systems log files?

Re: Check_by_ssh issue

Posted: Mon Aug 29, 2016 1:18 am
by MarMottE
tgriep wrote:The check_by_ssh is using a passwordless ssh session to connect to that host and this setting in the sshd_config may be causing that to fail.
Try changing it to yes and see if that helps.

Code: Select all

PermitEmptyPasswords no
No, same problem when i'm closing my ssh session

Re: Check_by_ssh issue

Posted: Mon Aug 29, 2016 10:33 am
by tgriep
Can you run the following commands on the XI server and post the output here while you are not connected to the remote host?

Code: Select all

su nagios
ssh -v nagios@remoteip
Replace remoteip with the IP address of the system you are trying to monitor.

Re: Check_by_ssh issue

Posted: Tue Aug 30, 2016 1:31 am
by MarMottE
Please find bellow the output


root@:/home/nagios# su nagios
nagios@:~$ ssh -v nagios@xxxx
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to xxxx [xxxx] port 22.
debug1: Connection established.
debug1: identity file /home/nagios/.ssh/id_rsa type -1
debug1: identity file /home/nagios/.ssh/id_rsa-cert type -1
debug1: identity file /home/nagios/.ssh/id_dsa type 2
debug1: identity file /home/nagios/.ssh/id_dsa-cert type -1
debug1: identity file /home/nagios/.ssh/id_ecdsa type -1
debug1: identity file /home/nagios/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/nagios/.ssh/id_ed25519 type -1
debug1: identity file /home/nagios/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.7
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.7
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.7 pat OpenSSH_6.6.1* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr [email protected] none
debug1: kex: client->server aes128-ctr [email protected] none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: RSA xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
debug1: Host 'xxxx' is known and matches the RSA host key.
debug1: Found key in /home/nagios/.ssh/known_hosts:10
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /home/nagios/.ssh/id_rsa
debug1: Offering DSA public key: /home/nagios/.ssh/id_dsa
debug1: Server accepts key: pkalg ssh-dss blen 433
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type DSA
debug1: Authentication succeeded (publickey).
Authenticated to xxxx ([xxxx]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 4.2.0-42-generic x86_64)

* Documentation: https://help.ubuntu.com/

System information as of Tue Aug 30 08:29:44 CEST 2016

System load: 0.42 Processes: 182
Usage of /: 34.9% of 12.39GB Users logged in: 0
Memory usage: 29% IP address for eth0: 10.10.29.34
Swap usage: 5%

Graph this data and manage this system at:
https://landscape.canonical.com/

New release '16.04.1 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Last login: Wed Aug 24 08:27:20 2016 from 10.10.5.20
nagios@:~$

Re: Check_by_ssh issue

Posted: Tue Aug 30, 2016 9:55 am
by tgriep
I am thinking that the error is the printing of the message of the day or the banner when you login to the remote system.
Your sshd_config file is setup to not show it but it is there and if you can shut that off, that should fix it for you.

Re: Check_by_ssh issue

Posted: Tue Aug 30, 2016 4:41 pm
by Box293
tgriep wrote:I am thinking that the error is the printing of the message of the day or the banner when you login to the remote system.
Adding -E 1 to the check_by_ssh command will ignore the first line of output.