Find the answer to your Linux question:
Results 1 to 5 of 5
Hi All, I have shell script that connect to remote machine via password less SSH. So I need to do base validation whether password less ssh available or not between ...
  1. #1
    Just Joined!
    Join Date
    Nov 2010
    Posts
    23

    Validate password-less SSH between two remote machine

    Hi All,

    I have shell script that connect to remote machine via password less SSH. So I need to do base validation whether password less ssh available or not between two machines. can anyone suggest some way to do this..?


  2. #2
    Trusted Penguin Roxoff's Avatar
    Join Date
    Aug 2005
    Location
    Nottingham, England
    Posts
    3,393
    Use PKI, generate an encryption key-pair with 'ssh-keygen' (make sure you use 2048 or bigger keys if possible), and copy the keys to the machine you're connecting from and the server. Then use that key in the login, you can specify the key on the command line, or you can put it into the .ssh directory for the user who the connection is taking place as. There's a more detailed description of the process here.
    Linux user #126863 - see http://linuxcounter.net/

  3. #3
    Just Joined!
    Join Date
    Nov 2010
    Posts
    23
    Thanks for the Quick reply,,

    But I already have passwd-less SSH and what I need is shell script to validate it, If I use my script on machine that haven't passwd-less ssh script it self should check and say that you haven't passwd-less SSH between your machines, otherwise it's should prompt "OK you have passwd-less SSH so you can proceed."

  4. #4
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    You can try using the command:
    Code:
    ssh -o PasswordAuthentication=no remote.host
    By disabling password authentication, if you don't have passwordless SSH set up, the command will fail. Here is an example trying to log into my old university's computer lab:
    Code:
    $ ssh cabhan@login.ccs.neu.edu
    cabhan@login.ccs.neu.edu's password:
    
    $ ssh -o PasswordAuthentication=no cabhan@login.ccs.neu.edu
    Permission denied (publickey,password).
    DISTRO=Arch
    Registered Linux User #388732

  5. #5
    Linux Guru
    Join Date
    May 2011
    Posts
    1,843
    What cabhan has suggested is exactly what I do. That last piece I add is a remote command to run that always returns success and then evaluate the exit status of the ssh command (which if keys are working is success or '0', and if the keys are not working is failure, or not '0'):
    Code:
    /usr/bin/ssh -o PasswordAuthentication=no 192.168.1.1 /bin/true
    if [ $? -eq 0 ]; then
      echo SSH keys have been set up
    else
      echo SSH keys have NOT been set up yet
    fi
    Edit: the failure exit code is not necessarily 1, it is usually 255, but might be some other non-zero number
    Last edited by atreyu; 01-20-2012 at 05:47 AM. Reason: failure exit status

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...