在客戶端編寫的一個腳本check_ssh_auto.shios
#!/bin/bashbash
a=`/bin/cat /etc/ssh/sshd_config | grep PasswordAuthentication | grep -v "^#" | awk '{print $2}'`服務器
if [ "$a" = "yes" ]; thenssh
echo "SSH authentication: WARNING Please amend the warning SSH authentication for key authentication;"ide
$(exit 1)測試
elseui
echo "SSH authentication: OK;"spa
$(exit 0)it
fiio
客戶端執行正常
nagios服務器測試執行
/usr/local/nagios/libexec/check_nrpe -H 192.168.10.1 -c ssh_auth
提示NRPE: Unable to read output
解決方法
在客戶端修改文件
vi /etc/sudoers
注視這行
#Defaults requiretty
在root ALL=(ALL) ALL下面添加一行
nagios ALL=(ALL) NOPASSWD:/usr/local/nagios/libexec/*
修改nrpe配置文件/usr/local/nagios/etc/nrpe.cfg
command[ssh_auth]=/usr/bin/sudo /usr/local/nagios/libexec/check_ssh_auth.sh
重啓nrpe
服務器端再次測試
SSH authentication: OK;