brandonleon
4/3/2012 - 4:27 PM

Simple script to use minecraft over an SSH tunnel

Simple script to use minecraft over an SSH tunnel

#!/bin/bash

MCLAUNCHER="path/to/MinecraftLauncher.jar"

# Your SSH host, e.g. www.example.com
SSHHOST="<your-ssh-host>"

# Stores the controlmaster file. Need to enable controlpath in the ssh .config file
SOCKCTL="~/.mc-ssh-ctl"

# Opens up an SSH tunnel to the remote server opening port 8080 locally
SSHCMD="ssh -nfN -D 8080 -S ""$SOCKCTL"" ""$SSHHOST"""

# Uses the control file to kill the SSH tunnel when finished with minecraft
SSHEXIT="ssh -S ""$SOCKCTL"" -O exit ""$SSHHOST"""

${SSHCMD}

# sleep for 5 seconds to make sure that the connection has been made
sleep 5

# Loads up Minecraft with the proxy information using the SSH tunnel
java -DsocksProxyHost=127.0.0.1 -DsocksProxyPort=8080 -Xmx800m -jar "$MCLAUNCHER"

# when finished, quit SSH
${SSHEXIT}