I'd like to execute some sudo privilege commands using bash script from local to remote server via ssh without passing multiple commands separating from semicolons on ssh. I've tried below step but got error.
ssh -t user@remoteip 'bash -s' < services.sh
Though I've used -t option here it still shows error message.
sudo: sorry, you must have a tty to run sudo
ssh -t
. The basic problems are (1) that you are not running a script, you are sourcing it, which is very different sometimes, and (2)sudo
will want to authenticate you, but your input is redirected to the script.ssh -tt
to force the tty allocation, but make sure that sudo will not ask for a password, if sudo ask for a password it will return control to the tty for password input and will fail there. If you can not set sudo without password your only option besides ansible or similar is to use expect and have your password in clear text which is not good at all.scp
and run them asssh remote-machine-name /bin/bash -x /path/to/copied/script/file