5 easy steps to start editing python notebooks over SSH

ref:
5 easy steps to start editing python notebooks over SSH
http://fizzylogic.nl/2017/11/06/edit-jupyter-notebooks-over-ssh/

When you work with Linux machines on Amazon EC2 or Azure over SSH and want to edit interactive python code you’ve got a challenge. There is vim and other console based editors, but that might not be what you want. Here’s how you can edit python code in your browser over SSH in 5 steps.

Step 1: Install jupyter on your remote machine

Jupyter is a webbased python editor that works with notebooks. Notebooks are interactive pieces of python mixed with markdown code.

It’s cool because you can write several fragments of code and execute them one after another. When one of the fragments doesn’t work you can simply edit and run it again. The global variables defined in the other fragments are still there.

Want some documentation with your code? Add a markdown fragment and go wild. The cool thing about notebooks is that you’re not only editing python code and writing docs. It also visualizes graphs generated using pyplot.

The fact that you can do this kind of stuff in a notebook makes it ideal for creating experiments. It may not be suitable for production, but it is pretty much the only way I want to experiment when setting up protoypes.

You can install jupyter using the following command:

pip install jupyter
Bash
Copy

Execute this command on the remote machine you want to work on.
Once installed you can start editing notebooks.

Step 2: Start the jupyter notebook editor

Typically you’d start jupyter using the command jupyter notebook. But this opens up the browser, which is not available through an SSH session. So instead run the following command to start the jupyter notebook server without opening a browser:

jupyter notebook --no-browser --port=8080
Bash
Copy

Notice the port setting. Keep this port in mind when executing the next step.

Step 3: Setup a SSH tunnel to your remote machine

To access the notebook on your remote machine over SSH, set up a SSH tunnel to the remote machine using the following command:

ssh -N -L 8080:localhost:8080 <remote_user>@<remote_host>
Bash
Copy

This command opens op a new SSH session in the terminal. I’ve added the option -N to tell SSH that I’m not going to execute any remote commands. This ensures that the connection cannot be used in that way, see this as an added security measure.

I’ve also added the -L option that tells SSH to open up a tunnel from port 8080 on the remote machine to port 8080 in my local machine.

Step 4: Open the notebook in your browser

Now that you have a tunnel to the remote machine, open up your browser and navigate to http://localhost:8080/. This will fire up the jupyter notebook web interface.

Step 5: Enjoy your python notebooks

Time to start hacking! Keep in mind that the notebooks you save will be stored on the remote machine. So if you want to backup the notebook files you will have to either push them to git or download them to your local machine.

Enjoy!

posted on   yusisc  阅读(37)  评论(0编辑  收藏  举报

编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示