• Uncategorized

About ssh : Shell-script-to-automate-SSH-login-using-password

Question Detail

I am trying to automate SSH login by using password. I can’t use expect command or sshpass etc. So I am left with only option to use password directly.
Did lot of research in google and didn’t get any solution… 🙁

Please help me with this.

The code I tried is.

#!/bin/bash
USERNAME=user1
PASSWORD=abcd1234
HOSTS="server01.mat.us"
ssh ${HOSTS} -l ${USERNAME} -p ${PASSWORD}

Question Answer

The OpenSSH ssh utility doesn’t accept a password on the command line or on its standard input. This also applies to the scp and sftp file transfer utilities, which invoke ssh to make the SSH connection. I believe this is a deliberate decision on the part of the OpenSSH developers. You have these options available to you:

  1. Use an SSH key for authentication, instead of a password.
  2. Use sshpass, expect, or a similar tool to invoke ssh through a TTY and automate responding to the password prompt.
  3. Use (abuse) the SSH_ASKPASS feature to get ssh to get the password by running another program, described here or here, or in some of the answers here.
  4. Get the SSH server administrator to enable host-based authentication and use that. Note that host-based authentication is only suitable for certain network environments. See additional notes here and here.
  5. Write your own ssh client using perl, python, java, or your favorite language. There are ssh client libraries available for most modern programming languages, and you’d have full control over how the client gets the password.
  6. Download the ssh source code and build a modified version of ssh that works the way you want.
  7. Use a different ssh client. There are other ssh clients available, both free and commercial. One of them might suit your needs better than the OpenSSH client.

I’d recommend to use ssh keys instead of password if it’s possible.

This script can help you to upload your public key to desired remote machine:

https://github.com/aprey10/ssh-authorizer

You may also like...

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.