本文介绍 CentOS7/8
启动 desktop
的方法和启动 VNC(Virtual Network Computing)
服务器,并提供如何使用 teamview
远程 CentOS
桌面。
开启图形界面
CentOS 7
yum groupinstall -y "GNOME Desktop"
yum install -y xorg-x11-apps
KDE
和 GNOME
均提供桌面服务。
systemctl get-default
说明:
- graphical.target 图形桌面模式
- multi-user.target 命令行模式
systemctl set-default graphical.target
systemctl set-default multi-user.target
$ gsettings set org.gnome.desktop.session idle-delay 180
$ gsettings set org.gnome.desktop.screensaver lock-delay 300
$ gsettings set org.gnome.desktop.screensaver lock-enabled true
# 或修改配置文件
$ cat /etc/dconf/db/local.d/00-screensaver
[org/gnome/desktop/session]
idle-delay=uint32 180
[org/gnome/desktop/screensaver]
lock-enabled=true
lock-delay=uint32 300
$ cat /etc/dconf/db/local.d/locks/screensaver
/org/gnome/desktop/session/idle-delay
/org/gnome/desktop/screensaver/lock-enabled
/org/gnome/desktop/screensaver/lock-delay
# 生效
$ dconf update
shutdown -r now
CentOS 8
dnf groupinstall "Server with GUI" -y
systemctl set-default graphical
reboot
Ubuntu
ubuntu安装图形界面
说明
用户家目录的文件夹由 ~/.config/user-dirs.dirs
控制,按照格式(XDG_xxx_DIR="$HOME/yyy
)添加、删除即可定制用户目录。
server 端
安装 vncserver
yum install tigervnc tigervnc-server
使用
$ vncserver --help
usage: vncserver [:<number>] [-name <desktop-name>] [-depth <depth>]
[-geometry <width>x<height>]
[-pixelformat rgbNNN|bgrNNN]
[-fp <font-path>]
[-cc <visual>]
[-fg]
[-autokill]
[-noxstartup]
[-xstartup <file>]
[-fallbacktofreeport]
<Xvnc-options>...
vncserver -kill <X-display>
vncserver -list
$ vncserver :1 -name test-vnc
$ sudo -u xiexianbin -s /bin/bash -c "vncserver :0"
vncserver
的默认端口是 5900
,而远程桌面连接端口号是 5900+n
。如果使用 vncserver :1
命令启动端口是 5901
。
$ vncserver -kill :1
$ sudo -u xiexianbin -s /bin/bash -c "vncserver -kill :1"
$ vncserver -list
TigerVNC server sessions:
X DISPLAY # PROCESS ID
:1 1925
$ sudo -u xiexianbin -s /bin/bash -c "vncserver -list"
$ vncpasswd
client 端
通过 VNC viewers 访问
使用 vnc viewers
远程:ip:5901
远程控制,参考:Windows使用VNC远程登录Centos系统
通过 noVNC 访问
noVNC 远程连接使用教程
xauth
xauth list
FaQ
X11 forwarding request failed on channel 0
$ ssh -v -X <host>
X11 forwarding request failed on channel 0
···
ssh
默认不转发 x11
,修改 /etc/ssh/sshd
:
X11Forwarding yes
或 ipv6
导致:
# AddressFamily any
AddressFamily inet
并重启 sshd 服务:
systemctl restart sshd
并检查是否安装:
yum install -y xorg-x11-xauth
No xauth data; using fake authentication data for X11 forwarding.
$ ssh -X <host>
No xauth data; using fake authentication data for X11 forwarding.
···
# /etc/ssh/ssh_config
Host *
ForwardAgent yes
ForwardX11 yes
ForwardX11Trusted yes
或
# ~/.ssh/config
XAuthLocation /opt/X11/bin/xauth
Host *
ForwardAgent yes
ForwardX11 yes
Bad owner or permissions on ~/.ssh/config
$ ssh -X <host>
Bad owner or permissions on ~/.ssh/config
···
chmod 600 ~/.ssh/config