0

I am using ssh to connect to remote server from local.

[siebel@local ~]$ ssh remote

siebel@remote password:

I dont want to input the password manually. I want to write a script in which I will give the password as an input. It will enable me to login without manual action.

I don't want to setup passwordless authentication by ssh-keygen. I tried to use expect but spawn is not working. I don't want to install any other utility also.

  • 1
    it is strongly discouraged to hardcode passwords like this – Inder Aug 06 '18 at 05:23
  • Possible duplicate of [Shell script to automate SSH login using password](https://stackoverflow.com/questions/43526330/shell-script-to-automate-ssh-login-using-password) – Kenster Aug 06 '18 at 13:13

1 Answers1

1

As I said its strongly discouraged to hardcode passwords for security reasons but what I will suggest, only if you just can't avoid doing it. is to use sshpass.

You can easily do a:

sudo apt install sshpass

following that the following simple command will do the trick for you.

sshpass -p "PASSWORD" ssh -o StrictHostKeyChecking=no USERNAME@REMOTE_HOST:Custom port number(default is 22)
Inder
  • 3,711
  • 9
  • 27
  • 42
  • I don't want to install a utility. I want to do it using a script. – Prithhish Bal Aug 06 '18 at 06:18
  • I am afraid you will anyways have to install a utility if not sshpass then except etc – Inder Aug 06 '18 at 08:33
  • what you can try to do is mimic what sshpass is doing but u will still need to add utilities for that – Inder Aug 06 '18 at 08:34
  • I am trying to build a tool which is using the ssh. And this tool may be used by different people on different types of Linux. I don't want them t o install one utility as a pre-requisite. I am fine to mimic what sshpass does. Does anyone know how sshpass works? – Prithhish Bal Aug 06 '18 at 13:54