View on GitHub

tutos

Run tasks from anywhere

As a student at the Le Wagon Data Science bootcamp (batch #722, Paris), i started to run tasks remotely on my home desktop PC from my on campus laptop PC.

I found out it could be 10 times faster for building or pushing a Docker image, for downloading or uploading big files, or for training or running big models (on Week 7 and Project Weeks).

I'd like to share the few tricks that I learnt from scratch, as it might be of interest for students in future batches and fellow freelancer alumni.

Using aliases, connecting to my Jupyter lab is now as simple as [ cxlab + password + cxlab + Ctrl + click ].

Table of contents

  1. About the setup i used
  2. How to setup SSH
  3. How to connect (SSH)
  4. What you can do once you're connected
  5. How to connect with port forwarding
  6. How to run Jupyter lab
  7. How to run other services
  8. What you cannot do, yet
  9. The issue with public IPs...
  10. Optional: WOL
  11. Optional: Set aliases, environment variables
  12. Optional: Set Makefile, Dockerfile...
  13. How you can help

...

About the setup i used

How to setup SSH

How to connect (SSH)

# ssh login to desktop
ssh <username>@<my_public_IP> -p<ssh_port>
# enter your password...

What you can do once you're connected

How to connect with port forwarding

# ssh login and port forwarding
ssh <username>@<my_public_IP> -p<ssh_port> -L <source_port>:localhost:<destination_port>

How to run Jupyter lab

# run jupyter lab and specify the port you've just chosen
jupyter lab --port=<source_port>

How to run other services

You can launch several services... just SSH multiple time with ditinct port redirection:

What you cannot do, yet

The issue with public IPs...

echo >> /var/services/homes/edmz/Scripts/IP.txt
curl ifconfig.me >> /var/services/homes/edmz/Scripts/IP.txt

Optional: WOL

# SSH to my NAS
ssh <username_on_nas>@<my_public_IP> -p<port_to_nas>
# send magic packet to the desktop
sudo synonet --wake <MAC_address> eth0
# Ctrl+D to exit NAS shell
# wait a bit for the desktop to wake up
# SSH to the desktop

Optional: Set aliases, environment variables

With the following setup, i just need [ cxlab + password + cxlab + Ctrl + click ] to connect to Jupyter lab!

Copy-paste the following lines at the end of ~/.zshrc on LAPTOP PC


##################################
### CONNECT CONFIGURATION
##################################

export USERNAME_DESKTOP=XXXXXX
export PUBLIC_IP_HOME=XXX.XXX.XXX.XXX
export PORT_SSH_DESKTOP=XXXX

alias cxdesktop="ssh ${USERNAME_DESKTOP}@${PUBLIC_IP_HOME} -p${PORT_SSH_DESKTOP}"

export PORT_NOTEBOOK=8880
export PORT_LAB=8890
export PORT_API=5000
export PORT_STREAMLIT=8000

alias cxnotebook="ssh ${USERNAME_DESKTOP}@${PUBLIC_IP_HOME} -p${PORT_SSH_DESKTOP} -L ${PORT_NOTEBOOK}:localhost:${PORT_NOTEBOOK}"
alias cxlab="ssh ${USERNAME_DESKTOP}@${PUBLIC_IP_HOME} -p${PORT_SSH_DESKTOP} -L ${PORT_LAB}:localhost:${PORT_LAB}"
alias cxapi="ssh ${USERNAME_DESKTOP}@${PUBLIC_IP_HOME} -p${PORT_SSH_DESKTOP} -L ${PORT_API}:localhost:${PORT_API}"
alias cxstreamlit="ssh ${USERNAME_DESKTOP}@${PUBLIC_IP_HOME} -p${PORT_SSH_DESKTOP} -L ${PORT_STREAMLIT}:localhost:${PORT_STREAMLIT}"

##################################

Alternatively, use echo >>:

echo "

##################################
### CONNECT CONFIGURATION
##################################

export USERNAME_DESKTOP=XXXXXX
export PUBLIC_IP_HOME=XXX.XXX.XXX.XXX
export PORT_SSH_DESKTOP=XXXX

alias cxdesktop=\"ssh \${USERNAME_DESKTOP}@\${PUBLIC_IP_HOME} -p\${PORT_SSH_DESKTOP}\"

export PORT_NOTEBOOK=8880
export PORT_LAB=8890
export PORT_API=5000
export PORT_STREAMLIT=8000

alias cxnotebook=\"ssh \${USERNAME_DESKTOP}@\${PUBLIC_IP_HOME} -p\${PORT_SSH_DESKTOP} -L \${PORT_NOTEBOOK}:localhost:\${PORT_NOTEBOOK}\"
alias cxlab=\"ssh \${USERNAME_DESKTOP}@\${PUBLIC_IP_HOME} -p\${PORT_SSH_DESKTOP} -L \${PORT_LAB}:localhost:\${PORT_LAB}\"
alias cxapi=\"ssh \${USERNAME_DESKTOP}@\${PUBLIC_IP_HOME} -p\${PORT_SSH_DESKTOP} -L \${PORT_API}:localhost:\${PORT_API}\"
alias cxstreamlit=\"ssh \${USERNAME_DESKTOP}@\${PUBLIC_IP_HOME} -p\${PORT_SSH_DESKTOP} -L \${PORT_STREAMLIT}:localhost:\${PORT_STREAMLIT}\"

##################################
" >> ~/.zshrc

Copy-paste the following lines at the end of ~/.zshrc on DESKTOP PC


##################################
### CONNECT CONFIGURATION
##################################

export PORT_NOTEBOOK=8880
export PORT_LAB=8890
export PORT_STREAMLIT=8000
export PORT_API=5000

alias cxnotebook="jupyter notebook --port=${PORT_NOTEBOOK}"
alias cxlab="jupyter lab --port=${PORT_LAB}"

##################################

Alternatively, use echo >>

echo "

##################################
### CONNECT CONFIGURATION
##################################

export PORT_NOTEBOOK=8880
export PORT_LAB=8890
export PORT_STREAMLIT=8000
export PORT_API=5000

alias cxnotebook=\"jupyter notebook --port=\${PORT_NOTEBOOK}\"
alias cxlab=\"jupyter lab --port=\${PORT_LAB}\"

##################################
" >> ~/.zshrc

Optional: Set Makefile, Dockerfile...

Streamlit

i haven't try this

# Makefile on desktop (streamlit project folder)
run_streamlit_cx:
    streamlit run app.py --server.port ${PORT_STREAMLIT}

# Makefile on desktop (fastapi project folder)
run_api-cx:
    uvicorn my_api.fast:app --reload --port ${PORT_API}

in a Docker project

i haven't try this

How you can help

Jupyter service

[Unit]
Description=Jupyter Notebook

[Service]
Type=simple
PIDFile=/run/jupyter.pid
ExecStart=/home/user/.pyenv/shims/jupyter lab --port=8890 --notebook-dir=/home/user/folder --no-browser
User=user
Group=user
WorkingDirectory=/home/user/folder
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable jupyter
sudo systemctl start jupyter
# to check:
sudo systemctl status jupyter

Everything there