Linux Minimal如何实现远程控制
小樊
37
2025-11-20 14:29:30
Linux Minimal 远程控制的实用方案
一、SSH 远程命令行(首选)
- Ubuntu/Debian 系
- 安装与启动:sudo apt update && sudo apt install openssh-server;sudo systemctl start ssh;sudo systemctl enable ssh。
- 获取地址:ip addr;或 hostname -I。
- 连接:ssh 用户名@服务器IP。
- CentOS/RHEL 系
- 安装与启动:sudo yum install openssh-server;sudo systemctl start sshd;sudo systemctl enable sshd。
- 防火墙放行:sudo firewall-cmd --permanent --add-service=ssh;sudo firewall-cmd --reload。
- 连接:ssh 用户名@服务器IP。
- 安全加固要点
- 建议禁用 root 登录与密码登录,改用密钥认证:编辑 /etc/ssh/sshd_config,设置 PermitRootLogin no,PasswordAuthentication no,PubkeyAuthentication yes;重启 sshd;将本机公钥追加到服务器 ~/.ssh/authorized_keys。
二、图形桌面远程 VNC
- 适用:需要在 Minimal 上操作桌面环境(通常需先安装桌面,如 XFCE/GNOME)。
- Ubuntu/Debian 系
- 安装与设密:sudo apt install x11vnc;x11vnc -storepasswd。
- 创建 systemd 服务(示例):/etc/systemd/system/x11vnc.service
- [Unit] Description=Start x11vnc at startup;After=multi-user.target
- [Service] Type=simple;ExecStart=/usr/bin/x11vnc -display :0 -auth /home/your_username/.Xauthority -forever -loop -noxdamage -repeat -rfbauth /home/your_username/.vnc/passwd -rfbport 5900 -shared
- [Install] WantedBy=multi-user.target
- 启用与启动:sudo systemctl enable --now x11vnc.service;客户端用 IP:5900 连接。
- CentOS/RHEL 系
- 安装与设密:sudo yum install tigervnc-server;vncpasswd。
- 配置 systemd 模板:cp /usr/lib/systemd/system/vncserver@.service /etc/systemd/system/;编辑 ExecStart 为 /usr/bin/vncserver -depth 24 -geometry 1920x1080 :%i;User=你的用户名。
- 启用与启动:sudo systemctl daemon-reload;sudo systemctl enable --now vncserver@:1.service;客户端用 IP:5901 连接。
- 防火墙放行:sudo firewall-cmd --permanent --add-port 5901/tcp;sudo firewall-cmd --reload。
三、Windows 远程桌面 RDP(xrdp)
- 安装与启动:sudo apt install xrdp(Debian/Ubuntu);sudo systemctl enable --now xrdp。
- 防火墙放行:sudo ufw allow 3389/tcp(若启用 UFW);或 firewalld 放行 3389/tcp。
- 连接:Windows 使用“远程桌面连接”输入 服务器IP,登录后在 Minimal 上选择已安装的桌面会话(如 XFCE)。
四、安全与网络要点
- 端口与防火墙:SSH 默认 22/TCP,VNC 显示号 N 对应 590N/TCP,RDP 为 3389/TCP;按需放行并更新规则。
- 加固建议:SSH 优先使用密钥登录、禁用 root 与密码;VNC/RDP 设置强密码;云服务器需放行相应安全组端口。
- 端口转发与内网穿透:通过 SSH 本地端口转发安全访问 VNC,例如:ssh -L 6666:127.0.0.1:5901 用户名@服务器IP,然后 VNC 客户端连接 localhost:6666。