-1

This is to follow up on this thread: Automatically enter SSH password with script

In my case, i cannot use sshpass, i cannot use expect, I just need to script it as if no other packages are installed on the end user machine.

I want to ssh through a shell script and expand the password but it does not work.

So, using a shell script, let's say I create those variables:

_USER='Joebloe'
_MACHINE='1.1.1.1'
_PASSWORD='Password'

Then, the goal is just to ssh and pass the password:

ssh $(echo $_USER)@$(echo $_MACHINE)  ##That works fine

Then, it prompts for the password:

Joebloe Password:

But I cannot say echo $_PASSWORD or even $(echo $_PASSWORD) because it takes the values literally.

Is there a way to expand the password as soon as you type it, or before it is processed, or it is not doable through a shell script?

Thanks a lot

  • You should set up public-key authentication, which does not require any additional software, just a one-time login with the password. – chepner Mar 17 '23 at 20:41
  • The fact that `ssh` only reads passwords from the terminal, not from a file or standard input, is a *feature*, to prevent password leaks. – chepner Mar 17 '23 at 20:43
  • `ssh`is reading a literal password directly, not via a shell that can process your input before `ssh` sees it. – chepner Mar 17 '23 at 20:44

1 Answers1

0

You can use the sshpass, but this is a bad decision. It is better to use key-based authorization.

But if you are confident in your actions there is example:

Install sshpass:

Debian-based (Ubuntu): $ apt-get install sshpass

Fedora/CentOS: $ yum install sshpass

Arch-based: $ pacman -S sshpass

$ sshpass -p $(echo $_PASSWORD) ssh $(echo $_USER)@$(echo $_MACHINE)