CentOS和Windows互相远程桌面方法

文章来源:http://blog.csdn.net/zlinsc/article/details/7392545

http://blog.csdn.net/ownfire/article/details/10188117

一、Windows远程CentOS桌面(前提条件是CentOS采用桌面版安装,非最小化安装)
1.VNC
VNC(Virtual Network Computing,虚拟网络计算机)是一种可以对远程计算机进行远程控制的软件,支持linux远程桌面管理,也适合其它操作系统。而putty、SSH等只能进行命令模式的远程管理。
查看本机是否有安装vnc(CentOS 7默认没有安装vnc) 
rpm -q vnc vnc-server
如果显示结果为:
package vnc is not installed
则需要安装。

服务器配置
1) 安装vncserver
[plain]  view plain copy
  1. yum install -y vnc-server  
2) 修改配置
[plain]  view plain copy
  1. vi /etc/sysconfig/vncservers  
最后两行去#,并分别设置如下
Line1: "1:username"
Line2: "... 1024*768 ..."
3) 设置密码
[plain]  view plain copy
  1. vncserver  
4) 修改防火墙
[plain]  view plain copy
  1. vi /etc/sysconfig/iptables  
添加-A INPUT -m state --state NEW -m tcp -p tcp -dport 5901 -j ACCEPT
使用vncserver命令启动VNC服务,命令格式为“vncserver :桌面号”,其中“桌面号”用“数字”的方式表示,每个用户连个需要占用1个桌面。

VNC服务使用的端口号与桌面号相关,VNC使用TCP端口从5900开始,对应关系如下:

桌面号为“1”  ---- 端口号为5901

桌面号为“2”  ---- 端口号为5902

桌面号为“3”  ---- 端口号为5903

……


5) 重启防火墙服务
[plain]  view plain copy
  1. service iptables restart  
6) 重启vnc服务
[plain]  view plain copy
  1. service vncserver restart   
7) ping [客户端ip]
验证连通性

客户端配置
1) 打开vnc客户端,输入ip:5901
2) 输入密码

二、Linux远程Windows桌面
1.rdesktop

客户端配置
1) 安装rdesktop
[plain]  view plain copy
  1. yum install -y rdesktop  
2) 使用rdesktop命令连接到win桌面
[plain]  view plain copy
  1. rdesktop -a 16 x.x.x.x:3389 -u username -p password -f  

服务器配置
1) 开启远程访问
2) 取消防火墙拦截


----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

CentOS7下安装配置vncserver/vncviewer

http://hsuehwee.blog.51cto.com/10114119/1632211

一.安装

  1. 以root用户运行以下命令来安装vncserver;

    yum install tigervnc-server 

  2. 同样运行以下命令来安装vncviewer;

    yum install vnc

  3. 停止并禁用防火墙;

    systemctl stop firewalld.service

    systemctl disable firewalld.service

二.配置

  1. vncviewer基本上不用配置;

  2. vncserver的配置,创建一个新的配置文件,以开启1号窗口为例(也可以同时开启多个窗口,修改数字即可),方法如下:

    cp /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:1.service

    或者再增加一个窗口:

    cp /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:2.service

  3. 编辑/lib/systemd/system/vncserver@:1.service,设置用户root相关参数,最终内容如下

1
2
3
4
5
6
7
8
9
10
[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 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 || :'
  • 上述内容中最好设置为root用户,否则可能会看到以下报错:

1
2
3
4
5
6
7
8
9
10
11
vncserver@:1.service - Remote desktop service (VNC)
    Loaded: loaded ( /usr/lib/systemd/system/vncserver @:1.service; enabled)
    Active: failed (Result:  exit -code) since Tue 2015-04-14 10:09:24 CST; 1min 36s ago
   Process: 3258 ExecStart= /sbin/runuser  -l sysadmin -c  /usr/bin/vncserver  %i (code=exited, status=1 /FAILURE )
   Process: 3254 ExecStartPre= /bin/sh  -c  /usr/bin/vncserver  - kill  %i >  /dev/null  2>&1 || : (code=exited, status=0 /SUCCESS )
Apr 14 10:09:24 F1A-VMHOST-SWPE systemd[1]: Starting Remote desktop service (VNC)...
Apr 14 10:09:24 F1A-VMHOST-SWPE runuser[3258]: Password:
Apr 14 10:09:24 F1A-VMHOST-SWPE systemd[1]: vncserver@:1.service: control process exited, code=exited status=1
Apr 14 10:09:24 F1A-VMHOST-SWPE systemd[1]: Failed to start Remote desktop service (VNC).
Apr 14 10:09:24 F1A-VMHOST-SWPE systemd[1]: Unit vncserver@:1.service entered failed state.
Warning: Unit  file  changed on disk,  'systemctl daemon-reload'  recommended.

三.应用

  1. 更新systemctl以使其生效;

    systemctl daemon-reload 

  2. 设置vncserver的密码;

     vncpasswd root

    按提示输入密码以及确认密码

  3. 启动该服务用来启用vnc的1号窗口;

    systemctl start vncserver@:1.service  或者 vncserver :1

    关闭1号窗口:

    systemctl stop vncserver@:1.service   或者 vncserver -kill :1

  4. 设置为开机自动启动;

    systemctl enable vncserver@:1.service

    End.                            

本文出自 “冯学伟-遇见曾经的妳” 博客,请务必保留此出处http://hsuehwee.blog.51cto.com/10114119/1632211

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Centos7远程桌面 vnc/vnc-server的设置

http://uchase.blog.51cto.com/880483/1545357

Centos7与Centos6.x有了很大的不同。

为了给一台服务器装上远程桌面,走了不少弯路。写这篇博文,纯粹为了记录,以后如果遇到相同问题,可以追溯。

1、假定你的系统没有安装vnc的任何软件,那么,首先安装vnc

1
yum -y  install  tigervnc-server tigervnc

2、Centos7之前的系统,如果安装vnc一般都需要配置

1
2
[root@localhost ~] # cat /etc/sysconfig/vncservers 
# THIS FILE HAS BEEN REPLACED BY /lib/systemd/system/vncserver@.service

但是,如上所述,Centos7需要配置的文件在

1
2
[root@localhost ~] # ll /lib/systemd/system/vncserver@.service
-rw-r--r--. 1 root root 1744 Jun 10 14:15  /lib/systemd/system/vncserver @.service

3、文件内有如下提示

1
2
3
4
5
6
# Quick HowTo:
# 1. Copy this file to /etc/systemd/system/vncserver@:<display>.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


4、复制一份文件,并改名为vncserver@:1.service

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

5、将文件中的<User>用你当前的用户替换,将%i替换为1

1
2
3
4
5
6
7
8
9
10
11
12
[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 :1 > /dev/null 2>&1 || :'
ExecStart= /sbin/runuser  -l root -c  "/usr/bin/vncserver :1 -geometry 1280x720 -depth 24"
PIDFile= /root/ .vnc/%H%i.pid
ExecStop= /bin/sh  -c  '/usr/bin/vncserver -kill :1 > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target

6、更新systemctl

1
systemctl daemon-reload

7、设置为自动启动

1
systemctl  enable  vncserver@:1.service

8、启动vnc服务

1
systemctl start vncserver@:1.service

9、在iptables中加入对应的端口5901(注意,如果有其他用户,那么也需要将端口加上。vnc的端口默认是5900 + n)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@localhost system] # cat /etc/sysconfig/iptables
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 5901 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

注意:

1、如果你不配置和启用防火墙,此时用VNC Viewer连接的话,会报:"connect:Connection timed out(10060)"错误。

2、本文是以root用户为例,如果其他用户也需要登录,那么,还需要将文件复制为

1
cp  /lib/systemd/system/vncserver @.service  /lib/systemd/system/vncserver @:2.service

同时,将文件内的%i改为2,并建立对应用户的vncpasswd。

3、你可以通过UltraVNC,TigerVNC或者RealVNC Viewer进行访问,我在win7下使用这3中工具均能连接

本文出自 “Chase” 博客,请务必保留此出处http://uchase.blog.51cto.com/880483/1545357


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值