Load a file from a remote machine in a local ipython notebook - ipython

I'm running IPython notebook on my local machine and I would like to load/save a file which resides on a remote machine via %load / %%writefile. Did anyone tried? Or is it possible? The remote machine is reachable via ssh.

Related

Matlab connection to a remote server

Is there a way to connect to a host through matlab using SSH? The way that can be done in vscode for example.
I have script and data in the remote machine but matlab license in my local machine. I would like to run the matlab scripts using matlab installed on my laptop.
Alternatively, I clone the scripts on my laptop run them while processing the data located in the remote machine.
https://en.wikipedia.org/wiki/SSHFS
helps you mount a remote filesystem via ssh. So if you can login from your matlab laptop to the data pc via ssh , then sshfs is one step more. From there your data is a path on the matlab laptop.

How do not display xterm terminal from remote server to local machine

I run my code on remote server trough ssh and my code execute other scripts through xterm. Then the scripts are displayed on my local machine through xterm, but I don't want to display these on my local machine.
Is there any method that do not display these terminals on my local machine, even remote server actually run the scripts through xterm?

Trigger jupyter notebook save

I have a jupyter notebook that I opened on a remote computer (with the kernel also running on that remote computer). I have also opened the notebook on my local computer (connecting to the remote kernel) but there have been changes to the notebook on the remote that haven't been saved.
Is there a way to trigger the remote computer to save the notebook, e.g., by sshing in and issuing some command?
It can be trigged by JavaScript.
IPython.notebook.save_notebook();

Use Jupyter Notebook on my local computer to run code on a remote computer

I use Jupyter Notebook to run bioinformatic analyses, and I love it. However, it only really plays nice when I run it on my personal computer. However, I regularly do analysis using a remote computer with multiple cores to reduce processing time. I'd like to be able to use the Jupyter Notebook interface on my personal computer while everything is actually running on the remote computer. I generally do this via ssh access to the remote computer within the shell and execute all commands at the command line. I'd love to do this from the Jupyter notebook on my personal computer, rather than from the shell on my personal computer. It is relevant that I don't have sudo access on the remote computer.
So far, I've installed miniconda and jupyter notebook on the remote computer like this:
wget https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
Once conda is installed properly, I install jupyter notebook via miniconda with this line:
conda install jupyter
This installs successfully. I can then start a jupyter notebook session on the remote machine with the line:
jupyter notebook --no-browser
So far, so good. My next question: How do I have my local jupyter notebook connect to the remote machine, so that I can execute commands on the remote machine using my local jupyter notebook? There is some documentation here, however i have been trying different things for hours, but have failed to succeed.
Can anyone give a straight forward method to connect to my remote server, given that I am this far along? I feel like it should just be a matter of entering url addresses and passwords into my local Jupyter notebook (all of this is so easy via ssh in the shell).
Follow the steps below:
Enable port forwarding on remote machine
ssh -N -f -L 127.0.0.1:8898:127.0.0.1:8898 user#remote-machine.com
Do ssh to your remote machine and then run following command on remote machine
jupyter-notebook --no-browser --port=8898
you will see some thing as shown below
Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://localhost:8898/token=eaf2f51f9c053f43d8bd093e76f0cc6301b545549c998fa2&token=eaf2f51f9c053f43d8bd093e76f0cc6301b545549c998fa2
Copy and paste the URL in your local machine browser.
If you want to access Jupyter/Ipython notebook running on a VPS remotely, I wrote a tutorial on the digital ocean community site.
As shown in the guide, after installing and running Ipython Notebook using command line on the server, you can connect to the notebook using SSH tunnelling with Putty (on windows) or the ssh -L command on Unix-like systems (ie Mac and Linux)

Connect to remote kernel on AWS using local qtconsole?

By following the instructions listed here:
Running a notebook server — IPython 1.2.1: An Afternoon Hack documentation - https://ipython.org/ipython-doc/rel-1.1.0/interactive/public_server.html
I have been able to connect to a remote notebook server on Amazon AWS via the browser. Can I get to this kernel using a local qtconsole? In other words, can I do something like this on the local client:
% ipython qtconsole --kernel
My concern is that the instructions listed above refer to a password and certificate that is required by the browser to connect to the remote server. How would this work with the desired qtconsole? Maybe some kind of tunnel is required to handle this case?
Thanks in advance.
It took me awhile to figure out so I thought I'd save others the trouble. The link
http://jupyter.org/qtconsole/stable/#ssh-tunnels
provides some clues but is incomplete. Note that I am interested in connecting a local ipython qtconsole to a remote kernel. The first thing is to start the
console on the remote machine by doing
% ipython console
This fires up a ipython console on the amazon instance. Next, I manually
transfer the kernel-*.json file to my local machine. This file is automatically created in the .ipython/profile_default/security directory on the remote instance. Note that by kernel-*.json, I mean the kernel file that is created automatically when ipython console is run. Usually, this looks something like kernel-21311.json, for example. It is possible to configure this with the .ipython configuration files, but that's another story.
# filename: console_tunnels.py
import json
import argparse
from sshtunnel import SSHTunnelForwarder
from time import sleep
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('ipython_json',
type=str,
help='ipython kernel json file')
parser.add_argument('--host',
type=str,
help='hostname',
default='awsinstance')
parser.add_argument('-k',
'--private_key',
type=str,
help='private_key',
default='/home/reckoner/.ssh/id_rsa')
parser.add_argument('-u',
'--username',
type=str,
help='username',
default='reckoner')
args = parser.parse_args()
ports_keys = ['stdin_port', 'control_port', 'hb_port', 'shell_port',
'iopub_port']
d = json.load(open(args.ipython_json))
addresses = [('127.0.0.1', d[i]) for i in ports_keys]
with SSHTunnelForwarder(
ssh_username=args.username,
local_bind_addresses=addresses,
remote_bind_addresses=addresses,
ssh_private_key=args.private_key,
ssh_address=args.host, ):
while True:
# press Ctrl-C for stopping
sleep(0.5)
Next, I run the script listed above on the client machine
% python console_tunnels.py kernel-*.json
and then all the right ports get forwarded!
The next step is to start the local qtconsole by pointing it to the
kernel-*.json file I downloaded earlier.
% ipython qtconsole --existing kernel-*.json
and that's it! You can now work in the qtconsole but all the computation
happens on the remote instance. The great part is that opening figure windows in the qtconsole opens them on the client while the data and computation reside on the remote instance!
Enjoy!