_Ritchie

windows下远程桌面连接centos

最近,由于项目需要,必须要在centos下进行操作。习惯了图形界面的我,通过黑框框来远程操作服务器,着实让人难受。但是,windows自带的远程桌面工具貌似不能直接连centos。所以,只能借助其他工具来实现这一目的。好了,废话不多说,下面,就把我的成功方案总结一下。
注:centos版本为7,windows版本为8

1.服务器端(centos)

安装组件

yum install -y vnc-server

配置文件

[root@localhost /]# cp /lib/systemd/system/vncserver@:.service /etc/systemd/system/vncserver@:1.service
[root@localhost /]# gedit /etc/systemd/system/vncserver@:1.service

文件vncserver@:1.service的内容:

# The vncserver service unit file
#
# Quick HowTo:
# 1. Copy this file to /etc/systemd/system/vncserver@.service
# 2. Edit <USER> and vncserver parameters appropriately
#   ("runuser -l <USER> -c /usr/bin/vncserver %i -arg1 -arg2")
# 3. Run `systemctl daemon-reload`
# 4. Run `systemctl enable vncserver@:<display>.service`
#
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted!  For a secure way of using VNC, you should
# limit connections to the local host and then tunnel from
# the machine you want to view VNC on (host A) to the machine
# whose VNC output you want to view (host B)
#
# [user@hostA ~]$ ssh -v -C -L 590N:localhost:590M hostB
#
# this will open a connection on port 590N of your hostA to hostB's port 590M
# (in fact, it ssh-connects to hostB and then connects to localhost (on hostB).
# See the ssh man page for details on port forwarding)
#
# You can then point a VNC client on hostA at vncdisplay N of localhost and with
# the help of ssh, you end up seeing what hostB makes available on port 590M
#
# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
#
# Use "-localhost" to prevent remote VNC clients connecting except when
# doing so through a secure tunnel.  See the "-via" option in the
# `man vncviewer' manual page.


[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=/usr/sbin/runuser -l admin -c "/usr/bin/vncserver %i"
PIDFile=/home/admin/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.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=/usr/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 || :'

把这部分中的<User>都改成admin,即远程登录的用户名

重新加载vncserver@:1.service

[root@localhost /]# systemctl daemon-reload

设置密码

[root@localhost /]# vncpasswd

设置开机启动

[root@localhost /]# systemctl enable vncserver@:1.service

启动服务

[root@localhost /]# systemctl start vncserver@:1.service

防火墙设置

关闭防火墙

[root@localhost /]# systemctl stop firewalld

OR
添加端口
这里写图片描述

关闭服务

[root@localhost /]# vncserver -kill :1

2.客户端(windows)

文件下载

vnc views http://www.realvnc.com/download/viewer/

软件配置

这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述

posted on 2015-12-24 20:25  _Ritchie  阅读(836)  评论(0编辑  收藏  举报

导航