-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssh-vnc
executable file
·45 lines (37 loc) · 1.04 KB
/
ssh-vnc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
INFO="
Start vncserver on a remote host, set up ssh tunneling,
and connect to the session using vncviewer.
Usage:
ssh-vnc <ssh options>
"
if [ "x$1" = x ]; then
echo "$INFO" 1>&2
exit 1
fi
SIZE=$(xinfo r) || exit 1
SIZE=$((${SIZE%% *}-50))x$((${SIZE##* }-100)) || exit 1
TMPDIR=$(mktemp -d) || exit 1
trap "rm -rf $TMPDIR" EXIT
ECHO_PASSWD="echo -n $'\x49\x40\x15\xf9\xa3\x5e\x8b\x22'"
bash -c "$ECHO_PASSWD" > "$TMPDIR/passwd"
REMOTE_CMD="
cd || exit 1
mkdir -p .vnc || exit 1
$ECHO_PASSWD > .vnc/passwd || exit 1
chmod 0600 .vnc/passwd || exit 1
vncserver -list | grep '^:' | cut -f 1 | xargs -n1 vncserver -kill
echo Starting VNC server on remote host...
vncserver -geometry '$SIZE' -depth 24 \
-alwaysshared -dpi 96 -localhost :1 </dev/null || exit 1
echo Started
sleep 3600
"
ssh "$@" -L 6900:localhost:5901 "$REMOTE_CMD" 2>&1 | while read line; do
if [ "x$line" = xStarted ]; then
vncviewer 127.0.0.1:6900 -passwd "$TMPDIR/passwd"
exit 0
elif [ "x$line" != x ]; then
echo "$line"
fi
done