0
What I wanted to do is:
run a bash script from my local terminal, to run a jar file in an EC2 instance.
But in order to run the script, I'll have to first log in with .pem credentials, and then do su admin
and type admin password to gain run access. The command I've figured out so far is like this:
ssh -i ~/.ssh/my_credentials.pem -t ${EC2IP} 'su admin' "ADMIN_PASSWORD" 'cd /tmp' 'java -jar my-program.jar'
But it's still prompting me to type the ADMIN_PASSWORD, and then after that, my terminal will be logged into that EC2 machine, which is not what I wanted, I just want to finish all of the commands, and then continue with another EC2 instance.
How could I achieve that please? Thanks a lot!
Why are you using
su
here at all? It's much easier to configuresudo
for passwordless access, or configuring SSH to provide your private key direct access to the account you're trying tosu
to. – Charles Duffy – 2017-03-08T22:26:12.9171
You seem to assume that the strings you paste are supplied as standard input to
– tripleee – 2017-03-08T22:52:12.080ssh
but this is not at all the case. Maybe see also http://stackoverflow.com/questions/37586811/pass-commands-as-input-to-another-command-su-ssh-sh-etc1
This might help: Allow user1 to “su - user2” without password
– Cyrus – 2017-03-08T20:54:10.490