Pass multiple user input to ssh remote command

198 Views Asked by At

I'm trying to make a script that creates a ssh connection and executes a remote command which needs multiple user interactions. The remote script expects two passwords sequentially. One of another ssh connection and one for a git pull (ssh-)command.

Local script (run manually):

#!/bin/bash

echo -n "Password 1: "
read -s password_1
echo

echo -n "Password 2: "
read -s password_2
echo

result=$(ssh -t user@remote_host "/path/to/remote_script.bs" 2>&1 <<EOF
echo "$password_1"
echo "$password_2"
EOF
)

echo "$result"

Remote script (remote_script.bs):

# expects first password
ssh -M -S ".ssh_socket" -fNT "fixed_user@git_server" -L 1234:192.168.24.99:22
# expects seconds password; git is configured to pull via localhost portforwarding of ssh connection above
git --git-dir "path_to_git/.git" pull

The remote interactions ignore the echoed passwords and rush into a failed authentication.

Due to diverse environments I cant'use expect or sshpass.

0

There are 0 best solutions below