230803 jupyter 服务器远程连接失败

230803 jupyter 服务器远程连接失败

1.服务器端配置以及本地使用

(1)jupyter安装

pip install jupyter

(2)生成配置文件

jupyter notebook --generate-config

(3)编辑配置文件

  • 使用vim 命令对文件vi /root/.jupyter/jupyter_notebook_config.py `进行编辑。
  • vi /root/.jupyter/jupyter_notebook_config.py 打开文件;
  • 按住ESC键,并依次输入:$,跳到文件末尾;
  • 安装Shift+i,执行插入操作;这个时候可以移动光标对文件中的内容进行修改。
  • 也可以直接在末尾输入以下内容(PS:这些内容都可以在文件中找到,但都被注释掉了,如何不想找的话,直接在末尾加入这些信息)

c.NotebookApp.ip = ‘*’ # 表示允许任意ip访问
c.NotebookApp.open_browser = False # 运行时不打开本机浏览器
c.NotebookApp.port = 8890 # 使用的端口,随意设置
c.NotebookApp.allow_remote_access = True #允许远程访问
c.NotebookApp.allow_root = True

  • 按住ESC键,并依次输入:wq!,进行保存。

(4)配置密钥

输入ipython打开ipython生成密钥:

In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:ce23d945972f:34769685a7ccd3d08c84a18c63968a41f1140274' *#这段是密钥*

(5)服务器端启动

输入 jupyter notebook --no-browser --port=8888 --ip=0.0.0.0 启动

在这里插入图片描述

(6)本地端启动

在浏览器里敲入你的地址 http://yourip:8888/ ,进入。

2.遇到的问题(本地端404)

大部分问题现有的博客中都可以找到,这里主要讲一下我耽误时间比较长的一个,最后在浏览器中输入网址之后不显示界面。这里采取的是使用SSH将远程端口映射到本地的方法。主要参考了使用SSH映射远程端口至本地_ssh 端口映射_Snychng的博客-CSDN博客

我在cmd中输入的命令是ssh -CNgv -L 8888:127.0.0.1:8888 root@10.181.108.38 -p 20004

cmd结果如下:

C:\Users\William>ssh -CNgv -L 8888:127.0.0.1:8888 root@10.181.108.38 -p 20004
OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2
debug1: Connecting to 10.181.108.38 [10.181.108.38] port 20004.
debug1: Connection established.
debug1: identity file C:\\Users\\William/.ssh/id_rsa type 0
debug1: identity file C:\\Users\\William/.ssh/id_rsa-cert type -1
debug1: identity file C:\\Users\\William/.ssh/id_dsa type -1
debug1: identity file C:\\Users\\William/.ssh/id_dsa-cert type -1
debug1: identity file C:\\Users\\William/.ssh/id_ecdsa type -1
debug1: identity file C:\\Users\\William/.ssh/id_ecdsa-cert type -1
debug1: identity file C:\\Users\\William/.ssh/id_ed25519 type -1
debug1: identity file C:\\Users\\William/.ssh/id_ed25519-cert type -1
debug1: identity file C:\\Users\\William/.ssh/id_xmss type -1
debug1: identity file C:\\Users\\William/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_8.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.6p1 Ubuntu-4ubuntu0.7
debug1: match: OpenSSH_7.6p1 Ubuntu-4ubuntu0.7 pat OpenSSH_7.0*,OpenSSH_7.1*,OpenSSH_7.2*,OpenSSH_7.3*,OpenSSH_7.4*,OpenSSH_7.5*,OpenSSH_7.6*,OpenSSH_7.7* compat 0x04000002
debug1: Authenticating to 10.181.108.38:20004 as 'root'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: zlib@openssh.com
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: zlib@openssh.com
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:WDO27N6vAol2twim51o7rlqaeum9Wk314fdsISAvtCE
debug1: Host '[10.181.108.38]:20004' is known and matches the ECDSA host key.
debug1: Found key in C:\\Users\\William/.ssh/known_hosts:2
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: pubkey_prepare: ssh_get_authentication_socket: No such file or directory
debug1: Will attempt key: C:\\Users\\William/.ssh/id_rsa RSA SHA256:8zsKHcEa+k0VdidXgBTv1EFBWKNRVBObqFgUVnaITIs
debug1: Will attempt key: C:\\Users\\William/.ssh/id_dsa
debug1: Will attempt key: C:\\Users\\William/.ssh/id_ecdsa
debug1: Will attempt key: C:\\Users\\William/.ssh/id_ed25519
debug1: Will attempt key: C:\\Users\\William/.ssh/id_xmss
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: C:\\Users\\William/.ssh/id_rsa RSA SHA256:8zsKHcEa+k0VdidXgBTv1EFBWKNRVBObqFgUVnaITIs
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: C:\\Users\\William/.ssh/id_dsa
debug1: Trying private key: C:\\Users\\William/.ssh/id_ecdsa
debug1: Trying private key: C:\\Users\\William/.ssh/id_ed25519
debug1: Trying private key: C:\\Users\\William/.ssh/id_xmss
debug1: Next authentication method: password
debug1: read_passphrase: can't open /dev/tty: No such file or directory
root@10.181.108.38's password:
debug1: Authentications that can continue: publickey,password
Permission denied, please try again.
debug1: read_passphrase: can't open /dev/tty: No such file or directory
root@10.181.108.38's password:
debug1: Authentications that can continue: publickey,password
Permission denied, please try again.
debug1: read_passphrase: can't open /dev/tty: No such file or directory
root@10.181.108.38's password:
debug1: Enabling compression at level 6.
debug1: Authentication succeeded (password).
Authenticated to 10.181.108.38 ([10.181.108.38]:20004).
debug1: Local connections to *:8888 forwarded to remote address 127.0.0.1:8888
debug1: Local forwarding listening on :: port 8888.
debug1: channel 0: new [port listener]
debug1: Local forwarding listening on 0.0.0.0 port 8888.
debug1: channel 1: new [port listener]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug1: Connection to port 8888 forwarding to 127.0.0.1 port 8888 requested.
debug1: channel 2: new [direct-tcpip]
debug1: Connection to port 8888 forwarding to 127.0.0.1 port 8888 requested.
debug1: channel 3: new [direct-tcpip]
debug1: Connection to port 8888 forwarding to 127.0.0.1 port 8888 requested.
debug1: channel 4: new [direct-tcpip]
debug1: Connection to port 8888 forwarding to 127.0.0.1 port 8888 requested.
debug1: channel 5: new [direct-tcpip]
debug1: Connection to port 8888 forwarding to 127.0.0.1 port 8888 requested.
debug1: channel 6: new [direct-tcpip]
debug1: Connection to port 8888 forwarding to 127.0.0.1 port 8888 requested.
debug1: channel 7: new [direct-tcpip]
debug1: Connection to port 8888 forwarding to 127.0.0.1 port 8888 requested.
debug1: channel 8: new [direct-tcpip]
debug1: channel 2: free: direct-tcpip: listening port 8888 for 127.0.0.1 port 8888, connect from 127.0.0.1 port 1882 to 127.0.0.1 port 8888, nchannels 9
debug1: channel 3: free: direct-tcpip: listening port 8888 for 127.0.0.1 port 8888, connect from 127.0.0.1 port 1883 to 127.0.0.1 port 8888, nchannels 8
debug1: channel 5: free: direct-tcpip: listening port 8888 for 127.0.0.1 port 8888, connect from 127.0.0.1 port 2364 to 127.0.0.1 port 8888, nchannels 7
debug1: channel 7: free: direct-tcpip: listening port 8888 for 127.0.0.1 port 8888, connect from 127.0.0.1 port 2370 to 127.0.0.1 port 8888, nchannels 6

浏览器可正常访问:
在这里插入图片描述

其他的一些参考:Running as root is not recommended. Use --allow-root to bypass._farley li的博客-CSDN博客

如何远程使用服务器上的Jupyter notebook_python_脚本之家 (jb51.net)

如何远程连接linux服务器上的jupyter notebook - 知乎 (zhihu.com)

Linux上配置Jupyter Notebook远程访问_方程无解的博客-CSDN博客

Jupter Notebook远程连接服务器,本地浏览器登录不上_jupyter服务器连不上_Frontier Wildfire的博客-CSDN博客

本地浏览器无法打开远程服务器的jupyter notebook - 代码先锋网 (codeleading.com)

windows远程连接服务器并映射端口访问目标服务_映射远程端口需要publickey_月光晒了很凉快的博客-CSDN博客

eading.com/article/17675200935/)

windows远程连接服务器并映射端口访问目标服务_映射远程端口需要publickey_月光晒了很凉快的博客-CSDN博客

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
您可以通过以下步骤远程连接服务器上的 Jupyter Notebook: 1. 在服务器上安装 Jupyter Notebook。如果您使用的是 Anaconda 发行版,可以运行以下命令安装: ``` conda install jupyter ``` 2. 在服务器上启动 Jupyter Notebook 服务器。在终端中运行以下命令: ``` jupyter notebook --no-browser --port=<PORT> ``` `<PORT>` 是您希望 Jupyter Notebook 服务器监听的端口号。默认端口号为 8888。 3. 在本地计算机上安装 Jupyter Notebook。同样,如果您使用的是 Anaconda 发行版,可以运行以下命令安装: ``` conda install jupyter ``` 4. 在本地计算机上使用 SSH 命令将服务器端口转发到本地。运行以下命令: ``` ssh -N -f -L localhost:<LOCAL_PORT>:localhost:<SERVER_PORT> <USERNAME>@<SERVER_IP> ``` `<LOCAL_PORT>` 是您本地计算机上用于访问 Jupyter Notebook 的端口号,`<SERVER_PORT>` 是服务器Jupyter Notebook 服务器的端口号,`<USERNAME>` 是您在服务器上的用户名,`<SERVER_IP>` 是服务器的 IP 地址。 5. 在本地计算机的浏览器中访问 `localhost:<LOCAL_PORT>`。您将能够通过 Jupyter Notebook 界面远程连接服务器,并在本地计算机上编辑和运行代码。 请注意,为了安全起见,您可能还需要设置密码来保护 Jupyter Notebook 服务器。可以通过运行以下命令在服务器上设置密码: ``` jupyter notebook password ``` 然后,您将被要求输入密码并确认。设置密码后,每次访问 Jupyter Notebook 时都需要输入该密码。 希望这可以帮助到您!如果您有任何其他问题,请随时问我。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

guangyi0404

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值