CentOS和Windows互相远程桌面方法

首先安装tigervnc-server:

yum install tigervnc-server

安装好后,设置 vi /etc/sysconfig/vncservers

[root@gateway-001 ~]# cat /etc/sysconfig/vncservers
# The VNCSERVERS variable is a list of display:user pairs.
#
# Uncomment the lines below to start a VNC server on display :2
# as my 'myusername' (adjust this to your own).  You will also
# need to set a VNC password; run 'man vncpasswd' to see how
# to do that. 
#
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted!  For a secure way of using VNC, see this URL:
# https://access.redhat.com/knowledge/solutions/7027

# 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.

VNCSERVERS="1:root"
VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -localhost"
VNCSERVERS="2:work"
VNCSERVERARGS[2]="-geometry 1024x768  -nolisten tcp -localhost"

service vncserver start

切换到work用户,设置vncpasswd

在服务器上可以看到打开的vnc端口:

在windows上安装viewvnc,输入ip地址和端口号进行连接:

/etc/sysconfig/iptables

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 6000:6010 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 177 -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited



COMMIT

关闭防火墙: /etc/init.d/iptables stop 使用root账号

一、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 plaincopy
 
 
  1. yum install -y vnc-server  
2) 修改配置
[plain]  view plaincopy
 
 
  1. vi /etc/sysconfig/vncservers  
最后两行去#,并分别设置如下
Line1: "1:username"
Line2: "... 1024*768 ..."
3) 设置密码
[plain]  view plaincopy
 
 
  1. vncserver  
4) 修改防火墙
[plain]  view plaincopy
 
 
  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 plaincopy
 
 
  1. service iptables restart  
6) 重启vnc服务
[plain]  view plaincopy
 
 
  1. service vncserver restart   
7) ping [客户端ip]
验证连通性
 
客户端配置
1) 打开vnc客户端,输入ip:5901
2) 输入密码
 
二、Linux远程Windows桌面
1.rdesktop
 
客户端配置
1) 安装rdesktop
[plain]  view plaincopy
 
 
  1. yum install -y rdesktop  
2) 使用rdesktop命令连接到win桌面
[plain]  view plaincopy
 
 
  1. rdesktop -a 16 x.x.x.x:3389 -u username -p password -f  
服务器配置
1) 开启远程访问
2) 取消防火墙拦截
 
 

1、安装VNC

yum install vnc-server

2、添加多个用户用户

useradd user1  //添加用户user1

passwd user1  //设置用户的linux登录密码

su user1          //切换到用户user1

vncpasswd      //设置用户的user1登录密码

exit

useradd user2  //添加用户user2

passwd user2  //设置用户的linux登录密码

su user2        //切换到用户user2

vncpasswd    //设置用户的user2登录密码

exit

3、编辑vnc配置文件

vi /etc/sysconfig/vncservers

在最后加上:

VNCSERVERS="1:user1 2:user2"

VNCSERVERSVNCSERVERARGS[1]="-geometry 1024x768 -alwaysshared" 

VNCSERVERSVNCSERVERARGS[2]="-geometry 1024x768 -alwaysshared"

注意:-geometry 1024x768表示分辨率;-alwaysshared 表示允许多终端同时登陆

4、打开对应的端口打开5901至5902 端口用于vnc  //如果需要配置更多的桌面,增加端口即可

iptables -I INPUT -p tcp --dport 5901:5902 -j ACCEPT

iptables -A INPUT -p tcp --dport 5901:5902 -j ACCEPT

永久保存

service iptables save

4.启动vncserver服务

1)启动全部桌面

  service vncserver start

2)启动某一桌面

  vncserver :1  //这里1表示第一个桌面

5、停止vncserver服务1)停止全部桌面

  service vncserver stop

2) 停止某一桌面

    vncserver -kill :1  //停止第1个界面,要用kill命令来杀掉界面1的进程

6、查看当前有几个桌面在运行    service vncserver status

7、让vncserver服务随机启动默认状态下,vncserver服务不是开机自动启动,需要手工启动。

chkconfig --list vncserver

chkconfig vncserver on

保存后,重启测试。

8.客户端登录vncserver服务(1)先安装vncviewer来远程登录,

(2)然后在地址栏输入“主机地址:1”(即主机IP加界面号的方式)

9、开机自动启动vncserver

# chkconfig vncserver on

 查看是否设置成功

10、关闭自动启动

# chkconfig vncserver off

查看是否关闭自动启动

猜你喜欢

转载自ssydxa219.iteye.com/blog/2417273