You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Windows IDE访问Ubuntu AWS EC2实例代码?替代CLI方案

解决方案:用Windows本地IDE远程访问Ubuntu EC2实例代码

Absolutely, there are several practical ways to ditch the single CLI terminal and use your Windows-based IDE to work with code on your Ubuntu EC2 instance—perfect for when you need to handle multiple files/folders without the hassle. Let’s walk through the best options:

1. 利用IDE原生的远程开发功能(首推VS Code)

Most modern IDEs have built-in or plugin-based support for remote SSH connections, and VS Code's Remote-SSH extension is the most popular choice here. Here's how to set it up:

  • First, ensure your EC2 instance's SSH server is running (it’s enabled by default on Ubuntu EC2 instances, but you can confirm with sudo systemctl status sshd).
  • If you’re using a PuTTY .ppk key, convert it to OpenSSH format first:
    1. Open PuTTYgen, load your .ppk file.
    2. Go to Conversions > Export OpenSSH Key and save it as a .pem or .key file (remember the file path!).
  • Install the Remote - SSH extension in VS Code.
  • Open the command palette (Ctrl+Shift+P) and select Remote-SSH: Connect to Host... > Add New SSH Host.
  • Enter the SSH command: ssh ubuntu@[your-ec2-public-ip] -i [path-to-your-converted-openssh-key]
  • Save the configuration when prompted, then select the new host to connect.

Once connected, you can open any folder on the EC2 instance directly in VS Code—edit files, run commands via the integrated terminal, and even debug code just like you would locally. No more switching between PuTTy windows!

2. 挂载EC2文件系统到Windows本地

If you prefer to treat the EC2 instance's files like a local folder, use SSHFS to mount the remote filesystem:

  • Install two tools on Windows: WinFsp (a Windows filesystem provider) and SSHFS-Win.
  • After installation, open File Explorer and enter this in the address bar:
    \\sshfs\ubuntu@[your-ec2-public-ip]\home\ubuntu
    
  • When prompted, select your converted OpenSSH key (or enter your EC2 user password if you use password auth, though key-based is recommended).

Once mounted, your Windows IDE can access the EC2 files exactly like local files—open, edit, save, and run them without leaving your IDE. Just note that performance depends on your network speed.

3. 远程桌面(RDP)访问EC2实例(适合需要图形界面的场景)

If you want a full remote desktop experience (like using the EC2 instance as a local machine), set up RDP on your Ubuntu instance:

  • SSH into your EC2 instance via PuTTy, then run these commands to install a lightweight desktop environment and RDP server:
    sudo apt update && sudo apt install xfce4 xfce4-goodies xrdp
    sudo systemctl enable xrdp
    sudo systemctl start xrdp
    
  • Go to your EC2 security group settings and add an inbound rule allowing RDP (3389) from your Windows machine's IP address.
  • Open Windows Remote Desktop Connection, enter your EC2 instance's public IP, and log in with your Ubuntu username (default is ubuntu) and password (or use key auth if configured).

Once logged in, you can use a GUI IDE directly on the EC2 instance, or access the filesystem through the desktop to work with your code. This is heavier than the first two options, but great if you need graphical tools alongside your code.

Important Notes

  • Always secure your EC2 instance: Restrict inbound SSH/RDP access to only your Windows machine's IP address in the security group.
  • Keep your instance's packages updated with sudo apt update && sudo apt upgrade to avoid security risks.
  • Key-based authentication is always more secure than password auth—stick with it whenever possible.

内容的提问来源于stack exchange,提问作者Sandeep Gupta

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:46:13