在 Debian 虚拟机中进行远程控制的实用方案
一、前置准备与网络连通
hostname -I 或 ip addr showping <虚拟机IP>sudo ufw allow 22(SSH)、sudo ufw allow 3389(RDP)、sudo ufw allow 5901(VNC)sudo firewall-cmd --add-port=22/tcp --permanent && sudo firewall-cmd --reload二、方案一 SSH 远程登录(命令行首选)
sudo apt update && sudo apt install -y openssh-serversudo systemctl start ssh && sudo systemctl enable sshhostname -Issh <用户名>@<虚拟机IP> -p 22<虚拟机IP>,Port 填 22/etc/ssh/sshd_config,设 PermitRootLogin no,重启 sudo systemctl restart sshssh-keygen 生成密钥,ssh-copy-id <用户名>@<虚拟机IP> 部署公钥,随后可禁用密码登录三、方案二 图形桌面远程桌面
sudo apt update && sudo apt install -y tightvncserver xfce4vncserver :1,会生成显示号 :1(端口 5901)sudo nano /etc/systemd/system/vncserver@:1.service[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
User=debian
Group=debian
WorkingDirectory=/home/debian
ExecStartPre=/usr/bin/vncserver -kill :%i
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%i
ExecStop=/usr/bin/vncserver -kill :%i
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload && sudo systemctl enable --now vncserver@:1.service<虚拟机IP>:5901sudo apt update && sudo apt install -y xrdpsudo systemctl enable --now xrdp<虚拟机IP>:3389,登录使用系统账户凭据四、方案三 安全增强与常见问题
ssh -L 5901:localhost:5901 <用户名>@<虚拟机IP>localhost:5901(隧道将流量安全转发至虚拟机 5901 端口)~/.vnc/xstartup 是否启动了桌面环境(如 startxfce4 &)xrdp 服务运行且系统会话可用,必要时重启 sudo systemctl restart xrdp.deb 包后按向导配置