python - 在 PyCharm 中通过 SFTP 连接到部署服务器不起作用

标签 python debugging deployment pycharm

我已使用登录名和密码配置了 SFTP 连接 Mac OS 10.15.3 上的 PyCharm 2019.3.3(内部版本 #PY-193.6494.30)。当我尝试“测试 SFTP 连接”时,没有收到任何错误,但出现“通过 SFTP 连接”循环,永不超时。每次我重新安装 PyCharm 时,它都会工作 2-3 次,但之后就不再建立连接,并且我会出现所描述的连接循环。当我重新安装 PyCharm 时,我确保从 ~/Library 中删除所有相关文件。正在通过 VPN 隧道建立连接。我可以完美地 ssh 到相同的部署地址,只有 PyCharm 无法连接。

enter image description here

我能够从日志中获取以下内容:

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 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6c191f091e2c5d5c4259425d5a5a42545d" rel="noreferrer noopener nofollow">[email protected]</a>: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 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="42373127300273726c776c7374746c7a73" rel="noreferrer noopener nofollow">[email protected]</a>: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 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ec999f899eacdddcc2d9c2dddadac2d4dd" rel="noreferrer noopener nofollow">[email protected]</a>: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 

我通常通过我的私有(private) ssh key 登录,但使用用户名+密码登录也可以:

$ 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
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e99c9a8c9ba9d8d9c7dcc7d8dfdfc7d1d8" rel="noreferrer noopener nofollow">[email protected]</a>'s password:
Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-46-generic x86_64)

我注意到,对于新的部署服务器,PyCharm 有时不会要求我接受 ECDSA key 指纹。也许这可能会导致 PyCharm 在等待用户接受从未出现的 key 指纹提示时无休止地尝试“通过 SFTP 连接”。

我不使用 KeX 算法,因此建议的解决方法 here无法使用。

最佳答案

我能够解决这个问题。日志表明 sftp 出现问题。通过调试sftp -v <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="65101600172554554b504b5453534b5d54" rel="noreferrer noopener nofollow">[email protected]</a>的输出我可以看到通过 SSH 进行的身份验证工作正常,但 sftp 之后会停止。事实证明,我有命令 zsh在我的~/.bashrc这对于 ssh session 效果很好,但对于 sftp session 则不然。从 bashrc 中删除这一行并改为使用 chsh <user> -s /bin/zsh解决了问题,现在启用 Connecting by SFTP成功。

关于python - 在 PyCharm 中通过 SFTP 连接到部署服务器不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60490921/

相关文章:

python - 是否有一种矢量化的方式来访问另一列中明确指示的列的值?

debugging - 无法在 IntelliJ 中调试 Go 应用程序

来自编译器的c++类型错误消息,这是什么意思?

java - jboss 服务器上的 war 部署失败

python - 用相关列的平均值替换数据框中的 NaN 值的函数

python - 带 flask 的服务图像

python - 基于 URL 为文件创建文件名的明智方法?

debugging - 未找到 Visual Studio Code 中 'Debug: evaluate' 的 CommandID

Firebase 托管删除的部署占用空间

php - 使用 git 进行部署与发送 .tar.gz 相比有什么明显的优势吗?