Skip to content

Instantly share code, notes, and snippets.

@rafamdr
Created November 5, 2020 18:40
Show Gist options
  • Save rafamdr/f7dd76987838971d1c62ecad4ae3c7d4 to your computer and use it in GitHub Desktop.
Save rafamdr/f7dd76987838971d1c62ecad4ae3c7d4 to your computer and use it in GitHub Desktop.
Bash script to execute a command through SSH passing username/password as parameters
#!/bin/bash
#!/usr/bin/expect
if [ ! "$BASH_VERSION" ] ; then
exec /bin/bash "$0" "$@"
fi
echo -n "SSH User":
read -r sshusertemp
echo -n "SSH Password":
read -sr sshpasswordtemp
printf "\n"
sshpass -p "$sshpasswordtemp" ssh -o StrictHostKeyChecking=no "$sshusertemp"@192.128.0.2 "ls -la"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment