Last active
May 2, 2023 10:01
-
-
Save thangdc94/e050e0d023f3cb25d8e29696c7dee9cb to your computer and use it in GitHub Desktop.
ssh with saved pass
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
Include config.d/* | |
Host remote-host | |
HostName 10.10.10.10 | |
User root | |
Port 22 | |
#PS password-for-remote-host | |
Host jump-remote-host | |
HostName target-remote | |
User root | |
Port 22 | |
StrictHostKeyChecking no | |
ProxyJump jump-user@jump-host | |
#PS password-for-target-remote | |
Host jump-portforward | |
HostName target-remote | |
User root | |
Port 22 | |
StrictHostKeyChecking no | |
ProxyCommand ssh -W %h:%p jump-user@jump-host | |
LocalForward 16001 target-host1:11001 | |
LocalForward 16002 target-host2:11002 | |
#PS password-for-target-remote |
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 | |
ORIG_SSH=/usr/bin/ssh | |
HOST=$1 | |
SSHPASS=$(grep -rhPzo "Host $HOST"'\s*\n((?!Host).*\n)*#PS\s(\N+)\n' ~/.ssh/config*|tail -n 2|head -n 1 | sed 's/#PS //') | |
if [ -z "${SSHPASS}" ]; then | |
$ORIG_SSH $@ | |
else | |
export SSHPASS | |
sshpass -e $ORIG_SSH $@ | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
put
ssh
to~/.local/bin
directory