Skip to main content

Jupyter Remote Server Connection Guide

Jupyter Notebook can be used not only locally but also for conveniently connecting to remote servers. This way, if you have a server with large memory but prefer not to work directly on Linux, you can connect to the server remotely from a local Windows machine through Notebook and use the server's resources to write code.

1. Install Jupyter

Originally, Jupyter referred to Jupyter Notebook. Later, the Jupyter team introduced Jupyter Lab.

Run the following commands in the terminal to install Jupyter Notebook and Jupyter Lab:

pip install notebook jupyterlab

2. Set a Password

2.1 Automatic Setup

Run the following command in the terminal to set a password automatically:

jupyter server password

The system will prompt you to enter and verify a password:

Enter password:  ****
Verify password: ****
[JupyterPasswordApp] Wrote hashed password to /Users/you/.jupyter/jupyter_server_config.json

Automatic password setup does not require configuring a password in the configuration file.

Reference link: automatic-password-setup

2.2 Manual Setup

Open Python and enter the following statements:

from jupyter_server.auth import passwd
passwd()

The system will prompt you to enter and verify a password:

Enter password:
Verify password:
'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'

Manual setup requires configuring the password in the configuration file. If an automatic password is set, the manual password will not take effect.

Reference link: preparing-a-hashed-password

3. Generate the Configuration File

Run the following command in the terminal to generate the configuration file:

jupyter server --generate-config

The system will indicate where the configuration file was generated:

Writing default config to: /root/.jupyter/jupyter_server_config.py

4. Modify the Configuration File

Open the jupyter_notebook_config.py file and modify the following settings:

c.ServerApp.allow_remote_access = True
c.ServerApp.allow_root = True
# Enable remote access IP
c.ServerApp.ip = '*'
c.ServerApp.open_browser = False
c.ServerApp.password_required = True
# If using automatic password setup, no need to configure the manual password here
c.ServerApp.password = ''
# Set the port number
c.ServerApp.port = 9999
# Notebook storage directory
c.ServerApp.notebook_dir = '/root/app/jupyter'

5. Start Jupyter

Run the following command in the terminal to start the service:

jupyter notebook

To run Jupyter Notebook in the background, use the following command:

nohup jupyter notebook --allow-root >/dev/null 2>&1 &

Similarly, to start Jupyter Lab, run:

nohup jupyter lab --allow-root >/dev/null 2>&1 &

Since Jupyter Lab includes Jupyter Notebook, starting Jupyter Lab will also start Jupyter Notebook.

By following these steps, you can use Jupyter Notebook locally to remotely connect to and use resources on the server.