Linux的远程桌面配置

一、Ubuntu的远程桌面

Ubuntu默认已安装好VNC服务端组件vino-server,只需要在“系统设置->首选项->桌面共享”中设置即可。

1、设置桌面共享首选项

Linux的远程桌面配置

2、设置好之后,可查看启动的VNC服务进程

[[email protected]]$ sudo netstat -altunp | grep 590
tcp   0 0   0.0.0.0:5900 0.0.0.0:*   LISTEN 4652/vino-server 
tcp6 0 0    :::5900          :::*        LISTEN 4652/vino-server

二、CentOS6.x的远程桌面

CentOS的远程桌面配置VNC比Ubuntu要稍复杂一些,需要在默认需要任务安装VNC服务端软件,如:tigervnc-server。安装和配置步骤如下:

1、挂载安装光盘作为软件源

[[email protected]]# vim /etc/yum.repos.d/CentOS-Media.repo

[c6-media]
name=CentOS-$releasever - Media
**baseurl=file:///media/CentOS_6.7_Final/**
file:///media/cdrom/
file:///media/cdrecorder/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

[[email protected]]# yum --disablerepo=\* --enablerepo=c6-media update

2、安装VNC服务端

[[email protected]]# yum --disablerepo=\* --enablerepo=c6-media install tigervnc-server tigervnc

3、编辑VNC服务端配置文件

[[email protected]]# vim /etc/sysconfig/vncservers     //配置如下

VNCSERVERS="1:cb"         //服务监听端口: 5900+1, 用户:cb
VNCSERVERARGS[2]="-geometry 1024x768 -nolisten tcp -localhost" //分辨率1024x768, X到vncser不使用tcp连接

4、设置VNC客户端登录密码

[[email protected]]$ vncpasswd
password: *****
verify: *****

5、VNC服务启动/重启/关闭/查看状态

[[email protected]]# /etc/init.d/vncserver start/restart/stop/status

6、配置开机启动VNC服务

[[email protected]]# chkconfig vncserver --level 345 on

重启就OK。

三、CentOS7.x的远程桌面

CentOS 7.x用systemd替换了之前版本采用的init初始化程序,systemd接管了很多初始化过程,包括系统服务的管理,所以方法和以前不一样。
当然安装VNC服务器软件和步骤1、2是一样的,不再赘述。从第3步开始:

3、编辑VNC服务端配置文件

[[email protected]]# cp /lib/systemd/system/[email protected] /etc/systemd/system/[email protected]:1.service
[[email protected]]# vim /etc/systemd/system/[email protected]:1.service

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

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

[Install]
WantedBy=multi-user.target

修改方法:将所有<USER>改成VNC客户端连接的用户名, 所有%i改成 :1(VNC服务器端监听5901端口)

4、设置VNC客户端登录密码

[[email protected]]$ vncpasswd
password: *****
verify: *****

5、开放防火墙VNC服务端口

[[email protected] 桌面]# firewall-cmd --state
running

[[email protected] 桌面]# firewall-cmd --zone=public --add-port=5900/tcp --permanent
success
[[email protected] 桌面]# firewall-cmd --zone=public --add-port=5901/tcp --permanent
success
[[email protected] 桌面]# firewall-cmd --reload
success
[[email protected] 桌面]# firewall-cmd --zone=public --list-ports
5900/tcp 5901/tcp

6、配置开机启动VNC服务

[[email protected]]# systemctl systemctl daemon-reload
[[email protected]]# systemctl enable [email protected]:1.service //设置开机启动VNC服务
[[email protected]]# systemctl start [email protected]:1.service //启动VNC服务,监听在5901端口

OK !

四、VNC客户端连接远程桌面

1、Ubuntu Linux

对于用Ubuntu,只需要用“互联网->Remmina远程桌面客户端”就能连接CentOS的桌面,设置如下:
Linux的远程桌面配置

2、Windows

用Vncviewer等vnc客户端软件都可以(略)。

注:以上在CentOS 6.7和Ubuntu 14.04下测试通过。