Last active
September 21, 2021 14:33
-
-
Save nickpopovich/c5e22d930c5f217682bda063b12bee91 to your computer and use it in GitHub Desktop.
use ssh with password natively without expect/sshpass from non-interactive shell
This file contains 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
# in a scenario where you have a non-interactive shell, and need to use discovered SSH credentials (not private keys) from cli and don't | |
# want to/can't install expect/sshpass | |
# usage would be create script on target host, and use the non interactive shell to chmod +x/execute script from target | |
# if calling with bash need to give full path to script even if operating in same directory | |
#video at https://www.youtube.com/watch?v=-YlG9M9X2Oc | |
#!/bin/bash | |
SSH_USER=testuser | |
SSH_PASS="password123" | |
SSH_HOST=127.0.0.1 | |
REMOTE_CMD="ls -al" | |
if [ -n "$PASSWORD" ]; then | |
cat <<< "$PASSWORD" | |
exit 0 | |
fi | |
export PASSWORD=$SSH_PASS | |
export SSH_ASKPASS=$0 | |
export DISPLAY=dummy:0 | |
exec setsid ssh -o "StrictHostKeyChecking no" $SSH_USER@$SSH_HOST $REMOTE_CMD | |
# from https://titanwolf.org/Network/Articles/Article?AID=ec202919-fb60-49d8-b75f-38025d69e222#gsc.tab=0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment