# How can I connect to a remote machine?

My friend and I are trying to set up remote kernels.

He has a server at home running 1 kernel off of a Linux-based server. We're both on 8.0.

I manually set $RemoteCommand to "ssh 3@1-l 3 \"math -mathlink -linkmode Connect 4 -linkname \ 2 -subkernel -noinit >& /dev/null &\""  and manually changed $RemoteUserName to the one he set up for me. The problem is, whenever we try and run the code, we get the following error message:

LaunchRemote::rsh: Command ssh [my username]@[his server address]-l [my username] "math -mathlink -linkmode Connect -linkprotocol TCPIP -linkname 51145@[my public IP address],51146@[my public IP address] -subkernel -noinit >& /dev/null &" may have failed (exit code 1).

The problem is, my public IP address is not the same as my private IP address, so I can't connect. How can I get Mathematica to recognize my private IP instead?

-

## 2 Answers

I've been successful connecting to my office Mac workstation using SSH port forwarding:

ssh -R 31415:127.0.0.1:31415 -R 31416:127.0.0.1:31416 username@XXX.XXX.XXX.XXX "/Applications/Mathematica.app/Contents/MacOS/MathKernel -mathlink -LinkMode Connect -LinkProtocol TCPIP -LinkName 31415@127.0.0.1,31416@127.0.0.1 -LinkHost 127.0.0.1"


where username@XXX.XXX.XXX.XXX should be replaced with your SSH user name and the IP address of the remote machine. If the remote machine is running Linux, replace

/Applications/Mathematica.app/Contents/MacOS/MathKernel


with the appropriate path of the MathKernel executable.

-
 So 31415 and 31416` are ports.. ARe these default values? Can I do something similar to start a remote kernel in my notebook/script? – drN Oct 7 '12 at 13:44 You can change those port numbers to anything. Yes, you should be able to use the same to start a remote kernel in your notebook/script. – Dale Roberts Oct 7 '12 at 23:18 can you give more details on how/where you use the command? – jenson Nov 6 '12 at 0:16

I have never had luck with this directly, since the remote machine has to connect back to the master. However, there is a way to do it with OpenVPN -- make the two machines connect to the VPN appear to be on the same subnet.

-
and just to add -- you might think that you can do port forwarding through your router. But it often doesn't work because of ISP port-blocking policies. Also, I have never gotten the ssh forwarding stuff to work, either. – Eric Brown Oct 7 '12 at 5:09