Shell – How to use SSH to run a shell script on a remote machine

linuxscriptingshell-scriptsshsudo

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

Best Answer

This can occur when Defaults requiretty is uncommented in /etc/sudoers.

The fix is to comment that line:

#Defaults    requiretty

Remember to only edit /etc/sudoers using the visudo** command.

**The visudo command may only be run by the root user.

Related Question