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的博客-优快云博客
我在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的博客-优快云博客
如何远程使用服务器上的Jupyter notebook_python_脚本之家 (jb51.net)
如何远程连接linux服务器上的jupyter notebook - 知乎 (zhihu.com)
Linux上配置Jupyter Notebook远程访问_方程无解的博客-优快云博客
Jupter Notebook远程连接服务器,本地浏览器登录不上_jupyter服务器连不上_Frontier Wildfire的博客-优快云博客
本地浏览器无法打开远程服务器的jupyter notebook - 代码先锋网 (codeleading.com)
windows远程连接服务器并映射端口访问目标服务_映射远程端口需要publickey_月光晒了很凉快的博客-优快云博客
eading.com/article/17675200935/)
windows远程连接服务器并映射端口访问目标服务_映射远程端口需要publickey_月光晒了很凉快的博客-优快云博客