vscode连接远程服务器,实现python代码本地修改
2021-06-30 本文已影响0人
JLGao的简书
实现vscode远程连接服务器,只需要简单的两步
- SSH远程登录服务器
- 使用VSCODE连接远程服务器
一、SSH远程登录服务器
有两种登录方式:一种是密码登录,一个是公钥登录。
1、密码登录
# ssh hostname@ip
ssh tb@192.168.1.1

输入密码,就可以登录到远程服务器。但是,这种方法登录,每次需要输入密码,比较麻烦。
2、公钥登录
(1)在本机生成密钥对
ssh-keygen -t rsa

按照提示按enter键即可(其中有一个提示是要求设置私钥口令passphrase,不设置则为空),执行结束以后会在/home/***/.ssh文件夹中生成私钥文件id_rsa和公钥文件 id_rsa.pub。
(2) 将公钥复制到远程主机中
# ssh-copy-id hostname@ip
ssh-copy-id tb@192.168.1.1

然后登录远程服务器,就不用输入密码了。(如果在生成密钥对时,设置了私钥口令passphrase,在登录时需要输入passphrase)
二、使用vscode连接远程服务器
安装插件remote-SSH和python

重启VSCODE,点击左下角中绿色的选项

添加远程服务器。按照格式“ssh://hostname:pwd@远程服务器ip”添加服务器信息。

选择远程服务器保存在本地主机的路径。

查看保存的信息:
cd /home/user/.ssh
gedit config


然后,就在本地的VSCODE修改服务器中的代码吧。
