How do I execute a remote shell script over SSH and be prompted for passwords by commands that require it in that script?

I want to do something like this

ssh user@remote-domain.com ./remote_script.sh

Contents of remote_script.sh

#!/bin/bash
hg pull

This example is much simpler than what I am actually doing. I know I can pass shell commands directly over ssh, but assume I want to run a remote script. Also I know Mercurial has hooks, but ignore that as well, I am only using Mercurial as an example here for brevity.

This is what I expect to happen, a password prompt for the user:

user@repository-domain.com password: 

This is the output:

ssh user@remote-domain.com ./remote_script.sh
remote: Permission denied, please try again.
remote: Permission denied, please try again.
remote: Permission denied (publickey,password).
abort: no suitable response from remote hg!

The remote shell session seems to be feeding something to the password input prompts and failing after 3 automated tries. I would really like the prompt to reach my local shell session. Perhaps that isn’t possible.

I don’t want to give the remote server key authentication to the repository, I’d prefer the user be prompted each time. Is there any way to do this?

Answer

It’s hard to figure out what exactly is going on from this post. Is the password prompt being printed by the hg command (I’m not familiar with hg)?

I recommend you try adding the -t option to ssh:

ssh -t user@remote-domain.com ./remote_script.sh

Attribution
Source : Link , Question Author : Matthew Chambers , Answer Author : MadScientist

Leave a Comment