xrdp linux 3389 端口,在 Linux 中使用 xrdp - Azure Virtual Machines | Microsoft Docs

您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

安装并配置 xrdp 以在 Ubuntu 上使用远程桌面Install and configure xrdp to use Remote Desktop with Ubuntu

03/03/2021

本文内容

通常使用安全外壳 (SSH) 连接从命令行管理 Azure 中的 Linux 虚拟机 (VM)。Linux virtual machines (VMs) in Azure are usually managed from the command line using a secure shell (SSH) connection. 如果不熟悉 Linux,或者要快速进行故障排除,使用远程桌面可能会更方便。When new to Linux, or for quick troubleshooting scenarios, the use of remote desktop may be easier. 本文详细介绍如何为运行 Ubuntu 的 Linux VM 安装和配置桌面环境 (xfce) 和远程桌面 (xrdp)。This article details how to install and configure a desktop environment (xfce) and remote desktop (xrdp) for your Linux VM running Ubuntu.

本文使用 Ubuntu 18.04 VM 进行编写和测试。The article was writen and tested using an Ubuntu 18.04 VM.

先决条件Prerequisites

本文需要 Azure 中的现有 Ubuntu 18.04 LTS VM。This article requires an existing Ubuntu 18.04 LTS VM in Azure. 如果需要创建 VM,请使用以下方法之一:If you need to create a VM, use one of the following methods:

在 Linux VM 上安装桌面环境Install a desktop environment on your Linux VM

Azure 中的大多数 Linux VM 默认情况下未安装桌面环境。Most Linux VMs in Azure do not have a desktop environment installed by default. 通常使用 SSH 连接(而不是桌面环境)来管理 Linux VM。Linux VMs are commonly managed using SSH connections rather than a desktop environment. Linux 中有各种可以选择的桌面环境。There are various desktop environments in Linux that you can choose. 根据所选的桌面环境,可能会占用 1 到 2 GB 的磁盘空间,并需要 5 到 10 分钟来安装和配置所有所需的包。Depending on your choice of desktop environment, it may consume one to 2 GB of disk space, and take 5 to 10 minutes to install and configure all the required packages.

以下示例在 Ubuntu 18.04 LTS VM 上安装轻型 xfce4 桌面环境。The following example installs the lightweight xfce4 desktop environment on an Ubuntu 18.04 LTS VM. 其他发行版的命令略有不同(例如,使用 yum 在 Red Hat Enterprise Linux 上安装并配置适当的 selinux 规则,或者使用 zypper 在 SUSE 上安装)。Commands for other distributions vary slightly (use yum to install on Red Hat Enterprise Linux and configure appropriate selinux rules, or use zypper to install on SUSE, for example).

首先,通过 SSH 连接到 VM。First, SSH to your VM. 以下示例使用用户名 azureuser 连接到名为 myvm.westus.cloudapp.azure.com 的 VM。The following example connects to the VM named myvm.westus.cloudapp.azure.com with the username of azureuser. 使用自己的值:Use your own values:

ssh azureuser@myvm.westus.cloudapp.azure.com

如果要使用 Windows 并且需要有关使用 SSH 的详细信息,请参阅如何将 SSH 密钥用于 Windows。If you are using Windows and need more information on using SSH, see How to use SSH keys with Windows.

接下来,使用 apt 安装 xfce,如下所示:Next, install xfce using apt as follows:

sudo apt-get update

sudo apt-get -y install xfce4

安装和配置远程桌面服务器Install and configure a remote desktop server

安装桌面环境后,请配置远程桌面服务来侦听传入连接。Now that you have a desktop environment installed, configure a remote desktop service to listen for incoming connections. xrdp 是大多数 Linux 分发版中提供的开源远程桌面协议 (RDP) 服务器,可与 xfce 完美配合。xrdp is an open source Remote Desktop Protocol (RDP) server that is available on most Linux distributions, and works well with xfce. 在 Ubuntu VM 上安装 xrdp,如下所示:Install xrdp on your Ubuntu VM as follows:

sudo apt-get -y install xrdp

sudo systemctl enable xrdp

告诉 xrdp 在启动会话时要使用的桌面环境。Tell xrdp what desktop environment to use when you start your session. 配置 xrdp 以使用 xfce 作为桌面环境,如下所示:Configure xrdp to use xfce as your desktop environment as follows:

echo xfce4-session >~/.xsession

重新启动 xrdp 服务使更改生效,如下所示:Restart the xrdp service for the changes to take effect as follows:

sudo service xrdp restart

设置本地用户帐户密码Set a local user account password

如果在创建 VM 时已为用户帐户创建密码,请跳过此步骤。If you created a password for your user account when you created your VM, skip this step. 如果仅使用 SSH 密钥身份验证,并且未设置本地帐户密码,请在使用 xrdp 之前指定密码以登录到 VM。If you only use SSH key authentication and do not have a local account password set, specify a password before you use xrdp to log in to your VM. xrdp 无法接受使用 SSH 密钥进行身份验证。xrdp cannot accept SSH keys for authentication. 以下示例为用户帐户 azureuser 指定密码:The following example specifies a password for the user account azureuser:

sudo passwd azureuser

备注

指定密码不会将 SSHD 配置更新为允许密码登录(如果当前不允许)。Specifying a password does not update your SSHD configuration to permit password logins if it currently does not. 从安全角度看,可能想要使用基于密钥的身份验证通过 SSH 隧道连接到 VM,并连接到 xrdp。From a security perspective, you may wish to connect to your VM with an SSH tunnel using key-based authentication and then connect to xrdp. 如果是这样,请跳过以下创建网络安全组规则的步骤,以允许远程桌面流量。If so, skip the following step on creating a network security group rule to allow remote desktop traffic.

为远程桌面流量创建网络安全组规则Create a Network Security Group rule for Remote Desktop traffic

若要允许远程桌面流量到达 Linux VM,需要创建网络安全组规则以允许端口 3389 上的 TCP 访问 VM。To allow Remote Desktop traffic to reach your Linux VM, a network security group rule needs to be created that allows TCP on port 3389 to reach your VM. 有关网络安全组规则的详细信息,请参阅什么是网络安全组?For more information about network security group rules, see What is a network security group?

以下示例在端口 3389 上使用 az vm open-port 创建网络安全组规则。The following example creates a network security group rule with az vm open-port on port 3389. 使用 Azure CLI(而不是与 VM 的 SSH 会话),打开以下网络安全组规则:From the Azure CLI, not the SSH session to your VM, open the following network security group rule:

az vm open-port --resource-group myResourceGroup --name myVM --port 3389

使用远程桌面客户端连接 Linux VMConnect your Linux VM with a Remote Desktop client

打开本地的远程桌面客户端,并连接到 Linux VM 的 IP 地址或 DNS 名称。Open your local remote desktop client and connect to the IP address or DNS name of your Linux VM.

a1f8f548892425e9a1f432fc8112554b.png

输入 VM 上的用户帐户的用户名和密码,如下所示:Enter the username and password for the user account on your VM as follows:

2b41ee9eb99056712ab4015f1fff3434.png

进行身份验证后,将加载 xfce 桌面环境,其外观类似于以下示例:After authenticating, the xfce desktop environment will load and look similar to the following example:

d760f1d0e9608aafdff539a28c8f640d.png

如果本地 RDP 客户端使用网络级别身份验证 (NLA),则可能需要禁用该连接设置。If your local RDP client uses network level authentication (NLA), you may need to disable that connection setting. XRDP 目前不支持 NLA。XRDP does not currently support NLA. 还可以考虑其他支持 NLA 的替代 RDP 解决方案,例如 FreeRDP。You can also look at alternative RDP solutions that do support NLA, such as FreeRDP.

疑难解答Troubleshoot

如果无法使用远程桌面客户端连接到 Linux VM,请在 Linux VM上使用 netstat 验证 VM 是否正在侦听 RDP 连接,如下所示:If you cannot connect to your Linux VM using a Remote Desktop client, use netstat on your Linux VM to verify that your VM is listening for RDP connections as follows:

sudo netstat -plnt | grep rdp

以下示例显示正在按预期方式侦听 TCP 端口 3389 的 VM:The following example shows the VM listening on TCP port 3389 as expected:

tcp 0 0 127.0.0.1:3350 0.0.0.0:* LISTEN 53192/xrdp-sesman

tcp 0 0 0.0.0.0:3389 0.0.0.0:* LISTEN 53188/xrdp

如果 xrdp-sesman 服务未在侦听,请在 Ubuntu VM 上重新启动该服务,如下所示:If the xrdp-sesman service is not listening, on an Ubuntu VM restart the service as follows:

sudo service xrdp restart

请查看 Ubuntu VM 上的 /var/log 中的日志,以获得该服务可能未响应的原因的指示。Review logs in /var/log on your Ubuntu VM for indications as to why the service may not be responding. 也可以在远程桌面连接尝试期间监视 syslog 以查看任何错误:You can also monitor the syslog during a remote desktop connection attempt to view any errors:

tail -f /var/log/syslog

其他 Linux 分发(例如,Red Hat Enterprise Linux 和 SUSE)重新启动服务的方式可能有所不同,并且可能需要更换要查看的日志文件位置。Other Linux distributions such as Red Hat Enterprise Linux and SUSE may have different ways to restart services and alternate log file locations to review.

如果用户在远程桌面客户端中未收到任何响应,并且在系统日志中看不到任何事件,则此行为指示远程桌面流量无法到达 VM。If you do not receive any response in your remote desktop client and do not see any events in the system log, this behavior indicates that remote desktop traffic cannot reach the VM. 查看网络安全组规则,以确保有规则允许端口 3389 上的 TCP。Review your network security group rules to ensure that you have a rule to permit TCP on port 3389. 有关详细信息,请参阅排查应用程序连接问题。

后续步骤Next steps

有关为 Linux VM 创建 SSH 密钥和在 Linux VM 上使用 SSH 密钥的详细信息,请参阅在 Azure 中为 Linux VM 创建 SSH 密钥。For more information about creating and using SSH keys with Linux VMs, see Create SSH keys for Linux VMs in Azure.

有关从 Windows 使用 SSH 的信息,请参阅如何在 Windows 中使用 SSH 密钥。For information on using SSH from Windows, see How to use SSH keys with Windows.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
xrdp是一种远程桌面协议,用于在不同操作系统之间实现远程桌面连接。默认情况下,xrdp使用3389端口进行通信。如果需要更改xrdp端口,可以按照以下步骤进行操作: 1. 打开终端或命令提示符,以管理员身份登录系统。 2. 进入xrdp的配置文件所在目录。在大多数Linux发行版,该文件位于/etc/xrdp/目录下。 3. 使用文本编辑器打开xrdp.ini文件。命令可以是“sudo vi /etc/xrdp/xrdp.ini”(如果使用vi编辑器)或“sudo nano /etc/xrdp/xrdp.ini”(如果使用nano编辑器)。 4. 在配置文件寻找“port=-1”的行。-1表示使用默认的3389端口。将该行修改为“port=新端口号”,新端口号可以是1024到65535之间的任意未使用端口。 5. 保存并关闭文件。 6. 重新启动xrdp服务,以使更改生效。在终端,可以执行“sudo systemctl restart xrdp”命令(对于使用systemd管理服务的发行版),或者“sudo service xrdp restart”命令(对于使用init.d管理服务的发行版)。 7. 如果系统有防火墙,还需要相应地更改防火墙规则以允许新端口的通信。具体方法因系统而异。在大多数Linux发行版,可以使用iptables或ufw来进行防火墙配置。 通过以上步骤,就可以成功将xrdp的默认3389端口修改为新的端口号。在实际使用远程桌面连接时,需要确保客户端程序或工具使用端口xrdp的配置一致,以确保连接成功。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值