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

Ubuntu桌面环境下,如何SSH连接无法直接访问的服务器?

Alright, let's cut through that annoying VM/PuTTY hoopla and get your Ubuntu Desktop (D) connected directly to server S. Dealing with environment mismatches, broken copy-paste, and wonky Alt-Tab is no fun—here are three solid fixes to solve this for good:

方法1:通过Windows虚拟机做SSH跳板(本地端口转发)

Since you can already reach S via your Windows VM, we can use that VM as a middleman to forward SSH traffic from your Ubuntu host. Here's how:

  • First, make sure your Windows VM and Ubuntu desktop are on the same network (use bridge mode or host-only networking in your hypervisor) and can ping each other.
  • On your Ubuntu terminal, run this command to set up local port forwarding:
    ssh -L 2222:S_IP:22 windows_vm_username@windows_vm_ip
    
    Breakdown: -L tells SSH to forward traffic from your Ubuntu's port 2222 to server S's port 22, routed through the Windows VM. Replace the placeholders with your actual VM username/IP and server S's IP.
  • Enter your Windows VM's password when prompted, and keep this terminal window open. Now open a new Ubuntu terminal and connect directly to your local forwarded port:
    ssh s_username@localhost -p 2222
    
    This drops you straight into server S, using Ubuntu's native terminal—copy-paste and Alt-Tab will work like normal.
方法2:配置SSH Config for Persistent, One-Click Access

If you want to skip typing long commands every time, set up your SSH config file to handle the jump automatically:

  • Open your Ubuntu SSH config file in a text editor:
    nano ~/.ssh/config
    
  • Paste in this configuration (replace placeholders with your actual details):
    Host windows-vm
        HostName windows_vm_ip
        User windows_vm_username
    
    Host server-s
        HostName S_IP
        User s_username
        ProxyJump windows-vm
    
  • Save and close the file (Ctrl+O, Enter, then Ctrl+X in nano). Now you can connect to server S with a single command:
    ssh server-s
    
    SSH will automatically connect to your Windows VM first, then jump to server S—all in your native Ubuntu terminal.
方法3:Open Firewall Rules (If You Have Permissions)

The most permanent fix is to bypass the firewall block entirely, if you manage the firewall or server S:

  • On server S (if it uses UFW), allow incoming SSH from your Ubuntu desktop's IP:
    ufw allow from D_IP to any port 22
    
  • If using iptables instead:
    iptables -A INPUT -s D_IP -p tcp --dport 22 -j ACCEPT
    

Once this rule is applied, you can connect directly from Ubuntu to server S with a simple ssh s_username@S_IP—no VM required.

Quick Notes:

  • For method 1/2, make sure your Windows VM has OpenSSH Server enabled (you can install it via Windows Settings > Apps > Optional Features).
  • If your Ubuntu has an older SSH version (pre-7.3), replace ProxyJump with ProxyCommand ssh -W %h:%p windows-vm in the config file.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 09:27:38