summaryrefslogtreecommitdiff
path: root/rapid-tunneling
blob: 92bd7c78ab9a4c869d1591997b37e4ab3ea2a049 (plain)
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
#!/bin/sh

if [ -z "$1" ]; then
	echo "Usage: $0 <remote-access-file-name>" 1>&2
	exit 1
fi

tmpdir=`mktemp -d`
mkdir $tmpdir/recv $tmpdir/send
tar xzf "$1" -C $tmpdir/recv
user=`cat $tmpdir/recv/user`
host=`cat $tmpdir/recv/host`
port=`cat $tmpdir/recv/port`
tunnelport=`cat $tmpdir/recv/tunnelport`

ssh-keygen -q -t rsa -C rapid-tunneling -N "" -f $tmpdir/send/key	# public will be in key.pub
cp $tmpdir/recv/key $tmpdir/send/origkey
cp $tmpdir/recv/key $HOME/key
tar czf $HOME/ra-params.tar.gz -C $tmpdir/send key origkey

mkdir -p -m 700 $HOME/.ssh
awk '$NF != "rapid-tunneling" {print}' $HOME/.ssh/authorized_keys > $HOME/.ssh/authorized_keys.new 2>/dev/null
cat $tmpdir/send/key.pub >> $HOME/.ssh/authorized_keys.new
mv -f $HOME/.ssh/authorized_keys.new $HOME/.ssh/authorized_keys
chmod 644 $HOME/.ssh/authorized_keys
rm -rf $tmpdir
# Remove host key of $host (in case it has changed)
ssh-keygen -R $host
# Run in background
busybox start-stop-daemon -S -b -m -p $HOME/pid -x /bin/sh -- -c "exec ssh -o 'StrictHostKeyChecking no' -o 'BatchMode yes' -o 'ServerAliveInterval 60' -T -p $port -i $HOME/key -R $tunnelport:127.0.0.1:22 -l $user $host < $HOME/ra-params.tar.gz"