Reputation: 1006
I have a remote access to remote server from my university and I'm accessing it through my local machine! However, my local machine has not enough memory to run multiple jupyter notebooks. Is there any way to run them through the remote server, which probably speed up tasks!! I'm not quite sure though!
I access the server from the terminal in macOS. Thanks!!
Upvotes: 66
Views: 217722
Reputation: 1
If you have some permission denied issue you can use the following steps: login server go to the directory where you want to create jupyter notebook Copy the following commands
export JUPYTER_CONFIG_DIR=~/.jupyter
export JUPYTER_DATA_DIR=~/.local/share/jupyter
export JUPYTER_RUNTIME_DIR=~/.local/share/jupyter/runtime
jupyter notebook
**note the key after the word 'localhost' in the link shown in terminal
open another terminal login server by using the following command:
ssh -L :localhost: username@server_ip
export JUPYTER_CONFIG_DIR=~/.jupyter
export JUPYTER_DATA_DIR=~/.local/share/jupyter
export JUPYTER_RUNTIME_DIR=~/.local/share/jupyter/runtime
jupyter notebook list
copy and paste the link in browser
Upvotes: 0
Reputation: 2033
There's quite a good tutorial here
Essentially you just run the notebook on the remote in no browser mode.
jupyter notebook --no-browser --port=8080
Then setup an ssh tunnel from the local machine:
ssh -L 8080:localhost:8080 <REMOTE_USER>@<REMOTE_HOST>
Then in your local browser go to: http://localhost:8080/
Running on a specific port is not necessary. The --no-browser
tag is.
Upvotes: 129
Reputation: 63
I have tested the following on Windows, MacOS, and Linux Operating Systems, and all of them gave successful results!
If you are using the Windows operating system, then make sure to have any client/terminal that can access SSH. I like the Git Bash as it is highly lightweight and very easy to use. However, the latest Windows PowerShell can also be used.
ssh remote_user@remote_ip
For example, suppose my remote user name is fahim and the remote IP is 103.101.50.2. Then the command would be:
ssh [email protected]
Write "Yes" when it asks to trust and add that connection.
Now, you need to use a port number that is not getting used by other applications or connections. For example, let's say, I am taking 8892 as my port number. I have already checked that port number 8892 is not getting used either on my local machine or the remote machine.
Now, I will open the Jupyter Notebook directly on my remote machine. As I have already been connected with the first git bash window, I can simply go there, and open my Jupyter notebook using:
jupyter notebook --no-browser --port=8892
ssh -NfL localhost:8892:localhost:8892 [email protected]
Here, "8892" is the port number that I chose earlier and it was not getting used by anything else at that moment. "fahim" is the remote machine's username. "103.101.50.2" is the remote machine's IP.
http://localhost:port_number
. As I used 8892 as the port number, I will go to http://localhost:8892
to open the Jupyter Notebook on my browser.After this point, I can use it without any hassle. But keep in mind to activate your conda environment if you have one before starting the jupyter notebook on your remote machine.
All of the processes are the same. You can use any terminal as all of the terminals support ssh by default. As the process continues, use separate terminal window so that in one window you can see the ongoing process for the notebook, and in another window, you can catch the forwarded port.
All of the processes are the same. You can use any terminal as all of the terminals support ssh by default. As the process continues, use separate terminal window so that in one window you can see the ongoing process for the notebook, and in another window, you can catch the forwarded port.
Upvotes: 1
Reputation: 27
None of the answers worked for me. What worked, instead, is a slight variation of all the answers and is quite simple.
Open the notebook in the remote server as jupyter notebook --no-browser --ip=<remote-host-ip>
. Then copy the link from the remote terminal in the local browser, which is of the form http://<remote-host-ip>:8888/tree?token=<>
Upvotes: 1
Reputation: 161
To access the remote machine with a browser the notebook must listen on an external facing port (not localhost). You will need the same invocation if want to run the Jupyter notebook on a container. In that case it is something like this:
jupyter notebook --no-browser --port=8080 --ip=0.0.0.0
To listen only in localhost then you can omit the IP
jupyter notebook --no-browser --port=8080
To access remotely the ssh tunnel option in other answers works. You will need an SSH tunnel per notebook. If you need to run multiple notebooks, another option is using the sshuttle
tool to simulate a VPN over SSH so you don't have to create multiple tunnels. Run sshuttle
with the option to have full reachability to the network of your remote machine (e.g. 10.250.100.40/24) or you can run it to forward all the traffic through the remote machine (like a traditional VPN).
# forward all traffic to network of remote server over the SSH VPN
sshuttle --dns -NHr username@sshserver 10.250.100.40/24
# forward all traffic through the remote server over the SSH VPN
sshuttle --dns -NHr username@sshserver 0/0
Note: The DNS flag is important to be able to use the remote machine DNS for name resolution.
Then execute the notebooks to listen on external ports. For example, running 3 notebooks.
jupyter notebook --no-browser --port=8080 --ip=0.0.0.0
jupyter notebook --no-browser --port=8081 --ip=0.0.0.0
jupyter notebook --no-browser --port=8082 --ip=0.0.0.0
You will use the Token on the output when running the notebooks for the authentication. It will display the output like this
http://server.example.com:8080/tree?token=dd9024f1fb68434645d3902d161f41720650644dc5832f16
Assuming the remote server is not blocking traffic to those port, then on you local machine it will be as simple as opening a browser to
http://<name-of-remote-machine>:8080/tree?token=<your-token>
http://<name-of-remote-machine>:8081/tree?token=<your-token>
http://<name-of-remote-machine>:8082/tree?token=<your-token>
Upvotes: 16
Reputation: 31
Run the jupyter notebook in the no browser mode with your custom port number
jupyter notebook --no-browser --port=8888
Then setup up an ssh tunnel from the local machine:
ssh -L 8888:localhost:8888 <REMOTE_USER>@<REMOTE_HOST>
Upvotes: 2
Reputation: 8435
Let's assume that the local user localuser
and host as localhost
, the remote user and remote host as remoteuser
and remotehost
. To run a Jupyter notebook on remote server from your local machine you can follow the steps below.
On remote machine run Jupyter notebook with --no-browser
with specifying a port
jupyter notebook --no-browser --port=XXXX
Forward it to your local machine via SSH
ssh -N -f -L localhost:YYYY:localhost:XXXX remoteuser@remotehost
Open a browser and go to http://localhost:YYYY
You may need to close the connection
Stop your running notebook with CTRL+C
then y
Kill the process running on port YYYY
, netstat
returns you the process ID (PID)
sudo netstat -lpn | grep :YYYY -> for LINUX
sudo netstat -anv | grep YYYY -> for MacOS
kill PROCESS_ID
Upvotes: 10
Reputation: 365
you can run jupyter notebook --no-browser --ip="<remote server ip>"
on your remote machine terminal. And access notebooks using http://:8888/?token=<> from your browser on local machine.
Upvotes: 17
Reputation: 329
I think you might be looking for port-forwarding.
e.g. when you're logged into your remote via ssh you can:
On the remote machine, start jupyter notebook from your current directory and specify the port:
jupyter notebook --no-browser --port=9999
On the local machine, catch the forwarded port:
ssh -NfL localhost:9999:localhost:9999 your_user_name@remote_ip_address
Go to http://localhost:9999
. You should be able to select your notebook and you'll be good to go.
Upvotes: 20