PyCharm如何配置SSH和SFTP连接远程服务器
作者:XerCis 时间:2022-04-27 01:57:28
简介
SSH
,Secure Shell,安全外壳协议,用于远程登录会话SFTP
,Secret File Transfer Protocol,安全文件传送协议,用于同步文件
Windows 连接远程服务器进行 Linux 环境下的 Python 开发需要结合 SSH 和SFTP
安装
安装 PyCharm Professional
PyCharm Community 没有该选项,无法配置 SSH Interpreter
登陆远程服务器
ssh user@host [-p port]
查看是否开启 SSH 服务
service sshd status
如果显示 Loaded: not-found (Reason: No such file or directory) 或 sshd: unrecognized service,则需要安装
sudo apt-get install openssh-server
如果显示 Active: inactive (dead),则需要启动
sudo /etc/init.d/ssh restart
只要 SSHD 服务启动了,SFTP便可使用
Tools → Deployment → Configuration…
→ SFTP → New server name 随意填(如 user@host:port) → 取消勾选 Visible only for this project → SSH configuration →→ 根据 SSH 信息对应填上 → Test Connection
SFTP 这里 Test Connection → Autodetect
File → Settings → Project: xxx → Python Interpreter → 设置 → Add… → SSH Interpreter → Existing server configuration
配置 Python 解释器和同步文件夹,是否用 sudo 权限看情况勾选
初试
main.py
print(__file__)
可能需要手动同步:Tools → Deployment → Upload to…
快捷键:Ctrl + Alt + Shift + X
遇到的坑
1. EOF while reading packet
需要启动 SSHD 服务
2. sudo: unable to resolve host xxx: No such file or directory
sudo vim /etc/hosts
添加
127.0.0.1 localhost xxx
3. vim /etc/hosts 报错 “/etc/hosts” E166: Can’t open linked file for writing
查看真实路径
readlink /etc/hosts
或者把文件删了
4. Can’t get remote credentials for deployment server xxx@xxx:xx password
没填 sudo 的密码,可以重新配,直接 SSH Interpreter → New server configuration
来源:https://xercis.blog.csdn.net/article/details/122682487
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Flask蓝图学习教程
![](https://img.aspxhome.com/file/2023/0/111920_0s.png)
Python实现的石头剪子布代码分享
python Kmeans算法原理深入解析
![](https://img.aspxhome.com/file/2023/8/95548_0s.png)
python画图常规设置方式
![](https://img.aspxhome.com/file/2023/9/130799_0s.jpg)
keras分类模型中的输入数据与标签的维度实例
使用Python制作一个数据预处理小工具(多种操作一键完成)
![](https://img.aspxhome.com/file/2023/8/59828_0s.jpg)
Django发送html邮件的方法
jQuery技巧
VBScript中清除数组元素Erase语句
Python文字截图识别OCR工具实例解析
![](https://img.aspxhome.com/file/2023/0/63920_0s.png)
解决Scrapy安装错误:Microsoft Visual C++ 14.0 is required...
Python如何生成随机高斯模糊图片详解
![](https://img.aspxhome.com/file/2023/1/107061_0s.png)
PHP简单实现HTTP和HTTPS跨域共享session解决办法
利用nohup来开启python文件的方法
MS SQL7.0的数据迁移到MySQL上的一种方法
django框架CSRF防护原理与用法分析
![](https://img.aspxhome.com/file/2023/0/83920_0s.png)
Laravel中间件的使用详解
JavaScript实现图片放大预览效果
![](https://img.aspxhome.com/file/2023/8/56098_0s.png)
Python中unittest的数据驱动详解
![](https://img.aspxhome.com/file/2023/6/66326_0s.png)
matplotlib subplot绘制多个子图的方法示例
![](https://img.aspxhome.com/file/2023/1/128761_0s.png)