1 安装桌面环境
如果桌面环境未安装时,需要提前安装好。已安装请忽略
$ sudo dnf groupinstall "Server with GUI"
2 安装VNC Server
vnc版本号
Xvnc TigerVNC 1.9.0 - built Apr 23 2020 14:52:39
$ sudo dnf install -y tigervnc-server
3 配置VNC登录密码
$ vncpasswd
输入并确认密码
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
A view-only password is not used
4 添加服务并设置开机自启
根据登录用户放到对应的用户目录下
- 创建目录
$ mkdir -p ~/.config/systemd/user
- 复制配置文件
$ cp /usr/lib/systemd/user/vncserver@.service ~/.config/systemd/user/
vncserver@.service
配置文件内容如下
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver %i
ExecStop=/usr/bin/vncserver -kill %i
Restart=on-success
RestartSec=15
[Install]
WantedBy=default.target
- 重新加载配置
$ systemctl --user daemon-reload
- 启动并添加开机自启服务
$ systemctl --user enable vncserver@:1.service --now
- 设置用户服务在系统启动时允许(不是用户登录时)
$ loginctl enable-linger
如果不是当前用户的话,例如设置 zqyu
用户,设置如下
$ loginctl enable-linger zqyu
- 验证运行状态
$ systemctl --user status vncserver@:1.service
运行正常如下
● vncserver@:1.service - Remote desktop service (VNC)
Loaded: loaded (/home/zqyu/.config/systemd/user/vncserver@.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2020-11-19 16:29:17 CST; 21min ago
Process: 2893 ExecStart=/usr/bin/vncserver :1 (code=exited, status=0/SUCCESS)
Process: 2887 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill :1 > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)
Tasks: 242 (limit: 23810)
Memory: 489.1M
CGroup: /user.slice/user-0.slice/user@0.service/vncserver.slice/vncserver@:1.service
.......
5 防火墙开放
$ sudo firewall-cmd --add-service=vnc-server --permanent
$ sudo firewall-cmd --reload
6 待解决
锁屏后重新登录时,出现错误"Authentication failed(认证失败)" ,并一直刷新无法输入的情况,待解决
网友评论