chatGPT教会我在Jupyter Lab上使用服务器

我:

我可以在本地电脑通过ssh登陆到我的服务器,我的本地电脑和服务器都是ubuntu系统,但是我只能在本地电脑的终端命令行界面使用服务器,这很不好看,而且效率很低,所以我想远程使用jupyter lab,也就是说我想在本地电脑的jupyter lab上使用服务器,我听说可以这样操作:通过SSH连接服务器,然后使用隧道,映射16001端口到本机16001端口,即可访问服务器上的Jupyter Lab进行python代码编写,但我不知道具体怎么操作,请详细地告诉我每一步需要怎么做,谢谢!

chatGPT:

好的,下面是具体步骤:
~~

  1. 通过SSH连接到你的服务器。可以使用以下命令:
ssh username@server_ip_address

其中,username是你的服务器账户名,server_ip_address是你的服务器IP地址。输入该命令后,会提示输入密码进行登录。

  1. 连接成功后,使用以下命令启动Jupyter Lab:
jupyter lab --no-browser --port=16001

这将启动Jupyter Lab,并监听在16001端口。

  1. 现在,我们需要使用SSH隧道将服务器的16001端口映射到本地16001端口。可以使用以下命令:
ssh -N -f -L localhost:16001:localhost:16001 username@server_ip_address

其中,username是你的服务器账户名,server_ip_address是你的服务器IP地址。

  1. 现在,我们可以在本地浏览器中打开Jupyter Lab,访问地址为:
http://localhost:16001

如果一切正常,你应该可以看到Jupyter Lab的登录页面。

  1. 最后,你需要输入Jupyter Lab的访问密码,这个密码可以在服务器上启动Jupyter Lab时,终端会输出一个类似下面这样的信息:
To access the server, open this file in a browser:
file:///home/username/.local/share/jupyter/runtime/nbserver-1234-open.html
Or copy and paste one of these URLs:
        http://localhost:16001/?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

其中,xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx就是Jupyter Lab的访问密码,复制该密码,粘贴到本地浏览器的登录页面即可。

以上就是将服务器上的Jupyter Lab通过SSH隧道映射到本地的具体步骤。

我:

but what is my Password or token?

chatGPT:

如果您在启动Jupyter Lab时没有设置密码,那么Jupyter Lab会自动生成一个访问令牌(access token)作为密码。在终端中启动Jupyter Lab时,会输出一个类似下面的信息:

To access the server, open this file in a browser:
file:///home/username/.local/share/jupyter/runtime/nbserver-1234-open.html
Or copy and paste one of these URLs:
        http://localhost:16001/?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

其中,xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx就是Jupyter Lab的访问令牌。您可以将其复制粘贴到Jupyter Lab登录页面的密码框中使用。如果您不小心关闭了终端窗口,可以使用以下命令查找Jupyter Lab的访问令牌:

jupyter notebook list

该命令将列出正在运行的Jupyter Notebook和Jupyter Lab进程的信息,包括它们的端口和访问令牌。

如果您在启动Jupyter Lab时设置了密码,那么您需要输入您设置的密码来登录Jupyter Lab。

我:

problem is solved, thank you very much!

chatGPT:

You're welcome! I'm glad that I could help you. If you have any further questions, feel free to ask!~~


但GPT说的很罗嗦,实际上只需3步即可:

1. ssh -L localhost:16004:localhost:16004 username@server_ip_address
登录服务器,连接端口。
2. jupyter lab --no-browser --port=16004
把Jupyter Lab映射到16004端口
3. 本地浏览器打开:localhost:16004
posted @ 2023-04-01 22:59  zhaopw5  阅读(151)  评论(0编辑  收藏  举报