Preventing Jupyter notebook from disconnecting - ssh

I have a server I connect to with ssh. Inside this server there are several nodes (virtual machines). I run jupyter notebook inside one of these nodes. The steps I follow in order to run the graphic interface on my local browser are the following:
On the node (VM): jupyter notebook --no-browser --port=8886 --ip=127.0.0.1
On server: ssh -N -L 8887:127.0.0.1:8886 node
On local: ssh -N -L 8888:127.0.0.1:8887 server#x.x.x.x
In particular, inside the node and the server I firstly run screen and then I detach, so they will run without problems.
Instead, my problem is in local. If I go away from keyboard for a bit of time It happens that my local instance disconnects, while the processes (training of Neural Networks) on the node of the server are still running as well as the jupyter notebook --no-browser
How can I prevent jupyter notebook from disconnecting in local?

Related

Running jobs on a HPC cluster using JupyterLab running on my personal computer

I would like to run jobs on a HPC cluster by writing commands using my personal computer. I can use the ssh command from the terminal to login the remote supercomputer. However, I am looking for a way to login and run commands on the remote HPC cluster from Jupyter notebook running on my personal computer. Is there a way to do this?

When using ssh -X to connect to remote Ubuntu 18.04, couldn't it show server's local terminal GUI on my own PC?

I found a strange thing when using ssh -X to connect to two servers.
Ubuntu16.04 is installed on one server, while Ubuntu 18.04 is installed on the other. I upload a simple shell script as following to both servers:
#!/bin/bash
tab=" --tab"
options=()
cmds[1]="echo Banana"
cmds[2]="echo Cat"
for i in 1 2; do
options+=($tab -e "bash -c '${cmds[i]} ; bash'" )
done
gnome-terminal "${options[#]}"
exit 0
You know this script will open a new terminal window on server with two tabs. One tab will print "Banana", and the other tab will print "Cat".
Then I using ssh -X to remotely login into the first server (Ubuntu 16.04) and execute this script on server, I got a new terminal opened with two tabs on my pc. That is I saw the remote terminal GUI of server on my own computer. However, if I repeated these steps on the second server(Ubuntu18.04), I will got nothing to show on my computer.
The I execute commandgedit on the ssh login terminal when using ssh -X to login into both servers, I could see the GUI on my computer for both the cases.
I guess Ubuntu 18.04 cannot transport terminal's GUI through ssh -X to my pc. I was very confused about this. Could you please to explain the reason? And BTW, how can I see terminal's GUI of server in this case? Thanks a lot!
ssh -X doesn't transport a terminal. It tunnels a X11 connection.
X11 in its core is a network based display protocol. The programs (X clients) connect to a X server (a program running on your local machine) and instruct it to create windows and draw stuff to it. There is no graphical rendition of any kind anywhere else than the X server!
ssh -X does not operate like Windows Remote Desktop, where there is an actual graphics environment running on the remote machine. Hence if you create two separate ssh -X connections (maybe even from different machines), these connections are completely independent from each other. Hence you cannot use ssh -X to connect with a preexisting X session!
What you want is either Xvnc or Xpra, where the graphics environment is actually run on the remote machine, and only the output is transferred to your local machine.

Google Compute Engine instance restarts when I ssh

I have a deep learning vm setup on google cloud platform. I ssh into by clicking the ssh button in my list of vm instances. The problem I am having is that if I run a program and close the ssh window while it is still running, when I ssh back into the vm, the program has been interrupted and the whole vm essentially has restarted.
Is there a way to setup my vm so that I can run a program and then close the ssh connection without it restarting the vm? I want to be able to run programs without being required to leave the ssh window open and my computer on.
As #Rup pointed out, processes belonging to your SSH session's shell will get a hang-up signal when you close the connection. To bypass the hang-up signal and let a program continue running, use the nohup command. Here is an example
nohup python test.py &
That will run the program test.py and as well as ignore the hang-up signal. The programs output will be stored in a nohup.out file.

Connect to remote iPython notebook

I want to connect to existing notebooks via ssh tunnel / vpn on a remote linux machine.
I can not log in to the remote desktop viewing them,
but can generally log into another desktop session via Windows Remote Desktop (Win7, Linux with xrdp), so that I found the *.json files containing the ports (see similar questions 1, though I have no experience in finding the correct job/file).
After connecting a vpn and putty ssh tunnel (port A), I tried to access localhost:A by opening that in Firefox. Also I tried to run ipython notebook --existing kernel-B.json.
This did not work.
Do notebooks have to be on the tunneled port?
Or is there a way to connect (not start as in 2), or should I open a tunnel for every notebook port?
Similar questions:
Connecting to a remote IPython instance
Connect ipython-notebook via SSH tunnel from a remote location
Read this:
How do I add a kernel on a remote machine in IPython (Jupyter) Notebook?
Remote jupyter kernel/kernels administration utility (the rk) here:
https://github.com/korniichuk/rk
Should I open a tunnel for every notebook port?
Yes!

How to exectute a Mathematica Script through ssh

here is my problem: i would like to run a Mathematica script through ssh on a remote machine so that i can close the terminal on my computer and keep it running on the remote one.
My problem arises because the script acts in interacting mode, and so when i close the terminal the process is shut down too.
Thanks.
Use tmux or GNU screen.
Workflow:
ssh into remote machine
start tmux/screen, e.g. tmux or screen
start Mathematica script inside tmux/screen session
detach tmux/screen session, e.g. Ctrl+B d (tmux) or Ctrl+A d (screen)
close ssh connection
Then later:
ssh into remote machine
reattach to tmux/screen session, e.g. tmux attach or screen -d -R
view completed Mathematica script output
Several cases:
If you don't need to interact with it or need to visualize the notebook during evaluation
Log in to the machine with ssh
Then, to run a kernel in the background and detach it from the current session, use nohup tool (the standard output of the command will be dumped to myNotebook.out):
nohup math < myNotebook.nb > myNotebook.out &
At this point, the ssh session can be closed without killing Mathematica
Optionally you can monitor mathcommand output with the tail command (use CTRL-C to exit the tail monitoring)
tail -f myNotebook.out
If you need to see what's going on, visualize graphs during calculation or to be able to interact graphically, use remote desktop (vnc) and tunnel your communication with remote machine. Details depends a bit on the Linux distribution (vnc clients & servers may differ). You can even from Windows or Mac connect with remote desktop to your linux box and manipulate it. I suggest you to search the web for remote desktop ssh tunnel + your distro for tutorials.