Skip to content

Instantly share code, notes, and snippets.

@thangdc94
Last active May 2, 2023 10:01
Show Gist options
  • Save thangdc94/e050e0d023f3cb25d8e29696c7dee9cb to your computer and use it in GitHub Desktop.
Save thangdc94/e050e0d023f3cb25d8e29696c7dee9cb to your computer and use it in GitHub Desktop.
ssh with saved pass
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
#!/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
@thangdc94
Copy link
Author

put ssh to ~/.local/bin directory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment