多设备协同编码:VSCode Remote-SSH+CPolar 终极解决方案
·
多设备协同编码:VSCode Remote-SSH + CPolar 配置指南
Remote-SSH 配置
安装 VSCode 的 Remote-SSH 扩展,通过 SSH 连接到远程服务器。编辑 ~/.ssh/config 文件,配置主机别名、IP 地址和用户名:
Host my-remote-server
HostName 192.168.1.100
User username
IdentityFile ~/.ssh/id_rsa
连接后可在本地直接编辑远程文件,终端操作也在远程执行。
CPolar 内网穿透配置
下载 CPolar 客户端并注册账号,通过命令行或配置文件启动隧道。例如暴露远程服务器的 SSH 端口(22):
./cpolar tcp 22
获取公网地址(如 tcp://3.tcp.cpolar.cn:12345),替换 HostName 为此外网地址即可实现跨网络访问。
安全优化建议
启用 SSH 密钥认证并禁用密码登录,修改 /etc/ssh/sshd_config:
PasswordAuthentication no
PubkeyAuthentication yes
CPolar 建议设置访问密码,在配置文件中添加:
authtoken: your_token
basic_auth: username:password
性能调优
在 VSCode 的 settings.json 中调整远程开发参数:
"remote.SSH.localServerDownload": "always",
"remote.SSH.remoteServerListenOnSocket": true,
"remote.SSH.lockfilesInTmp": true
CPolar 可启用压缩减少延迟:
compression: true
常见问题排查
连接超时需检查防火墙是否放行 CPolar 端口,SSH 故障可通过 ssh -v 调试。CPolar 日志路径为 ~/cpolar/logs/,流量异常时可限制带宽:
limit_bandwidth: 1MB
更多推荐
所有评论(0)