Skip to content

Instantly share code, notes, and snippets.

@knbknb
Last active April 15, 2022 17:35
Show Gist options
  • Select an option

  • Save knbknb/ab75832004bf32df72c9681b97b05a61 to your computer and use it in GitHub Desktop.

Select an option

Save knbknb/ab75832004bf32df72c9681b97b05a61 to your computer and use it in GitHub Desktop.
Open 2 Gnome terminals: _1: ssh--tunnel to linux-Jumpbox, _2: rdp to Windows Machine
#!/usr/bin/env bash
# create an SSH Tunnel to a Windows Remote Desktop machine via a sshd-jumpbox
# with SSH, local port fortwarding, and xfreerdp/rdesktop.
#
# last lines (xdotool ...) are optional
# they will open new gnome-terminal windows
#
# recommended step before
# ssh-agent add some-privatekey
#
# in first shell, open a tunnel
# using local ssh port forwarding
#
#
# knb 20220322
# Alternatives: xfreerdp or rdesktop
#"xfreerdp /u:conze' /p:'teufenlabor'"
commands=(
# the actual commands, can be run standalone-
# use TWO (2) terminal windows, one for each command
"ssh win.machine.xxx -L 1111:some.jumpbox.ip:3389"
"rdesktop 127.0.0.1:1111 -u username -p password "
)
len=${#commands[@]}
if [ $# -eq 0 ];then
num=$len
else
num=$1
fi
n=$((len-num))
command=${commands[$n]}
num=$((num-1))
# optional code.
# https://unix.stackexchange.com/a/192524/66342
# open gnome terminal with several tabs
# and execute a few commands in every tab
#
# Dependencies:
# sudo apt install xdotool
#
me=$(realpath $0)
xdotool key ctrl+shift+t
if [ $num -gt -1 ]; then
sleep 1;
xdotool type --delay 1 --clearmodifiers "$me $num; ${command}";
xdotool key Return;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment