python - 通过 SFTP 连接到 PyCharm 中的部署服务器不起作用
问题描述
PyCharm 2019.3.3 (Build #PY-193.6494.30)
我已经使用登录名和密码配置了SFTP 连接
Mac OS 10.15.3
。当我尝试“测试 SFTP 连接”时,我没有收到任何错误,但“通过 SFTP 连接”循环永远不会超时。每次我重新安装 PyCharm 时,它都会工作 2-3 次,但在那之后,不再建立连接,并且我得到了所描述的连接循环。当我重新安装 PyCharm 时,我确保从 ~/Library 中删除所有相关文件。正在通过 VPN 隧道建立连接。我可以完美地 ssh 到同一个部署地址,只有 PyCharm 无法连接。
我能够从日志中获得以下信息:
2020-03-02 15:22:42,945 [ 17190] DEBUG - t.connections.RemoteConnection - Opening connection to sftp://10.5.166.81:22/ in @6aab2a3e
2020-03-02 15:22:42,970 [ 17215] DEBUG - ntellij.ssh.impl.SshConnection - Failed to create SSH channel using existing SSH sessions, creating new SSH session
2020-03-02 15:22:42,970 [ 17215] DEBUG - ntellij.ssh.impl.SshConnection - Establishing new SSH session to user@10.5.166.81:22
2020-03-02 15:22:43,186 [ 17431] INFO - port.random.BouncyCastleRandom - Generating random seed from SecureRandom.
2020-03-02 15:22:43,603 [ 17848] INFO - z.sshj.transport.TransportImpl - Client identity string: SSH-2.0-SSHJ_0.27.0
2020-03-02 15:22:43,625 [ 17870] INFO - z.sshj.transport.TransportImpl - Server identity string: SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
2020-03-02 15:22:43,821 [ 18066] INFO - om.intellij.ssh.impl.sshj.sshj - Authentication log: SSHJ connection to user@10.5.166.81:22
* With preferred authentications: publickey,keyboard-interactive,password
* With signature factories: ssh-rsa, ssh-dss, ecdsa-sha2-nistp256, ecdsa-sha2-nistp384, ecdsa-sha2-nistp521, ssh-ed25519
* With keep alive interval 300 seconds
* With keep alive count max 1000
* With OpenSshLikeHostKeyVerifier(knownHostsFile=[/Users/user/.ssh/known_hosts], strictHostKeyChecking=ASK, hashKnownHosts=false)
* With predefined password
* With authentications: password by net.schmizz.sshj.userauth.method.AuthPassword, keyboard-interactive by net.schmizz.sshj.userauth.method.AuthKeyboardInteractive
* With socketFactory com.intellij.ssh.sockets.MySftpJavaSocketFactory@630ddfb0
* With connect timeout 10000
* Connected
=> none by net.schmizz.sshj.userauth.method.AuthNone@24b009e5 (failure, new allowed auth methods: publickey, password)
=> password by net.schmizz.sshj.userauth.method.AuthPassword@108e1414 (success)
2020-03-02 15:22:43,825 [ 18070] DEBUG - ntellij.ssh.impl.SshConnection - SSH session @30c953a1 established to user@10.5.166.81:22
2020-03-02 15:22:43,825 [ 18070] DEBUG - ellij.ssh.SshConnectionService - Creating sftp channel within SshjSshConnection(<crc32=zov9y>@<crc32=1djyopl>)@30c953a1
2020-03-02 15:22:44,628 [ 18873] INFO - .channel.direct.SessionChannel - Will request `sftp` subsystem
我通常通过我的私人 ssh 密钥登录,但使用用户+密码登录也可以:
$ ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no 10.5.166.81
The authenticity of host '10.5.166.81 (10.5.166.81)' can't be established.
ECDSA key fingerprint is SHA256:ELdUhvqI6us+QR/CJRwb0u4a+zUcvWLUdZdWeYmhj2s.
Are you sure you want to continue connecting (yes/no)? yes
user@10.5.166.81's password:
Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-46-generic x86_64)
我注意到对于新的部署服务器,PyCharm 有时不会要求我接受 ECDSA 密钥指纹。也许这可能会导致 PyCharm 在等待用户接受从未出现的密钥指纹提示时无休止地尝试“通过 SFTP 连接”。
我不使用 KeX 算法,因此无法使用此处建议的解决方法。
解决方案
我能够解决这个问题。日志表明 sftp 有问题。通过调试输出,sftp -v user@10.5.166.81
我可以看到通过 SSH 的身份验证工作正常,但 sftp 之后会停止。事实证明,我的命令zsh
对~/.bashrc
ssh 会话运行良好,但对 sftp 会话却不行。从 bashrc 中删除此行并改为使用chsh <user> -s /bin/zsh
解决了问题,现在Connecting by SFTP
成功启用。
推荐阅读
- jenkins - 如何将 2 个魅力报告合并在一起?
- python - 使用 numpy 时“解压的值太多”
- azure - Puppeteer 在发布到 Azure 应用服务时不起作用
- scala - 在 Spark 中,如何只对前 N 个频繁值进行一次热编码?
- c# - 如何通过C#删除Excel中的自定义列表
- python - 计算直线的角度(度)
- reactjs - 如何在 JSON 响应中获取空值?
- javascript - `overflow:auto` 不会在移动视图中隐藏滚动条
- python - 用数值替换字符串,同时保留 NaN
- node.js - ExpressJS:对象在发送响应时具有属性值但未到达客户端