纷飞的思绪 發表於 2025-11-8 00:00:00

windows使用远程桌面连接连接到CentOS系统

<div id="navCategory"><h5 class="catalogue">目录</h5><ul class="first_class_ul"><li>一、基本概念</li><li>二、安装桌面软件环境&nbsp;</li><li>三、安装配置XRDP</li><li>三、远程连接测试</li><li>四、其它连接方式<ul class="second_class_ul"><li>使用MobaXterm连接</li></ul></li><li>五、注销操作<ul class="second_class_ul"></ul></li><li>常见问题解决<ul class="second_class_ul"><li>1. 连接后黑屏或立即断开</li><li>2. 音频重定向</li><li>3. 剪贴板共享</li><li>4. 多用户支持</li><li>5. 自定义端口</li></ul></li><li>管理命令<ul class="second_class_ul"></ul></li><li>安全建议<ul class="second_class_ul"></ul></li></ul></div><p>xrdp是一个开源的 RDP 服务器,允许你使用 Windows 自带的远程桌面客户端连接到 Linux 系统。在 CentOS 上安装和配置 xrdp后,windows使用远程桌面连接连接到CentOS桌面。</p>
<p class="maodian"></p><h2>一、基本概念</h2>
<p><strong>XRDP</strong>:xrdp提供使用RDP(Microsoft远程桌面协议)的远程计算机的图形登录。xrdp接受来自各种RDP客户端的连接:FreeRDP,rdesktop,NeutrinoRDP和Microsoft远程桌面客户端(适用于Windows,macOS,iOS和Android)。</p>
<p>XRDP官网:</p>
<p class="maodian"></p><h2>二、安装桌面软件环境&nbsp;</h2>
<p>安装 X Window System。</p>
<div class="dxycode"><pre class="brush:plain;">yum groups install "X Window System"</pre></div>
<p>&nbsp;安装 MATE Desktop。</p>
<div class="dxycode"><pre class="brush:plain;">yum groups install "MATE Desktop"</pre></div>
<p>&nbsp;查看已安装是否有GNOME Desktop</p>
<div class="dxycode"><pre class="brush:plain;">yum grouplist</pre></div>
<p>设置默认通过桌面环境启动服务器。</p>
<div class="dxycode"><pre class="brush:plain;">systemctl set-default graphical.target</pre></div>
<p>&nbsp;执行命令 reboot 重启服务器,您也可以在云服务器 ECS 控制台重启服务器。</p>
<p>通过云服务器 ECS 控制台管理终端连接服务器,测试验证安装情况。</p>
<p class="maodian"></p><h2>三、安装配置XRDP</h2>
<p>切换root用户</p>
<div class="dxycode"><pre class="brush:plain;">sudo su - root
</pre></div>
<p>安装epel库</p>
<p>查询是否已经安装epel库:</p>
<div class="dxycode"><pre class="brush:plain;">rpm -qa|grep epel
</pre></div>
<p>如果 epel库 没有安装,则安装它:</p>
<div class="dxycode"><pre class="brush:plain;">yum install epel-release
</pre></div>
<p>安装xrdp</p>
<p>安装xrdp服务:</p>
<div class="dxycode"><pre class="brush:plain;">yum install xrdp
</pre></div>
<p>因为Xrdp最终会自动启用VNC,所以必须安装tigervnc-server,否则xrdp无法使用。</p>
<p>安装vnc</p>
<div class="dxycode"><pre class="brush:plain;">yum install tigervnc-server
</pre></div>
<p>为root用户设置VNC密码:</p>
<div class="dxycode"><pre class="brush:plain;">vncpasswd root
</pre></div>
<p>修改&nbsp;<strong>xrdp最大连接数</strong>(使用默认值,不修改也是可以的) :<code>vim /etc/xrdp/xrdp.ini</code>&nbsp;(默认是32):</p>
<div class="dxycode"><pre class="brush:plain;">max_bpp=32
</pre></div>
<p style="text-align:center"><img alt="安装配置XRDP" src="https://zhuji.jb51.net/uploads/allimg/20251108/1-25110P93955V0.png" /></p>
<p>xrdp最大连接数设置</p>
<p>关闭防火墙</p>
<p>这里,我们要确保两台机器可以ping通,能够相互访问。我这里是在局域网内测试,所以我直接关闭防火墙:</p>
<div class="dxycode"><pre class="brush:plain;">systemctl stop firewalld.service
</pre></div>
<p>设置开机不启动防火墙:</p>
<div class="dxycode"><pre class="brush:plain;">systemctl disable firewalld.servie
</pre></div>
<p>或者不关闭防火墙,打开3389端口命令:</p>
<div class="dxycode"><pre class="brush:plain;">firewall-cmd --permanent --zone=public --add-port=3389/tcp

firewall-cmd --reload</pre></div>
<p>关闭SElinux</p>
<p>SElinux应该关闭它。<strong>查看SElinux状态</strong>:</p>
<div class="dxycode"><pre class="brush:plain;">sestatus
</pre></div>
<p>如果是临时关闭SElinux:</p>
<div class="dxycode"><pre class="brush:plain;">setenforce 0
</pre></div>
<p>不过,我们要永久关闭SElinux:<code>vim /etc/selinux/config</code></p>
<div class="dxycode"><pre class="brush:plain;">SELINUX=disabled
</pre></div>
<p style="text-align:center"><img alt="安装配置XRDP_图2" src="https://zhuji.jb51.net/uploads/allimg/20251108/1-25110P93955641.png" /></p>
<p>永久关闭SELINUX</p>
<p>启动XRDP</p>
<p>启动xrdp服务:</p>
<div class="dxycode"><pre class="brush:plain;">systemctl start xrdp
</pre></div>
<p>设置xrdp服务&nbsp;<strong>开机自启动</strong>&nbsp;:</p>
<div class="dxycode"><pre class="brush:plain;">systemctl enable xrdp
</pre></div>
<p>停止xrdp服务:</p>
<div class="dxycode"><pre class="brush:plain;">systemctl stop xrdp
</pre></div>
<p>检查端口&nbsp;</p>
<div class="dxycode"><pre class="brush:plain;">netstat -antup | grep xrdp</pre></div>
<p>查看xrdp服务运行状态</p>
<div class="dxycode"><pre class="brush:plain;">status xrdp.service</pre></div>
<p class="maodian"></p><h2>三、远程连接测试</h2>
<p style="text-align:center"><img alt="远程连接测试" height="615" src="https://zhuji.jb51.net/uploads/allimg/20251108/1-25110P93955N1.gif" width="800" /></p>
<p>找到windows自带的远程桌面连接:<strong>附件</strong>&nbsp;-&gt;&nbsp;<strong>远程桌面连接</strong>(或者打开&nbsp;<strong>运行</strong>&nbsp;,输入mstsc)</p>
<p style="text-align:center"><img alt="远程连接测试_图2" src="https://zhuji.jb51.net/uploads/allimg/20251108/1-25110P939555L.png" /></p>
<p>远程桌面连接</p>
<p>然后就打开了&nbsp;<strong>远程桌面连接</strong>&nbsp;这个软件,然后输入你想连接的&nbsp;<strong>centos电脑的ip地址</strong>,选择centos上已有的一个&nbsp;<strong>用户名</strong>:</p>
<p style="text-align:center"><img alt="远程连接测试_图3" src="https://zhuji.jb51.net/uploads/allimg/20251108/1-25110P939553c.png" /></p>
<p>图片.png</p>
<p>然后输入&nbsp;<strong>vnc密码:</strong></p>
<p style="text-align:center"><img alt="远程连接测试_图4" src="https://zhuji.jb51.net/uploads/allimg/20251108/1-25110P93955516.png" /></p>
<p>vnc密码</p>
<p>这时,就看到了远程桌面了,这个界面和物理主机上看到的一样:</p>
<p style="text-align:center"><img alt="远程连接测试_图5" src="https://zhuji.jb51.net/uploads/allimg/20251108/1-25110P9395E25.png" /></p>
<p>远程桌面</p>
<p>不过你会发现,本地主机win7和远程centos之间,<strong>不能进行粘贴复制</strong>。这是mstsc功能不足导致的,后面使用MobaXterm连接可以解决这个问题。</p>
<p class="maodian"></p><h2>四、其它连接方式</h2>
<p class="maodian"></p><h3>使用MobaXterm连接</h3>
<p>MobaXterm 这个软件,在这里&nbsp;<strong>相当于</strong>&nbsp;win7自带的&nbsp;<strong>远程桌面软件</strong>&nbsp;mstsc 。使用MobaXterm替代mstsc的好处是,可以进行&nbsp;<strong>粘贴复制</strong>&nbsp;操作。也就是win7复制,直接可以粘贴到Centos上,或者Centos复制直接粘贴到win7上。</p>
<p>打开&nbsp;<strong>Session</strong>&nbsp;-&gt;&nbsp;<strong>RDP</strong>&nbsp;,输入将要远程操控的主机IP,以及可用的用户,端口默认是<strong>3389</strong>&nbsp;:</p>
<p style="text-align:center"><img alt="使用MobaXterm连接" src="https://zhuji.jb51.net/uploads/allimg/20251108/1-25110P9395C53.png" /></p>
<p>打开MobaXterm</p>
<p>点击&nbsp;<strong>OK</strong>,接下来输入密码登录即可。在点击全屏显示时,如果你希望&nbsp;<strong>高清全屏显示</strong>,MobaXterm连接前,<strong>选中一个会话右键,编辑会话(edit session) -&gt; 高级设置(advanced) -&gt; 显示(display)</strong>&nbsp;设置合理的分辨率。一般是&nbsp;<code>1920x1080</code>&nbsp;,根据远程桌面的分辨率而定。</p>
<p style="text-align:center"><img alt="使用MobaXterm连接_图2" src="https://zhuji.jb51.net/uploads/allimg/20251108/1-25110P9395C64.png" /></p>
<p>高清显示设置</p>
<p class="maodian"></p><h2>五、注销操作</h2>
<p>如果直接关闭MobaXterm,远程桌面还是没有注销的,用户还在&nbsp;<strong>占用Centos资源</strong>。所以,当你&nbsp;<strong>不用了的时候</strong>,记得&nbsp;<strong>进行注销操作</strong>,以减少远程主机的开销:</p>
<p style="text-align:center"><img alt="注销操作" src="https://zhuji.jb51.net/uploads/allimg/20251108/1-25110P9395C17.png" /></p>
<p>注销</p>
<p class="maodian"></p><h2>常见问题解决</h2>
<p class="maodian"></p><h3>1. 连接后黑屏或立即断开</h3>
<p>创建 xrdp 启动脚本:</p>
<div class="dxycode"><pre class="brush:xhtml">sudo vi /etc/xrdp/startwm.sh</pre></div>
<p>内容如下:</p>
<div class="dxycode"><pre class="brush:xhtml">#!/bin/sh
# 在文件开头添加
unset DBUS_SESSION_BUS_ADDRESS
unset XDG_RUNTIME_DIR

if [ -r /etc/profile ]; then
    . /etc/profile
fi

if [ -r ~/.bash_profile ]; then
    . ~/.bash_profile
else
    if [ -r ~/.bash_login ]; then
      . ~-.bash_login
    else
      if [ -r ~/.profile ]; then
            . ~/.profile
      fi
    fi
fi

# 启动 GNOME
exec gnome-session</pre></div>
<p>设置执行权限:</p>
<div class="dxycode"><pre class="brush:xhtml">sudo chmod +x /etc/xrdp/startwm.sh</pre></div>
<p class="maodian"></p><h3>2. 音频重定向</h3>
<p>安装音频支持:</p>
<div class="dxycode"><pre class="brush:xhtml">sudo yum install pulseaudio -y</pre></div>
<p class="maodian"></p><h3>3. 剪贴板共享</h3>
<p>确保安装了相关的插件:</p>
<div class="dxycode"><pre class="brush:xhtml">sudo yum install xrdp-pulseaudio-installer -y</pre></div>
<p class="maodian"></p><h3>4. 多用户支持</h3>
<p>xrdp 默认支持多用户同时登录,每个用户会获得独立的会话。</p>
<p class="maodian"></p><h3>5. 自定义端口</h3>
<p>如需更改默认端口,编辑配置文件:</p>
<div class="dxycode"><pre class="brush:xhtml">sudo vi /etc/xrdp/xrdp.ini</pre></div>
<p>找到&nbsp;<code>port=3389</code>&nbsp;更改为其他端口,如&nbsp;<code>port=3390</code>,然后重启服务:</p>
<div class="dxycode"><pre class="brush:xhtml">sudo systemctl restart xrdp
sudo firewall-cmd --permanent --add-port=3390/tcp
sudo firewall-cmd --reload</pre></div>
<p class="maodian"></p><h2>管理命令</h2>
<div class="dxycode"><pre class="brush:xhtml"># 重启 xrdp 服务
sudo systemctl restart xrdp

# 停止 xrdp 服务
sudo systemctl stop xrdp

# 查看服务状态
sudo systemctl status xrdp

# 查看日志
sudo tail -f /var/log/xrdp-sesman.log
sudo tail -f /var/log/xrdp.log</pre></div>
<p class="maodian"></p><h2>安全建议</h2>
<blockquote><p>使用强密码</p>
<p>考虑更改默认端口</p>
<p>使用防火墙限制访问 IP</p>
<p>或通过 SSH 隧道连接:</p></blockquote>

<div class="dxycode"><pre class="brush:xhtml"># 在 Windows 上使用 PuTTY 建立隧道
# 或将以下命令添加到本地 ~/.ssh/config
Host centos-rdp
    HostName your_centos_ip
    User your_username
    LocalForward 33389 localhost:3389</pre></div>
<p>然后连接&nbsp;<code>localhost:33389</code></p>
<p>xrdp 提供了一个相对稳定和兼容的解决方案,让 Windows 用户能够无缝地远程访问 CentOS 桌面环境。</p>
<p>以上就是远程连接&mdash;&mdash;Windows远程连接CentOS远程桌面的详细内容,更多相关资料请阅读琼殿技术社区其它文章!</p>
頁: [1]
查看完整版本: windows使用远程桌面连接连接到CentOS系统