Skip to content

Instantly share code, notes, and snippets.

@ileathan
Last active January 29, 2018 00:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ileathan/e10ce11f4788d6c67e76e5d928909d75 to your computer and use it in GitHub Desktop.
Save ileathan/e10ce11f4788d6c67e76e5d928909d75 to your computer and use it in GitHub Desktop.
Run sudo command on remote machine non-interactively
#!/bin/bash
# USAGE:
# ./remote-sudo.sh password hostname command
HOST=$2;
PASSWORD=$1;
COMMAND="${@:3}"
ssh -T $HOST "echo $PASSWORD | sudo -S su -c \"$COMMAND\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment