---
title: "Linux学习一 —— vnc远程学习"
author: "cooliufang"
date: "2012-11-01T16:11:51Z"
tags: ["Linux", "SSH", "vnc"]
categories: ["操作系统"]
slug: "linux-vnc"
draft: false
lastmod: "2012-11-01T16:11:51Z"
id: 1711521
url: "https://smallwildpig.iteye.com/blog/1711521"
---

vnc安装

```shell
[root@sc-026 ~]# yum install vnc
```


vnc远程连接
首先ssh登录到远程机器上，用命令vncserver为当前用户开放一个端口
退出后，在利用命令vncviewer连接到远程机器上，就可以进行各种操作。

```shell
[root@sc-026 ~]# ssh 192.168.15.182
root@192.168.15.182's password: 
Last login: Sat Oct 27 00:30:02 2012 from sfserver20.localdomain
```


远程机器开端口

```shell
[root@sfserver20 ~]# vncserver -geometry 1600x900 :3

New 'sfserver20.localdomain:3 (root)' desktop is sfserver20.localdomain:3

Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/sfserver20.localdomain:3.log
```


关闭端口

```shell
[root@sfserver20 ~]# vncserver -kill :3
Killing Xvnc process ID 29665
```


如果登录想看到桌面形式，需要修改一下文件

```shell
[root@sfserver20 ~]# vim .vnc/xstartup 
```

最后一行注释掉，再新增加一行如下：
#twm &			//注释掉
gnome-session &		//表示远程用户登录Linux的GNOME桌面
或startkde &		//表示远程用户登录Linux的KDE桌面，不如上一次效果好

退出，从端口进入：

```shell
[root@sfserver20 ~]# exit
[root@sc-026 ~]# vncviewer 192.168.15.182:3

VNC Viewer Free Edition 4.1.2 for X - built Jul 27 2010 10:24:13
Copyright (C) 2002-2005 RealVNC Ltd.
See http://www.realvnc.com for information on VNC.

Thu Nov  1 15:54:10 2012
 CConn:       connected to host 192.168.15.182 port 5903
 CConnection: Server supports RFB protocol version 3.8
 CConnection: Using RFB protocol version 3.8
```


出现以下界面，输入密码即可以桌面形式登陆到远程机器上。
![](http://dl.iteye.com/upload/attachment/0075/9534/4c4812d1-a8c4-3b6a-87b1-39e65b22e7ba.jpg)