Disabling of ssh Prompting for Password
Hi,
There are over a dozen of servers that I need to monitor for services running on them. Hence, I have created a separate VM on which I am hosting scripts for various purposes. I have written a script (bash) that checks the status of the services running on those servers. Since my script has this line of command (for example): Code:
/sbin/service vsftpd status Since I need to execute the command remotely from the VM so I have generated a Public RSA Key (ssh-heygen) and added it to "authorized_keys" file on all the servers. But on some servers when issue a command such as the following: Code:
ssh user_monitor@appServer1 '/sbin/service vsftpd status' Code:
ssh user_monitor@appServer1 'ls -ltr /tmp' Whereas, on some other servers I get this error (an excerpt from the sample run of the script): Code:
+ for SERVER in '`cat $INPUT_FILE`' So, how to bypass the password prompt when I am issuing the command (ssh ...) as given above? Here are the visudoers' contents: Code:
Defaults always_set_home Dev. |
1. consider using a monitoring tool like Nagios instead of rolling your own if you've got that many systems
2. assuming you are ssh-ing as user_monitor and NOT root (I hope), you will need to use 'sudo' to tell the remote end to check/use the sudoers file for privileged access eg Code:
ssh user_monitor@appServer1 'sudo /sbin/service vsftpd status' |
Quote:
Thanks for the minor mistake of leaving out "sudo" prefix from the command. I knew it but just forgot to type it in there. Thanks a lot for observing it. So, here is the sample run of the script again: Code:
+ for SERVER in '`cat $INPUT_FILE`' Your recommendation for the depoloyment of Nagios or any other such tools is okay but I am not supposed or authorised to do that on my own. It is my job to write scripts and I want to do these automations to prove my worth as well. ;) |
Okay, sudo and ssh are working now. But on some servers I am still getting password prompt.
|
I have found the solution. My senior colleague just figured it out that the permissons of the directory ".ssh" and of the file "authorized_keys" were not properly set. I set them to 700 and 600 respectively and things worked fine.
|
All times are GMT -5. The time now is 04:17 AM. |