在windows里用vs code打开远程 centos 与 ubantu / debian 服务器上日志文件的方法
【安装openssh】
centos 上安装openssh:
# 1. 装 sshd(一般已装) sudo yum install -y openssh-server # 2. 开机自启 + 启动 sudo systemctl enable sshd sudo systemctl start sshd # 3. 防火墙放行 SSH(22端口) sudo firewall-cmd --add-service=ssh --permanent sudo firewall-cmd --reload
ubantu 上安装openssh:
# 安装 openssh-server sudo apt update sudo apt install -y openssh-server # 开机自启 + 启动服务(Ubuntu 统一用 systemd,服务名同样是 ssh) sudo systemctl enable ssh sudo systemctl start ssh # 查看状态(确认正常运行) sudo systemctl status ssh # 允许 SSH 端口 sudo ufw allow ssh # 重载生效(若防火墙已开启) sudo ufw reload # 查看防火墙规则 sudo ufw status
Vs Code 里安装 安装 Remote-SSH 插件(必须)

点【安装】→ 重启 VSCode
【VSCode 连接 CentOS(关键一步)】
按 Ctrl+Shift+P → 输入:Remote-SSH: Connect to Host...
输入:root@你的CentOSIP(例如 root@192.168.1.100)
根据提示,将设置保存到 C:\Users\你的windows登录帐号\.ssh\config
会自动生成配置文件内容:
Host my-centos HostName 192.168.1.100 # 你的 CentOS IP User root Port 22
首次连接:
弹出指纹 → 选【Continue】
输入 root 密码 → 回车
左下角变成 SSH: root@xxx → 连接成功。
如果连不是,打开资源管理器
%APPDATA%\Code\User
打开这前会进到这个目录:C:\Users\Administrator\AppData\Roaming\Code\User
在setting.json里新增配置:
{ "typescript.locale": "zh-CN", "remote.SSH.showLoginTerminal": true, "remote.SSH.useLocalServer": false, "remote.SSH.remotePlatform": { "121.40.209.11": "linux", "121.199.20.176": "linux" }, "remote.SSH.enableDynamicForwarding": false, // 禁止同步所有扩展到远程 "remote.SSH.extensions.localEnabled": false, "settingsSync.ignoredExtensions": [ "*" ], // 关闭自动安装远程扩展 "remote.SSH.installExtensionsAutomatically": false }

如果还连不上,在vs code里查看 Remote-SSH: Show Log 日志,复制日志问ai帮助解决。
VS Code 按 Ctrl+Shift+P,执行:Remote-SSH: Show Log

浙公网安备 33010602011771号