LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 07-19-2011, 12:59 AM   #1
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Rep: Reputation: 59
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
I have created a user (let's name it user_monitor) and added it to /etc/sudoers file by issuing "visudo" on all the servers.

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'
or

Code:
ssh user_monitor@appServer1 'ls -ltr /tmp'
I am still getting a prompt for password to continue the operation.

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`'
+ echo -e '\n----------------------------------\nChecking Services on Server: 10.196.5.49\n'
+ ssh user_monitor@10.196.5.49 /sbin/service apache2 status
Password:
service: only root can use service
What could be wrong? I have given sufficient permissions to user_monitor and have also shared its PK on the target server.

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
Defaults env_reset

#Defaults env_keep = "LANG LC_ADDRESS LC_CTYPE LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE LC_TIME LC_ALL LANGUAGE LINGUAS XDG_SESSION_COOKIE"
# Comment out the preceding line and uncomment the following one if you need
# to use special input methods. This may allow users to compromise  the root
# account if they are allowed to run commands without authentication.
Defaults env_keep = "LANG LC_ADDRESS LC_CTYPE LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE LC_TIME LC_ALL LANGUAGE LINGUAS XDG_SESSION_COOKIE XMODIFIERS GTK_IM_MODULE QT_IM_MODULE QT_IM_SWITCHER"

# In the default (unconfigured) configuration, sudo asks for the root password.
# This allows use of an ordinary user account for administration of a freshly
# installed system. When configuring sudo, delete the two
# following lines:
#Defaults targetpw   # ask for the password of the target user i.e. root
#ALL ALL=(ALL) ALL   # WARNING! Only use this together with 'Defaults targetpw'!

# Runas alias specification

# User privilege specification
root    ALL=(ALL) ALL
user_monitor       ALL=(ALL) NOPASSWD: ALL
Thanks,
Dev.
 
Old 07-19-2011, 01:11 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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'
 
Old 07-19-2011, 02:02 AM   #3
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
Quote:
Originally Posted by chrism01 View Post
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'

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`'
+ echo -e '\n----------------------------------\nChecking Services on Server: 10.196.5.20\n'
+ ssh user_monitor@10.196.5.20 sudo /sbin/service apache2 status
user_monitor@10.196.5.20's password:

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these two things:

        #1) Respect the privacy of others.
        #2) Think before you type.

Password:

apache2: unrecognized service
+ ssh user_monitor@10.196.5.20 sudo /sbin/service httpd status
user_monitor@10.196.5.20's password:
How to suppress the password prompt?

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.
 
Old 07-19-2011, 04:39 AM   #4
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
Okay, sudo and ssh are working now. But on some servers I am still getting password prompt.
 
Old 07-19-2011, 08:24 AM   #5
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ssh without prompting password siva balan Linux - Networking 1 09-28-2010 01:14 AM
problem disabling SSH password login on suse 11 dasy2k1 Linux - Security 1 09-25-2008 07:03 PM
ssh prompting password maooah Linux - Enterprise 4 12-05-2007 08:42 AM
ssh not prompting for password and thus not working quarry_06 Linux - Networking 2 12-14-2005 03:17 PM
Ssh without prompting for a password deqmacrom Linux - General 2 04-21-2005 02:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 08:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration