Last active
May 14, 2022 07:58
-
-
Save checkaayush/7271e96e0be409a05a9f to your computer and use it in GitHub Desktop.
SSH: Run local bash script on remote server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Run local bash script on remote server via SSH connection | |
# Login variables | |
USER="username" | |
HOST="host_address" #Remote host | |
PATH_TO_SCRIPT="path/to/your_script.sh" | |
ssh -l $USER $HOST 'bash -s' < $PATH_TO_SCRIPT | |
## To run just a command on remote machine: | |
# COMMAND="echo 'Hi there!'" | |
# ssh -l $USER $HOST $COMMAND | |
## If you don't want to manually insert authentication password: | |
## Requires 'sshpass' locally (Debian-based systems: apt-get install sshpass) | |
## Note: This is a less secure way; You might want to use 'openssl' for password encryption and decryption | |
# PASSWD="your_password" | |
# sshpass -p $PASSWD ssh -l $USER $HOST 'bash -s' < $PATH_TO_SCRIPT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment