Realize windows remote CentOS

Realize windows remote CentOS
transfer from: https://www.cnblogs.com/jhxxb/p/10987058.html
This explanation is very detailed and organized, especially reprinted~

Application scenarios:

For the server CentOS client windows, it is necessary to log in to the CentOS server through the windows remote desktop.

The yum source is used by Ali: https://developer.aliyun.com/mirror/

First execute in CentOS

rm -rf /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

1. (CentOS) Configure the desktop environment

First install the desktop environment, install GNOME here.
Note: If you have installed the GUI when installing CentOS, omit the following steps and go directly to "Two, remote service settings

yum -y groups install "GNOME Desktop"

About desktop environment related commands

#从命令行切换到桌面环境
startx

#获取当前启动模式
systemctl get-default

#修改启动模式为图形化
systemctl set-default graphical.target

#修改启动模式为命令行
systemctl set-default multi-user.target

Automatically log in as root user after starting the desktop environment by default

#修改配置文件 
vi /etc/gdm/custom.conf 
#增加如下配置
AutomaticLoginEnable=True
AutomaticLogin=root

2. (CentOS) remote service settings

#Windows 远程登录需要安装 Xrdp,需要 epel 源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum install -y xrdp

#Xrdp 会调用 VNC,安装 tigervnc-server
yum install -y tigervnc-server

#修改 Xrdp 最大连接数
vim /etc/xrdp/xrdp.ini
max_bpp=32

#启动 Xrdp 并设置开机启动
systemctl start xrdp
systemctl enable xrdp

#开放 3389 端口,或者关闭防火墙
firewall-cmd --permanent --zone=public --add-port=3389/tcp
firewall-cmd --reload
#关闭防火墙
systemctl stop firewalld
#禁止防火墙开机启动
systemctl disable firewalld

At this point, the xrdp method is set up, open the remote desktop of Windows and enter the system user name and password to connect

The second method is described below:

3. (Another solution) VNC login settings

Some settings need to be done to connect and log in with a VNC client

VNC client download: https://www.realvnc.com/en/connect/download/viewer/

#为当前用户设置 VNC 密码,不然服务无法启动。此密码和系统密码不一样,这是使用 vnc viewer 登陆时使用的密码
vncpasswd

#复制服务设置的模板
cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
#修改配置,以 root 用户为例,每个用户都需要单独设置
vim /etc/systemd/system/vncserver@\:1.service

#将 <USER> 换成用户名,[Service] 下增加 User=root
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=forking
User=root

#Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i"
PIDFile=/root/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target

#让服务文件修改生效
systemctl daemon-reload

#启动服务
systemctl start vncserver@:1
#设为开机启动
systemctl enable vncserver@:1

#查看服务端口,用于客户端连接地址
netstat -lnpt|grep Xvnc

#放行连接端口,每个用户端口不同。也可直接关闭防火墙
firewall-cmd --add-port=5901/tcp --permanent
firewall-cmd --reload

–END–

Guess you like

Origin blog.csdn.net/hcqxd/article/details/113989206