Port forwarding to use jupyter notebook installed in your server

Warning: Do not experiment before you read all the below steps!

Happy Learning 🙂

First: Inside Local machine:

  1. Create an alias for port-forwarding in your ~/.bashrc (or ~/.zshrc) config file as:

For bash shell:

echo "alias startjupyter='ssh -N -f -L localhost:7777:localhost:8890 [email protected]'" >> $HOME/.bashrc

Note: replace remoteuser and remotehost by your username and server ip.

For zsh shell:

echo "alias startjupyter='ssh -N -f -L localhost:7777:localhost:8890 [email protected]'" >> $HOME/.zshrc
  1. It is always a wise decision to close the connection when you are done with using it. So, to close the connection:
sudo netstat -lpn | grep :7777

But, I will also make alias for this, by doing this:

echo "alias closejupyter='sudo netstat -lpn | grep :7777'" >> $HOME/.bashrc

Second: Inside server machine:

  1. Add an alias to start kernel of jupyter notebook (without opening the browser with new port number) in your ~/.bashrc (or ~/.zshrc) config file. You can do so by:
echo "alias nojupyter='jupyter notebook --no-browser --port=8890'" >> $HOME/.bashrc

Note: The default port number is 8888 so, please reserved that for default.

  1. Now you can able to start the Jupter server by typing nojupyter

Third: To Sum Up

  1. Start port forwarding by typing startjupyter
  2. Open the server and run the jupyter by typing nojupyter
  3. Copy the url produces after running nojupyter and paste it into your local browser
  4. Replace port number 8890 by 7777 in the url and hit enter.

Hurray!

Note: Do not close the connection from server. It will also close the jupter server. There's another option you can do: You can set the jupyter server run in daemon (i.e in background) but for this purpose, I don't think it's really a good idea.

  1. If you are done of using it then close the jupyter by Ctrl+C and exit the server connection, and also in local side by typing closejupyter

Optional: Create and use bash helper function

All you need to do is to paste all three helper function in your configuration file (this can be your .bashrc).

Helper function to fire-up a Jupyter notebook in remote

function nojupyter() {
    # Fires-up a Jupyter notebook by supplying a specific port
    jupyter notebook --no-browser --port=$1
}

And to run juypter, type this:

[email protected]: nojupyter 8899

Helper function to listen to a port

function openjupyter() {
    # Forwards port $1 into port $2 and listens to it
    ssh -N -f -L localhost:$2:localhost:$1 [email protected]
}

Then, type this:

[email protected]: jptt 8890 7777

To close the connection from the port

function closejupyter() {
    sudo netstat -lpn |grep :$1
}

Then type:

[email protected]: closejupter 7777

Optional: Wolfram Language kernel for Jupyter notebooks (Archived)

Original Link

You can download the latest version of the paclet here:

https://github.com/WolframResearch/WolframLanguageForJupyter/releases

To install the paclet, open the mathematica and run the following command with Wolfram Language (replacing x, y, and z with the correct values):

PacletInstall["WolframLanguageForJupyter-x.y.z.paclet"]

To load the paclet, run:

Needs["WolframLanguageForJupyter`"]

To add the Wolfram Language to Jupyter, run:

ConfigureJupyter["Add"]

To specify a specific Jupyter binary, run:

ConfigureJupyter["Add", "JupyterInstallation" -> "..."]

(This step is Optional) To specify a specific Wolfram Engine binary, run:

ConfigureJupyter["Add", "WolframEngineBinary" -> "..." ]

Please note, however, that the value for the "WolframEngineBinary" option should not be a wolframscript path.

Testing your installation

In your terminal, The following command should now list the Wolfram Engine:

jupyter kernelspec list

The output should include a line like this:

wolframlanguage12    C:\ProgramData\jupyter\kernels\wolframlanguage12

To test your installation in a notebook, run the following command:

jupyter notebook