Test SSH but do not return password prompt


 
Thread Tools Search this Thread
Top Forums Programming Test SSH but do not return password prompt
# 1  
Old 05-01-2012
Test SSH but do not return password prompt

Hello forum,

I want to have a function to test for passwordless SSH setup. Pretty simple. However, what I'm finding difficult is to NOT return a password prompt to screen IF it's not in place.

Here's the function:

Code:
check_passwordless_ssh_working()
#check passed parameter, assuming it is a hostname, to see if SSH works to that host
{
hostname=${1}
passwordless_ssh_whoami=$(ssh -q $hostname whoami)
 
local_whoami=$(whoami)
 
if [[ $passwordless_ssh_whoami = $local_whoami ]] ; then
  passwordless_ssh_working=1
  echo "SSH_working._SSH_response:_$passwordless_ssh_whoami._Local_response:_$local_whoami" $passwordless_ssh_working
else
  passwordless_ssh_working=0
  echo "SSH_NOT_working._SSH_response:_$passwordless_ssh_whoami._Local_response:_$local_whoami" $passwordless_ssh_working
fi
}

It will return the correct string and integer either way, however if the SSH command does not utilise a passwordless (key pair) SSH setup, then it prompts for the target user's password - you have to get it wrong 3 times to make it fail. I want it to just auto-fail here rather than prompting for a password - any idea how I can do this?
# 2  
Old 05-01-2012
There are options to only allow public key auth. Use those options and test for success.

Code:
    if ssh -o BatchMode=yes "$hostname" true 2>/dev/null; then
        echo "it works"
    else
        echo "it's broken."
    if

This User Gave Thanks to neutronscott For This Post:
# 3  
Old 05-01-2012
You can disallow ChallengeResponseAuthentication in ssh_config or ssd_config on the server you should default to key based auth only
This User Gave Thanks to Skrynesaver For This Post:
# 4  
Old 05-08-2012
FOLLOW UP:

FYI Have now tested code and implemented a change following NeutronScott's tip. See working function:

Code:
check_passwordless_ssh_working()
#check passed parameter, assuming it is a hostname, to see if SSH works to that host
{
hostname=${1}
passwordless_ssh_whoami=$(ssh -q -o BatchMode=yes $hostname whoami)
 
local_whoami=$(whoami)
 
if [[ $passwordless_ssh_whoami = $local_whoami ]] ; then
  passwordless_ssh_working=1
  echo "SSH_working._SSH_response:_$passwordless_ssh_whoami._Local_response:_$local_whoami" $passwordless_ssh_working
else
  passwordless_ssh_working=0
  echo "SSH_NOT_working._SSH_response:_$passwordless_ssh_whoami._Local_response:_$local_whoami" $passwordless_ssh_working
fi
}

The simple addition of the BatchMode option (-o) has allowed us to capture the fact that passwordless SSH isn't working, without prompting for a password.

---------- Post updated at 14:20 ---------- Previous update was at 14:18 ----------

NB Notice I return values in a string using echo. As this is a standard return I can then read them as if in an array, using awk to print $1 and $2. $1 showing the text response and $2 showing the numeric response. This is the reason the text all has underscores and no spaces (so it is auto-read as a single field/entry).
This User Gave Thanks to doonan_79 For This Post:
# 5  
Old 05-08-2012
You could also use a non-space separator, i.e. -F":" but that makes sense.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass password and prompt user for IP address while doing ssh and scp?

Hi All, I want to copy /.ssh/OM.pub file from source to destination. Here source IP address, username and password is always fixed. Whereas destination server IP address, password always gets changed. From destination server :- I am trying to write a script in which it should log in to... (3 Replies)
Discussion started by: madhur.baharani
3 Replies

2. Red Hat

Sudo Password Prompt over SSH

I am not sure what I am missing here. I have the following identical entry in /etc/sudoers on multiple Red Hat 6.4 servers. icinga ALL=NOPASSWD:/usr/bin/yum --security --exclude\="kernel*" check-update On one server when I enter the command over SSH as follows it works fine. ssh -t -q... (1 Reply)
Discussion started by: scotbuff
1 Replies

3. SuSE

SLES 11.2 slow SSH password prompt

We are having an issue with slow password prompts via SSH login on all of our SLES 11.2 boxes. The output from a ssh -v login attempt shows a delay here: debug1: SSH2_MSG_SERVICE_ACCEPT receivedThis issue only happens on the first logon of the day; subsequent logons are normal. Adding the client's... (8 Replies)
Discussion started by: j_aix
8 Replies

4. AIX

ssh keys - no password prompt from AIX to RPA

hello, i am running an AIX 5.3 machine and i want to connect via ssh to the RPA Management site without prompting for password. i already had a public key of this server as i use the same thing for ssh connection with other AIX machines. i connected to the RPA Management Site and i run the... (9 Replies)
Discussion started by: omonoiatis9
9 Replies

5. Solaris

expired password prompt at ssh login

Hi, I am using DSEE 6.3 to authenticate and authorize my Solaris 9 and 10 users. Everything works fine except password expiration. I use built-in global password policy for all users. The policy works well. However I could not find the right pam configuration in order to prompt users at ssh... (2 Replies)
Discussion started by: niyazi
2 Replies

6. UNIX for Dummies Questions & Answers

SSH version of rlogin (ie without password prompt)

I have 3 Solaris 10 UNIX servers, the shadow and passwd file are all identical and are automatically sync every 5 minutes. A majority of the users do not have CLI access but rather use a menu. I currently have menu options that allows them to rlogin to another server and I need to have the... (1 Reply)
Discussion started by: creedonjm
1 Replies

7. Linux

SSH user equivalency still prompt for password

Hi All, I've followed the exact same steps of how to setup and enable SSH user equivalent including the right permission, but when I "ssh" it still prompts for password. Could you help to see what I did wrong? I appreciate any helps. :confused: server1.com:/u01/oracle RAC1 > mkdir... (2 Replies)
Discussion started by: Beginer0705
2 Replies

8. Shell Programming and Scripting

script submitted using ssh does not return to command prompt

Gurus, I have written a shell script to backup a database and applications. This is how the script works: 1. As applications user (say applmgr), the main backup script, say backup.sh, is kicked off. 2. backup.sh does ssh to oracle user and kicks off the database backup using nohup and... (1 Reply)
Discussion started by: sunpraveen
1 Replies

9. Solaris

ssh Long time to return prompt.

Hi All, I was installed new server M5000 on solaris10. I'am try to connect to server by ssh client (putty) after type user name and password the server take long time to return prompt to me about 30-60 second. any body can suggess me how to do it. (8 Replies)
Discussion started by: cesmk
8 Replies

10. UNIX and Linux Applications

SSH: Avoiding password prompt with rsa key generation

Hi, I am using a remote storage service for backing up our data - we want to have a script run as part of a cron job which would do the backups from our local Linux machine to the service's Linux machine. I want to use tar and ssh to do this (rather than mounting the disk and using cp) .... (5 Replies)
Discussion started by: same1290
5 Replies
Login or Register to Ask a Question