个人工具

“UbuntuHelp:VNC”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
第1行: 第1行:
 
{{From|https://help.ubuntu.com/community/VNC}}
 
{{From|https://help.ubuntu.com/community/VNC}}
 
{{Languages|UbuntuHelp:VNC}}
 
{{Languages|UbuntuHelp:VNC}}
Virtual Network Computing (VNC) allows a computer to be seen and accessed remotely from other computers, who can see the screen and control the system using the keyboard and mouse.
+
<<Include(Tag/TooLong)>>
VNC is useful for remote technical support or remote access to personal/work computers.
+
VNC is a protocol that allows a desktop to be viewed and controlled remotely over the Internet. To use VNC, you need to run a '''VNC server''' on the computer sharing a destkop, and a '''VNC client''' on the computer accessing the shared desktop. VNC is a widely useful tool, although you'll need to do some work to set it up for your particular use case.
<u>tip</u>: If you need to access a Mac remotely, read [[UbuntuWiki:AppleRemoteDesktop|Apple Remote Desktop]] instead.
+
This page will discuss some common uses for VNC, present programs you can use to solve your particular problem, and then guide you through some example scenarios. You may want to [[UbuntuHelp:[guide|skip straight to the examples]]].
== Terminology ==
+
== Common uses ==
VNC Server = the computer you will connect to (log onto remotely).
+
The two most common uses for VNC are to control your own desktop from another computer and to let other people view your desktop while you're sitting at it.
VNC Client = the computer you will connect with (use to log on to a server).
+
=== Accessing your desktop over the Internet ===
With the default vnc server (vino) or x11vnc you will log into a shared desktop. With tightvnc server or with configuration of GDM you will have a separate session.
+
Although VNC has some optional security features, you should not run VNC directly over an untrusted network like the Internet. Instead, you should set an SSH server up as discussed in the [[UbuntuHelp:SSHHowto|SSH guide]] and configure a VNC server that you can start in so-called '''once''' mode, as described belowWhen you have set up your SSH and VNC servers, you can use SSH to log in to your computer over the Internet, start your VNC server, and use [[UbuntuHelp:[port-forwarding|port-forwarding]]] to securely access the VNC server.
*If you are logging into a shared desktop you will not be able to connect if there is no user logged into the system.
+
<<Anchor(let-other-people)>>
*With a separate session you can log in even if either no one is logged into the server, or even if X is not running on the server at all.
+
=== Let other people view your desktop ===
Just a quick note about terminology. X sessions or desktops are numbered starting with 0 and is referred to on the command line as :0.
+
At present, there is no easy, secure way of making your desktop available to others over the Internet. However, an application called [https://launchpad.net/remote-help-assistant Remote Help Assistant] is being developed to fill this gap, and needs unskilled volunteers to help test new versionsContributing there might be the best use of your time, especially if you're not technically adept enough to reconfigure your system.
*So the desktop you have when you first log in can be referred to as
+
If a small group of people regularly want to access your desktop, the best solution might be to [[UbuntuHelp:SSHHowto|set an SSH server up]], then add their public keys to your '''authorized_keys''' file, with very limited rights. As [[UbuntuHelp:SSHHowto#public-key-auth|discussed]] in the SSH guide, you can limit the SSH features that each public key can use - typically, a user that should only have VNC access would have a line like the following in '''authorized_keys''':
*localhost:0
+
*172.0.0.1:0
+
*Your lan ip (ie 192.168.1.25:0)
+
*Your internet IP (128.220.223.246:0)
+
Not to be confused with ports. Servers listen on your computer via ports and vnc connections uses 5900 + by default. So the first vnc session is port 5900. The second vnc server will use 5901.
+
*The default ports can of course be changed.
+
When you activate your vnc server via System -> Preferences -> Remote Desktop and tic off the "Allow other users to view your desktop" you are :
+
*Activating a server on your desktop which allows others to connect to your desktop (see "security issues" below).
+
*Your vnc server is listening for connections on your ip:5900 (ie 192.168.1.25:5900) or your internet IP :5900 (ie 128.220.223.246:5900).
+
When you start a new vnc server with tightvncsserver (see below) this second session starts on :1
+
*So the second vnc session is on localhost:1 (192.168.1.25:1 and on ...)
+
*And the port is :5901 (localhost:5901 or 192.168.1.25:5901)
+
When you connect to a vnc server you will use the server ip address and :0 or :1 to refer to the vnc session and 192.168.1.25:5900 or 192.168.1.25:5901 for configuration of routers/firewalls.
+
==== General Security ====
+
'''Security issues'''
+
By default Ubuntu will allow all connections so at a minimum set a password when you activate Remote desktop. Without one people can watch your desktop from your LAN ''without any password''.
+
So if you are connected directly to the internet, without a router, if you do not set a password, anyone can access your computer.
+
You may also consider:
+
*Purchasing a router.
+
*Create a user(s) specifically for vnc sessions ''without admin (sudo) access''.
+
*Either logging out or '''locking your desktop''' if not in use (System -> Preferences -> Screensaver tic off the "Lock screen when screensaver is active"). If you screen is locked your log in password will be required to unlock the screen.
+
**Kde Configure Desktop -> screen Saver tab -> tic off the "Require password to stop." option.
+
*Installing firestarter to help configure your firewall.
+
*Using ssh to log into vnc sessions [[UbuntuHelp:VNCOverSSH|VNC over SSH]]
+
== Enabling VNC connections ~ Server setup ==
+
To allow other computers to access your desktop sessions, when your logged in, perform the following steps.  Note: This is like MS Remote Assistance and only works when your are logged into the computer sharing that instance of your Xserv.  See below for creating Xservs on the fly and allowing multiple loggings and XDM/GDM.
+
=== Using the default vnc servers ===
+
==== using GNOME / Ubuntu (vino) ====
+
'''System''' > '''Preferences''' > '''Remote Desktop'''
+
'Check' the first two boxes to activate the service:
+
'''Allow other users to view your desktop''' (view only)
+
'''Allow other users to control your desktop''' (view & control).
+
Below you can set security.  The two options are:
+
'''Ask you for confirmation''' (ie; someone at the machine must click '''OK''' to grant remote accessThis will be a problem if you plan on accessing your home machine from work or visa versa, as no one may be there to grant you access.)
+
'''Require the user to enter this password:'''
+
This will require a password from anyone trying to remotely connect to your machine.  This is '''ALWAYS''' a good idea.
+
==== using KDE / Kubuntu ====
+
'''System Settings''' > '''Sharing''' > '''Desktop Sharing ''' > '''Create & Manage Invitations ...'''
+
Choose 'New Personal Invitation...' (you give the invitation by whichever means you prefer (Email, Instant Messaging, Written-Down Note) or 'New Email Invitation...'. The newly created invitation will last a default of 1 hour.
+
<u>tip</u> If you don't see this option ensure that the package 'krfb' (Desktop Sharing for KDE) is installed. Sometimes it is installed but doesn't appear on the menu. If it is installed, type Alt-F2 and enter krfb or type it in the Konsole. You can manually add menu entries by righ clicking the KDE menu icon.
+
==== using XFCE / Xubuntu ====
+
There is not vnc server installed by default in Xubuntu. The default gnome vnc server is ''vino'' and you can install this package, X11vnc, or tightvncserver.
+
=== VNC Server with Login Screen via GDM ===
+
This method is somewhat more complicated, but when connecting this way you get a login prompt and begin a new sessionThis also works when no user is logged in and allows multiple parallel  loggings.
+
'''Step 1'''
+
Append the following line to /etc/services
+
<pre><nowiki>$> gksudo gedit /etc/services
+
 
+
vnc            5901/tcp                        # VNC with GDM
+
</nowiki></pre>
+
'''Step 2'''
+
Create the following file /etc/xinetd.d/vnc
+
<pre><nowiki>$> sudo pico /etc/xinetd.d/vnc
+
 
+
service vnc
+
{
+
        disable = no
+
        socket_type = stream
+
        protocol = tcp
+
        wait = no
+
        user = nobody
+
        server = /usr/bin/Xvnc
+
        server_args = -inetd :1 -query localhost -broadcast -once -fp /usr/share/X11/fonts/misc/ -securitytypes=none -desktop=vnc://MyDesktop/
+
}
+
</nowiki></pre>
+
*Note: In 6.10 the default fount's were not found. The -fp /usr/share/X11/fonts/misc/ line should resolve this error.
+
*Note: -desktop=vnc://MyDesktop/ is the title that appears to the user when connecting.
+
*Note: -query localhost is optional, it may fix a problem when clients get "connection unexpectedly closed"
+
'''Step 3'''
+
Enable XDMCP in your login configuration to allow remote logins to GDM (the gnome login screen).
+
Edit /etc/gdm/gdm.conf
+
<pre><nowiki>$> sudo pico /etc/gdm/gdm.conf
+
</nowiki></pre>
+
find the section  [xdmcp] and set the enable to true:
+
 
<pre><nowiki>
 
<pre><nowiki>
[xdmcp]
+
command="/bin/sleep 4294967295":no-agent-forwarding:no-pty:no-user-rc:no-X11-forwarding:permitopen="localhost:5900" <public key>
....
+
Enable=true
+
 
</nowiki></pre>
 
</nowiki></pre>
uncomment this line:
+
This will allow the specified person to log in to your computer using your username and their public key instead of your password.  The long list of ''no-xyz'' statements disallow them from doing just about anything except connect to a VNC server.
 +
Because the Internet is a high speed public network, an attacker anywhere in the world could connect to an unsecured VNC server and start guessing passwords at a rate of thousands per minute.  Even if they couldn't guess your password, they could snoop on the VNC session much like someone in an Internet cafe might peer over your shoulder.  If securing your connection is not an option, it's possible to provide an unsecured VNC connection with a fairly low risk of disaster, so long as you follow three basic safety precautions:
 +
* only allow the other person to view your desktop, '''not''' to control it
 +
* tell your VNC server to request permission before allowing anyone to see your desktop
 +
* don't do anything that you wouldn't do in an Internet cafe
 +
If you're not comfortable with the risks, and the secure options discussed above aren't appropriate, you might be able to [[UbuntuWiki:TakingScreenshots|take|screenshots]] instead, and send them to the other person.
 +
Whichever of the above techniques you use, you might find that you can connect to your VNC server from computers on your local network, but that other people can't connect to your server over the Internet.  If that happens, you might need to [[UbuntuHelp:ServersBehindNAT|reconfigure your router]].
 +
<<Anchor(port-forwarding)>>
 +
=== SSH port-forwarding ===
 +
SSH has a feature called '''local port forwarding''' that allows programs on a computer running an SSH client to transparently connect to servers over the SSH connection. This works by setting up a dummy server on the computer running the SSH client (the '''local''' computer) that sends everything it hears ('''forward'''s it) to a real server on the other side of the SSH connection.
 +
It's called '''port''' forwarding because different types of server listen on virtual "ports", a bit like USB ports on the back of your computer. Like with USB, any server can be plugged in to any port; but unlike USB, ports are numbered and there are strong conventions about which port you're supposed to use for which server. The convention for VNC servers is to listen on port numbers starting at 5,900 - so a computer that shared three different desktops would normally listen on ports 5,900, 5,901 and 5,902.
 +
Port-forwarding is a widely useful technique that is supported in all major SSH clients, although you will have to consult your client's documentation to find out exactly how your client does it. The command-line ssh client uses the '''-L''' option, so if you typed this for example:
 
<pre><nowiki>
 
<pre><nowiki>
RemoteGreeter=/usr/lib/gdm/gdmlogin
+
ssh -L 5900:localhost:5900 joe@laptop
 
</nowiki></pre>
 
</nowiki></pre>
'''Step 4'''
+
you would log in to Joe's laptop and forward his shared desktop to your computer. You could then start your VNC client and connect to port 5900 on your computer to see his shared desktop. ''5900:localhost:5900'' means ''start a dummy server on port 5,900 on this computer, and forward it to port 5,900 on the computer that Joe's laptop calls "localhost"''. The word "localhost" is the computer equivalent of the word "yourself", so the SSH server on Joe's laptop will think you mean Joe's laptop when you tell it to connect to "localhost" port 5900, but a VNC client on your computer will think you mean your computer when you tell it to connect to "localhost" port 5900.
Stop and restart Xinetd
+
<<Anchor(vnc-clients)>>
<pre><nowiki>$> sudo /etc/init.d/xinetd restart
+
== VNC Clients ==
</nowiki></pre>
+
A VNC client lets you connect to a desktop that's been shared on another computer. Excellent VNC clients are available for every major Linux distribution and other operating system.  Some popular clients include:
'''Problems'''
+
* [[UbuntuHelp:Vinagre]] is the remote desktop viewer that comes by default with Ubuntu
*If you cant connect check your router/port forwarding, firewall, or try running the following to start a session without Xinetd to verify Xvnc is working.
+
* krdc is the standard KDE client, and can also act as a Windows Terminal Services client
<pre><nowiki>$> Xvnc :1 -fp /usr/share/fonts/X11/misc/
+
* xvnc4viewer is a simplistic client recommended for Xubuntu users.<<BR>>
</nowiki></pre>
+
xvnc4viewer is available in the Universe repository
*Make sure you connect to the proper port, in this case vnc://localhost:5901In some clients this is set by choosing display 1.
+
* xtightvncviewer is a simplistic client recommended for use with tightvncserver<<BR>>
=== Tightvncserver Server with Login Screen Via GDM ===
+
xtightvncviewer is available in the Universe repository
This method will give you an independent desktop once you log in (ie independent of session started when you logged in via GDM).
+
* [http://sourceforge.net/projects/cotvnc/ Chicken of the VNC] is a popular VNC client for Mac OS X<<BR>>
'''Step 1 - Install tightvncserver'''
+
Other Mac clients can be found on [http://www.apple.com/downloads/macosx/networking_security/ Apple's website]
<pre><nowiki>
+
* [http://www.tightvnc.com/ TightVNC] has a Windows version available
sudo apt-get install vnc-common tightvncserver
+
* TightVNC Java client is a multiplatform Java client that can run in a web browser<<BR>>
</nowiki></pre>
+
If you can't install software on the machine you'll log in from, you can make this available through a web server.  It's available in the vnc-java package in the Multiverse repository
'''Step 2 - Edit vncserver script'''
+
{|border="1" cellspacing="0"
<pre><nowiki>
+
|{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconTip.png%7D%7D%7C%7CIf you accidentally display the remote desktop fullscreen, try pressing ''F8'' or ''F11'' to exit.
sudo vim /usr/bin/vncserver
+
|}
</nowiki></pre>
+
To connect a VNC client to a VNC server, you need to know the name or the IP address of the computer you'll connect to, and the port or display number of its VNC serverBy convention, port numbers start at 5,900 and go up, so a computer that shared three different desktops would normally listen on ports 5,900, 5,901 and 5,902.  Display numbers use the 5,900 convention to try to make things easier - port number 5,900 is display number :0, port number 5,901 is display number :1, and so on.
First, you want a valid X11 font path for Xvnc.
+
=== Similar applications ===
Add these lines for Feisty/Gutsy (you will see a fonts section with a number of font paths commented out):
+
* [https://launchpad.net/remote-help-assistant Remote Help Assistant] is an application being developed to make it easier to securely acces a VNC server
<pre><nowiki>
+
* '''rdesktop''' is a client for Windows Terminal Services, available in the Main repository
$fontPath = join ',',qw(
+
* '''qtnx''' is an [http://en.wikipedia.org/wiki/NX_technology NX] client for KDE, available in the Universe repository
/usr/share/fonts/X11/misc
+
== VNC Servers ==
/usr/share/fonts/X11/100dpi/:unscaled
+
A VNC server is a program that shares a desktop with other computers over the Internet.  You will need a VNC server if you want other people to see your desktop.  Every VNC server has different strengths and weaknesses and is appropriate for different uses.  This section will discuss each of the VNC servers available in Ubuntu, and ways to configure them for most common uses of VNC.
/usr/share/fonts/X11/75dpi/:unscaled
+
The most important thing when setting up a VNC server is to only let the right people access your desktop.  The safest way to do that is usually to have someone sitting at the desktop deciding who gets to use it, but that's not always practical - for example, if you want to log in to your own computer from somewhere else.
/usr/share/fonts/X11/Type1
+
If you want to confirm each connection manually, you should look for these options:
/usr/share/fonts/X11/100dpi
+
* '''Request access each time''' - pop a window up asking whether to allow each connection as it comes in.
/usr/share/fonts/X11/75dpi
+
* '''view-only access''' - allow VNC clients to view the destkop, but not to change anything.  As well adding a little security, this avoids problems with both of you fighting over control of the mouse.
);
+
If you want to access your desktop when nobody is sitting at it, these options will be more useful:
</nowiki></pre>
+
* '''Only allow local connections''' - only let people connect if they already have access to your computer. 
You may add additional font paths as needed.
+
* '''Start your VNC server in "once" mode''' - tell your VNC server to allow one connection, then block anything after that
* see [[UbuntuHelp:VNCOverSSH|this link]] for font paths with earlier versions of Ubuntu
+
* '''Set a password''' - require people to send a password before they can connect.
''Optional:'' Set display size and color depth (make this whatever you want):
+
These options should give you a secure set-up, so long as they're used with  [[UbuntuHelp:[port-forwarding|port-forwarding]]], as discussed above.  Only allowing local connections means that only people with user accounts on your computer can access your desktop.  Starting the server in "once" mode means that people with user accounts on your computer would have to log in to your desktop between the time you start your VNC server and the time you connect from your VNC client.  Setting a password means that, if anyone did try to connect in that brief interval, they probably wouldn't be able to get in before you noticed and stopped the server.
<pre><nowiki>
+
Although passwords add some security, [[UbuntuHelp:StrongPasswords|hard-to-guess passwords]] are as difficult to create as they are to remember.  If nobody else has access to your computer, you might want to skip passwords altogether.
$geometry = "1280x1024";
+
=== Vino ===
$depth = 16;
+
Vino is the default VNC server in Ubuntu to share your existing desktop with other users.  Unfortunately, a [https://bugs.launchpad.net/ubuntu/+source/vino/+bug/196675 bug] in the version that comes with Hardy makes it incompatible with most networks and VNC clients.
</nowiki></pre>
+
To configure vino from within GNOME, go to System > Preferences > Remote Desktop
''Optional:'' Uncomment the line:
+
* To set vino to request access each time, tick '''Allow other users to view your destkop''' in the Remote Desktop configuration window
<pre><nowiki>
+
* There's no way to set vino to only listen for the next connection
$colorPath = "/usr/lib/X11/rgb";
+
* To set a password, tick '''Require the user to enter this password:''', and enter a [[UbuntuHelp:StrongPasswords|hard-to-guess password]]
</nowiki></pre>
+
* To put vino in view-only mode, untick '''Allow other users to control your desktop'''
Save file and close vim:
+
* To only allow local connections, click on the tab marked '''Advanced''', then tick '''Only allow local connections'''.
<pre><nowiki>
+
=== krfb ===
:wq</nowiki></pre>
+
Krfb is the default VNC server in Kubuntu, and is recommended for KDE users.  Because it's highly integrated with KDE, running it in other environments is difficult.
'''Step 3 - Run vncserver for the first time'''
+
To configure krfb, go to System Settings > Sharing > Desktop Sharing > Configure....
<pre><nowiki>
+
* To set krfb to request access each time, tick '''Confirm uninvited connections before accepting'''
vncserver :1
+
* There's no official way to set krfb to only listen for the next connection, although see below for an unofficial solution
</nowiki></pre>
+
* To set a password, type a [[UbuntuHelp:StrongPasswords|hard-to-guess password]] into the '''Password''' input box
The first time you run the server you will be asked to provide a name and password :
+
* To put krfb in view-only mode, untick '''Allow uninvited connections to control the desktop'''
<pre><nowiki>
+
* There's no official way to only allow local connections, although see below for an unofficial solution
ubuntu@ubuntu:~$ vncserver :1
+
==== Once mode ====
 
+
Krfb doesn't have any official way to accept the next connection then stop listening for connection attempts.  However, the following Python script will listen for a single connection then exit krfb:
You will require a password to access your desktops.
+
<pre><nowiki>#!python numbers=off
 
+
#!/usr/bin/python
Password: #Enter your desired password here
+
Verify:  #Confirm Password
+
  
New 'X' desktop is ubuntu:1
+
# Load extra functionality from the 'socket' and 'os' modules
 +
from socket import socket, AF_INET, SOCK_STREAM
 +
from os import execl
  
Starting applications specified in /etc/X11/Xsession
+
# Listen for a connection
Log file is /home/ubuntu/.vnc/ubuntu:1.log
+
server = socket(AF_INET, SOCK_STREAM) # This is an Internet (TCP) connection
 +
server.bind(('127.0.0.1', 5900))      # Listen for a local connection on port 5,900
 +
server.listen(1)                      # Listen for exactly 1 connection
 +
sock = server.accept()[0]            # Accept the connection
  
ubuntu@ubuntu:~$
+
# Attach krfb to this connection
 +
execl('/usr/bin/krfb', 'krfb', '--kinetd', str(sock.fileno()))
 
</nowiki></pre>
 
</nowiki></pre>
This will create a new directory in your home directory '''~/.vnc'''
+
To use this script, open your favourite text editor and paste the contents in.  Make sure that the initial '#' character is the very first character in the file, save the file as '''krfb.py''', and set the file's permissions to make it executable.  Although this simple program won't open a window of any kind, it will quietly wait for the next VNC client to connect to your computer, then pass the connection through to krfb.
* To change you password later use ''vncpasswd''
+
This script will only listen for local connections.  To allow connections from anywhere, change '127.0.0.1' to '0.0.0.0' in the script.
 +
==== Invitations ====
 +
Krfb lets you create "invitations" - individual passwords that are deactivated after an hour or after one use.  These are a handy way of giving people one-time access to a computer, but only provide limited security.  For example, if you send someone an invitation by e-mail or instant messaging, an attacker could read your invitation message as it went over the Internet and use it to log in.
 +
Invitations can be useful when you want to let other people view your desktop, but you still need to follow the precautions discussed [[UbuntuHelp:[let-other-people|above]]].
 +
=== x11vnc ===
 +
X11vnc is a VNC server that doesn't depend on GNOME or KDE, and is recommended for use by Xubuntu users. It's designed to be run from the command-line, which makes it flexible but difficult to learn. The few graphical parts of the interface are quite unattractive, because they're designed to work even on a very minimal installation. X11vnc is available in the '''x11vnc''' package in the Universe repository.
 +
Although x11vnc does have a simple configuration file, it's generally easier to specify options on the command-line.  To start x11vnc, type:
 
<pre><nowiki>
 
<pre><nowiki>
vncpasswd ~/.vnc/passwd
+
x11vnc -safer <options>
 
</nowiki></pre>
 
</nowiki></pre>
'''Step 4 - Edit your VNC startup script'''
+
'''<options>''' is a series of commands separated by spaces.  X11vnc has a lot of options, which are discussed fully in the [http://linux.die.net/man/1/x11vnc x11vnc man page].  Common options include:
We may want to edit the VNC (X) startup script in ''~/.vnc/xstartup''
+
* To set x11vnc to request access each time, include the '''-nopw -accept popup:0''' options
You can use these if you like :
+
* To set x11vnc to only listen for the next connection, include the '''-once''' option
'''Gnome'''
+
* To set x11vnc to continually listen for connections, include the '''-forever''' option
 +
* To set a password, include the '''-usepw''' option (and remove the '''-nopw''' option above)
 +
* To put x11vnc in view-only mode, include the '''-viewonly''' option
 +
* To set x11vnc to only allow local connections, include the '''-localhost''' option
 +
For example, if you want x11vnc to grant view-only access to the next local connection after asking your permission, type this on the command-line:
 
<pre><nowiki>
 
<pre><nowiki>
 
+
x11vnc -safer -localhost -nopw -accept popup:0 -once -viewonly -display :0
xrdb $HOME/.Xresources
+
xsetroot -solid navy # Choose your color
+
x-window-manager &
+
gnome-panel 2> /dev/null &
+
xterm &
+
 
</nowiki></pre>
 
</nowiki></pre>
'''XFCE'''
+
If you use a password, you will first need to create a password file by doing:
 
<pre><nowiki>
 
<pre><nowiki>
 
+
x11vnc -storepasswd
xrdb $HOME/.Xresources
+
xfwm4 2> /dev/null &
+
xfce4-panel 2> /dev/null &
+
xfce4-terminal &
+
 
</nowiki></pre>
 
</nowiki></pre>
'''KDE'''
+
Make sure to use a [[UbuntuHelp:StrongPasswords|hard-to-guess password]]
 +
<<Anchor(x11vnc-before-login)>>
 +
==== Connecting to your login screen ====
 +
Because X11vnc is run from the command-line, it can be started while your computer is still showing a login screen.  Exactly how to do this depends on which derivative of Ubuntu you use.  In Ubuntu (but not Kubuntu or Xubuntu), x11vnc needs superuser access, and needs the '' -auth /var/lib/gdm/:0.Xauth -display :0'' options to be specified on the command-line.  You will also need superuser access to edit your ''/etc/gdm/gdm.conf'' file, to stop your computer from closing your VNC session after you've typed your username and password.
 +
To edit ''/etc/gdm/gdm.conf'', type the following on a command-line:
 
<pre><nowiki>
 
<pre><nowiki>
 
+
sudo gedit /etc/gdm/gdm.conf
xrdb $HOME/.Xresources
+
xsetroot -solid navy # Choose your color
+
x-terminal-emulator -geometry 80x24+10+1- -ls -title "$VNCDESKTOP Desktop" &
+
x-window-manager &
+
kicker 2> /dev/null &
+
 
</nowiki></pre>
 
</nowiki></pre>
'''Step 5 - Restart the VNC server'''
+
Search for "!KillInitClients" in that file, and you should see a line that looks like this:
 
<pre><nowiki>
 
<pre><nowiki>
killall Xtightvnc
+
#KillInitClients=true
vncserver
+
 
</nowiki></pre>
 
</nowiki></pre>
Note that you can vary the screen size, depth, and number when starting '''vncserver''':
+
change that line to look like this:
 
<pre><nowiki>
 
<pre><nowiki>
vncserver -geometry 1288x1024 -depth 24 :3
+
KillInitClients=false
 
</nowiki></pre>
 
</nowiki></pre>
* See vncserver manpage for additional options
+
Then you can run x11vnc before you've logged in by typing something like this:
=== [[UbuntuHelp:FreeNX|FreeNX]] ===
+
See  [[UbuntuHelp:FreeNX| Ubuntu Wiki How to FreeNX]]
+
=== Tunnel VNC through SSH ===
+
If you wish to tunnel over ssh you need to install, setup, and secure the openssh server.
+
*[[UbuntuHelp:SSHHowto| Ubuntu Wiki How to SSH]]
+
*[[UbuntuHelp:AdvancedOpenSSH| Ubuntu Wiki, Advanced SSH (security) settings]]
+
== Enabling VNC connections ~ Client setup ==
+
=== Ubuntu clients ===
+
==== Terminal Server Client ====
+
'''This method works with both the default vino server ''and'' the tightvnc server'''
+
This is the default method in Ubuntu and uses a gui (graphical interface). Use this if you are averse to the command line.
+
Go to Applications -> Internet -> Terminal Server client
+
In the ''General tab'' :
+
*Put the server ip in the "Computer" box (ie 192.168.1.25:0 for the default vino server or 192.168.2.25:1 for a tightvnc server)
+
*Select ''VNC'' from the pull down menu in "Protocol"
+
Hit Connect
+
Enter the password you set on your server.
+
==== VNC Viewer ====
+
This method uses the command line. Open a terminal an enter ''vncviewer'' and you will be asked to enter the ip address and password.
+
If you know the ip address you can use the ip in conjunction, like this :
+
 
<pre><nowiki>
 
<pre><nowiki>
vncviewer 192.168.1.25:0
+
sudo x11vnc -safer -localhost -once -nopw -auth /var/lib/gdm/:0.Xauth -display :0
 
</nowiki></pre>
 
</nowiki></pre>
Or if you want to get fancy, copy ~/.vnc/passwd ''from the server to the client'' (saving it in ~/.vnc/passwd on ''both'' the server and client). Now you can connect directly with :
+
(Thanks to [http://www.karlrunge.com/x11vnc/#faq-display-manager the x11vnc FAQ] for this tip)
 +
=== tightvncserver ===
 +
Whereas most VNC servers share your desktop, tightvnc creates a completely new desktop, not attached to any actual screen.  This makes it much less useful for some things (like remote help), but much more useful for others (like creating a public area for collaboration).  If tightvncserver won't start, you might need to uncomment the `$fontpath` lines in '''/etc/vnc.conf'''.
 +
Like x11vnc, tightvnc is designed to be run from the command-line. To start it, type:
 
<pre><nowiki>
 
<pre><nowiki>
vncviewer 192.168.2.25:0 -passwd ~/.vnc/passwd
+
tightvncserver -nolisten tcp :1
 
</nowiki></pre>
 
</nowiki></pre>
*If you like, you can re-name the ~/.vnc/passwd to any name you like and keep one file for each server (each with a unique name).
+
This will tell tightvnc to listen for VNC connections on port 5,901 from anywhere on the Internet. Without the '''-nolisten tcp''' option, tightvnc will also listen for a different type of connection (X11 instead of VNC), which isn't usually very useful. Tightvnc's unusual design means that it can't create a remote desktop on the standard VNC port (5,900) if you have an ordinary desktop running on your computer.
==== Logging into a Tight VNC server ====
+
* There's no way to set tightvncserver to request access each time
If desired you will need to configure your desktop.
+
* There's no way to set tightvncserver only to accept the next connection, although see below for a similar solution
'''Ubuntu'''
+
* Tightvncserver always requires a password, and will ask you to specify one the first time it's run
I do not know how to set the background image on the tightvnc server, but the gnome panel works.
+
* There's no way to put tightvncserver in view-only mode
'''XFCE'''
+
* To set tightvncserver to only allow local connections, include the '''-localhost''' option
Applications -> Settings -> Desktop Settings
+
==== Once mode ====
*Tic off the "Allow Xfce to manage the desktop"
+
Tightvncserver can't be set to accept the next connection then stop listening for connection attemptsBut it can be set to automatically disconnect each client when the next client connects, and can be stopped after your connection is disconnected. To only allow local connections and automatically disconnect clients, start tightvnc by typing:
'''KDE'''
+
The kicker works fine, as with gnome I could not get set the backgound image.
+
=== Windows Clients ===
+
This method works with Windows 2000 and XP. I am not sure about other versions.
+
Connecting with a windows client is fairly straight forward, all you need to do is download the tight vnc viewer for windows. You then run the viewer and enter the server address and password very similar to connecting from Ubuntu.
+
[http://www.tightvnc.com/download.html Tight VNC viewer for windows]
+
*The tight vnc viewer is available without installation ( tightvnc-1.3.9_x86_viewer.zip "Viewer executable, does not require installation")
+
I have also used [http://www.uvnc.com/download/ Ultra] and [http://www.realvnc.com/download.html Real] vnc viewers
+
*You can set up tight, ultra, or real vnc servers on windows and connect just as easily from ubuntu.
+
== VNC Access over the Internet ==
+
'''Strongly consider''' tunneling over ssh [[UbuntuHelp:VNCOverSSH| VNC Over SSH]] , using a router (rather then connecting your server directly to the internet),  and configuring your firewall [[UbuntuHelp:Firestarter| Firestarter]].
+
The most difficult part of internet access is configuring your router and firewall ...
+
==== Server IP ====
+
The IP address of your VNC server is different on a LAN vs an internet connection. The internet IP address is assigned by your internet provider.
+
* You can check your IP address [http://whatismyip.com/ here] (or elsewhere).
+
The problem can occur if you use DHCP (rather then a static IP address) the internet IP address can change from time to time.
+
The solution is to register at [https://www.dyndns.com/services/dns/dyndns/ dyndns] or other providers. dyndns will provide free service.
+
You can then determine your vnc server address via ping.
+
==== Router ====
+
You must configure your router to forward the ports. The details vary by router.
+
<u>tip</u>: if you are connecting through a router you'll need to forward port 5900 to the machine you need to connect to(VNC can use other ports as well.  If you have multiple machines you would like to connect to you can forward 5900 to the first, 5901 to the second, 5902 to the third, etc.)
+
If you are using a non-standard port (ie; other than 5900) you will need to specify the port in the connection command.
+
You can simplify this step some what by tunneling though ssh (which also increases security). See the ssh section below.
+
==== Firewall ====
+
This is very easy to do via firestarter, a gui front end to IP Tables.
+
* Be sure to configure firestarter to allow pings.
+
Open the firestarter gui (Applications -> Internet -> Firestarter)
+
In the "Policy" tab, under the "Allow service" section, right click anywhere in the white space.
+
Select "Add rule"
+
*Under "Port" enter the ports you want to enable (5900 and/or 5901)
+
Allow "Anyone"
+
=== Method 1 ~ Using vncviewer from the command line ===
+
* Using tightvncserver - See the ''Tightvncserver'' section above.
+
*If you are using the default vnc server, vino, for a shared desktop, use 5900 or :0
+
Open a terminal and start vncviewer with this command
+
 
<pre><nowiki>
 
<pre><nowiki>
vncviewer
+
tightvncserver -nolisten tcp -localhost -nevershared :1
 
</nowiki></pre>
 
</nowiki></pre>
Enter the ip address :1
+
Then when your client is disconnected by the next client connecting, type:
Example:
+
 
<pre><nowiki>
 
<pre><nowiki>
192.168.1.25:1
+
tightvncserver -kill :1
 
</nowiki></pre>
 
</nowiki></pre>
Enter the vnc password
+
=== Similar applications ===
=== Method 2 ~ Ubuntu clients ~ Tunnel over ssh directly ===
+
* [http://www.gnu.org/software/screen/ GNU Screen] allows you to open, share, disconnect, and later return to a text-based terminal.
You can use this method with Ubuntu clients.
+
* '''directvnc''' is a VNC server that shares a Linux framebuffer instead of a desktop
Use the -via flag -via <server_IP> = use ssh authentication.
+
* '''linuxvnc''' is a VNC server that shares a text-based console instead of a desktop
vncviewer -via <server_ip> <name_of_vnc_session>
+
* '''xrdp''' is a server for Microsoft's Remote Desktop protocol, a client for which comes with all modern versions of Windows
<pre><nowiki>
+
* '''xserver-xephyr''' allows you to create a desktop within a desktop on a single computer
vncviewer -via 192.168.1.25 ubuntu:1
+
* [[UbuntuHelp:AppleRemoteDesktop|Apple Remote Desktop]] is a desktop sharing application for Mac OS that includes a VNC server
</nowiki></pre>
+
== Guide to example scenarios ==
Enter ssh password, enter vnc password
+
This section discusses some situations where you would want to use VNC, and how to set a server up for that situation.  The first scenario ("Accessing your PC") describes how to set VNC up for a computer that logs in automatically as soon as it starts up.  Because accessing a shared login screen requires more security privileges than accessing your personal desktop, the second scenario ("Accessing a family PC") describes the extra steps you need to take in order to access your computer before you've logged in.
*You are given the name of the vncserver by tight vnc when you start it up, see the tight vnc server section above
+
<<Anchor(accessing-your-pc)>>
=== Method 3 ~ Windows or Ubuntu ~ Tunnel over ssh manually ===
+
=== Accessing your PC over the Internet ===
This is a quick guide and assumes you have a ssh server set up on the vnc server.
+
This section describes how to connect to your own desktop computer from somewhere else on the Internet. See below for instructions about logging in to a shared computer.
See this link for a more detailed description : [[UbuntuHelp:VNCOverSSH|VNC Over SSH]]
+
To set your VNC server up, follow these steps.  You should only need to do this once:
The trick is to forward the ports over ssh. In this example I will use 5900 , the default path for the defalut VNC server ''vino''. If you use tightvnc you will need to change the forwarded port to 5901.
+
<ol><li>[[UbuntuHelp:InstallingSoftware|Install]] the ''x11vnc'' and ''openssh-server'' packages on your PC.
'''Step 1'''
+
</li><li>If you have previously reconfigured the firewall on your PC, make sure the firewall allows incoming connections on port ''22'' from anywhere, and on port ''5900'' from ''localhost'' (also known as ''127.0.0.1'').
Make the ssh connection :
+
</li><li>If your PC is behind a home router, or any other device that uses NAT, [[UbuntuHelp:ServersBehindNAT#Procedure|configure|your router]] to send connection attempts on port 22 (but '''not''' port 5900) to your computer.
<pre><nowiki>
+
</li><li>[[UbuntuHelp:SSHHowto#Logging_in_from_other_computers|Choose an SSH client]] for the computer you'll log in from, and create a public key for that computer.
ssh -fCNT [email protected] -L 5901:127.0.0.1:5901
+
</li><li>In a text editor on your PC, open the file '''''<home>''/.ssh/authorized_keys''', then add the public key you just created to the bottom of the file.</li></ol>
</nowiki></pre>
+
<pre><nowiki>
+
-f = Allows ssh to close after the connection is established.
+
-C = Use Compression
+
-N = No commands will be issued
+
-T = No terminal session will be started
+
  
-L = Port forwarding. The terminology is <server_port>:<client_port> the trick is we are using 127.0.0.1:<port> for the client. 127.0.0.1 must be used (not localhost or the client ip address)
+
Each time you want to connect to your PC, follow these steps:
</nowiki></pre>
+
<ol><li>Find your PC's public name or IP address. Unless your computer has been assigned a memorable name, the easiest way to do this is to go to [http://whatismyip.com/ www.whatismyip.com] from your PC.  You can assign your computer a name by getting one from a [[UbuntuHelp:DynamicDNS|dynamic DNS]] provider.
'''Step 2'''
+
</li><li>Start an SSH session on your PC with your SSH client, use local port-forwarding to connect port 5,900 on your desktop to port 5,900 on localhost, and run the command `x11vnc -safer -localhost -nopw -once -display :0`
Make the vnc connection.
+
</li><li>Start your VNC client, and connect to localhost port 5,900</li></ol>
Now we make the vnc connection, but now we use '''localhost:1''' as the server ip.
+
 
<pre><nowiki>
+
If you have a dial-up Internet connection, your IP address will change every time you connect to the Internet.  If you have a broadband Internet connection, your address will probably only change once every few months - usually right around the day you forget to check your address.
vncviewer localhost:1
+
If you were connecting from an Ubuntu computer with a command-line VNC client, you could do the following on a command-line:
</nowiki></pre>
+
Enter your password.
+
'''Step 3'''
+
To disconnect, close the vnc viewer, and enter '''killall ssh''' in the terminal.
+
=== Method 4 ~ Via a web browser (firefox for example) ===
+
This does not work with the default vnc server, vino. You will need to install and configure the tight vnc server as above.
+
You will need to enable the commercial repositories on both the server and client (or download the debs) :
+
<pre><nowiki>
+
deb http://archive.canonical.com/ubuntu gutsy commercial
+
deb-src http://archive.canonical.com/ubuntu gutsy commercial
+
</nowiki></pre>
+
==== Server setup ====
+
Install by any means '''vnc-common, tightvncserver, and tightvnc-java'''
+
<pre><nowiki>
+
sudo apt-get install vnc-common tightvncserver tightvnc-java
+
</nowiki></pre>
+
Configure the tight vnc server as above.
+
You will likely want to reduce the resolution as the java applet will run in a firefox window :
+
 
<pre><nowiki>
 
<pre><nowiki>
vncserver -geometry 800x600 -depth 24 :1
+
ssh -f -L 5900:localhost:5900 <your-name>@<your-computer> \
 +
x11vnc -safer -localhost -nopw -once -display :0 \
 +
&& sleep 5 \
 +
&& vncviewer localhost:0
 
</nowiki></pre>
 
</nowiki></pre>
* If you have a large monitor you may be able to increase the server resolution.
+
If the above VNC connection is terribly slow, then you may need to enable a compression mechanism, e.g., <code><nowiki>vncviewer -encodings "tight" localhost:0</nowiki></code>.  Alternatively, if your VNC viewer supports the "-via" option (e.g., xtightvncviewer does so) then you need neither manual port-forwarding nor manual settings for compression.  Instead, you SSH into the remote computer, start the VNC server with <code><nowiki>x11vnc -safer -localhost -nopw -once -display :0</nowiki></code> and, again on your client machine, start the client with the following command line:
The java server will start automatically
+
==== Client setup ====
+
On an Ubuntu client install by any means '''sun-java6-jre and sun-java-6-plugin'''
+
 
<pre><nowiki>
 
<pre><nowiki>
sudo aptitude install sun-java6-jre sun-java-6-plugin
+
vncviewer -via <your-name>@<your-computer> localhost:0
 
</nowiki></pre>
 
</nowiki></pre>
Allow java : In Firefox Edit -> Preferences Select the "Content" tab, tic off the "Load images automatically" "Enable JavaScript" and "Enable Java" boxes.
+
In Ubuntu, the ''vncviewer'' command will run whichever VNC client you have installed.
==== Connect ====
+
=== Accessing a family PC over the Internet ===
Open Firefox, in the address bar type vnc server ip : 5801
+
Accessing a family PC is a similar problem to accessing your own PC, except that the VNC server needs more security privileges in order to show your login screen.
Example:
+
First, make sure that you can [[UbuntuHelp:[accessing-your-pc|access your own desktop after logging in]]] - once you've logged in, accessing a shared PC is no different to accessing your own PC.
 +
Second, follow the instructions to [[UbuntuHelp:[x11vnc-before-login|get x11vnc working before you log in]]].  After this step, you should start the VNC server on the family PC with superuser privileges:
 
<pre><nowiki>
 
<pre><nowiki>
192.168.1.25:5801
+
ssh -L 5900:localhost:5900 <your-name>@<your-computer>
 +
sudo x11vnc -safer -localhost -nopw -once -auth /var/lib/gdm/:0.Xauth -display :0
 
</nowiki></pre>
 
</nowiki></pre>
The java applet will start automatically.
+
Then connect your VNC client in the same way you did before.
If you use NoScript (or other java blockers) you will need to allow 192.168.1.25:5801
+
== Further information ==
Click the connect button.
+
Remote desktop solutions are a broad and complex topic. The following links provide more detail about the technologies involved:
*If you reload the firefox window you will need to log in again.
+
* [[UbuntuHelp:WikiPedia:Vnc|Wikipedia's VNC page]]
=== Connecting with a Windows XP client ===
+
* [[UbuntuHelp:WikiPedia:Remote_administration|Wikipedia's remote administration page]]
You may use any of the above methods with Windows.
+
* [[UbuntuHelp:WikiPedia:Remote_Desktop_Protocol|The Remote Desktop Protocol]] is a similar protocol, popular in Windows
*VNC - See the windows section above.
+
* [[UbuntuHelp:WikiPedia:NX_technology|The NX Protocol]] is another similar protocol
*SSH - For windows I have used both [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html Putty] and [http://www.cygwin.com/mirrors.html Cygwin] with success. See here for details [[UbuntuHelp:VNCOverSSH#head-8b36ee1084a8123627a915fe0329534788cb11a7|vnc over ssh Windows clients]]
+
* [[UbuntuHelp:WikiPedia:X_display_manager|The XDMCP protocol]] also enables remote login
*For firefox just be sure to install java and the java plugins on the windows client.
+
* [http://tldp.org/HOWTO/XDMCP-HOWTO/ The XDMCP How-to] and two Ubuntu [http://ubuntuforums.org/showpost.php?p=5229232&postcount=458 forum] [http://ubuntuforums.org/showpost.php?p=4963842&postcount=1 posts] give explanations about how to use XDMCP
<u>Note</u>: If you tunnel ssh connections on a windows client, you must first ssh method (ie start ssh first, then connect with tightvnc viewer).
+
* [[UbuntuHelp:DynamicDNS]] is a way to obtain a stable DNS name even if your IP changes dynamically
<u>Note</u>: Cygwin offers a ssh server so you could potentially tunnel vnc connections from a Windows vnc server.
+
* [[UbuntuHelp:WikiPedia:KVM_switch|KVM switches]] are hardware devices that switch a keyboard, monitor and mouse between two or more computers
[[category:CategoryDocumentation]] [[category:CategoryCleanup]]
+
* [[UbuntuHelp:Xen]] is a way of running a virtual machine in Linux
 +
* [[UbuntuHelp:WikiPedia:Wake-on-LAN||Wake-on-LAN]] is a way of powering a computer on over a network or the Internet.
 +
[[category:CategoryNetworking]] [[category:CategoryInternet]]
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2008年10月19日 (日) 18:00的版本

<<Include(Tag/TooLong)>> VNC is a protocol that allows a desktop to be viewed and controlled remotely over the Internet. To use VNC, you need to run a VNC server on the computer sharing a destkop, and a VNC client on the computer accessing the shared desktop. VNC is a widely useful tool, although you'll need to do some work to set it up for your particular use case. This page will discuss some common uses for VNC, present programs you can use to solve your particular problem, and then guide you through some example scenarios. You may want to [[UbuntuHelp:[guide|skip straight to the examples]]].

Common uses

The two most common uses for VNC are to control your own desktop from another computer and to let other people view your desktop while you're sitting at it.

Accessing your desktop over the Internet

Although VNC has some optional security features, you should not run VNC directly over an untrusted network like the Internet. Instead, you should set an SSH server up as discussed in the SSH guide and configure a VNC server that you can start in so-called once mode, as described below. When you have set up your SSH and VNC servers, you can use SSH to log in to your computer over the Internet, start your VNC server, and use [[UbuntuHelp:[port-forwarding|port-forwarding]]] to securely access the VNC server. <<Anchor(let-other-people)>>

Let other people view your desktop

At present, there is no easy, secure way of making your desktop available to others over the Internet. However, an application called Remote Help Assistant is being developed to fill this gap, and needs unskilled volunteers to help test new versions. Contributing there might be the best use of your time, especially if you're not technically adept enough to reconfigure your system. If a small group of people regularly want to access your desktop, the best solution might be to set an SSH server up, then add their public keys to your authorized_keys file, with very limited rights. As discussed in the SSH guide, you can limit the SSH features that each public key can use - typically, a user that should only have VNC access would have a line like the following in authorized_keys:

command="/bin/sleep 4294967295":no-agent-forwarding:no-pty:no-user-rc:no-X11-forwarding:permitopen="localhost:5900" <public key>

This will allow the specified person to log in to your computer using your username and their public key instead of your password. The long list of no-xyz statements disallow them from doing just about anything except connect to a VNC server. Because the Internet is a high speed public network, an attacker anywhere in the world could connect to an unsecured VNC server and start guessing passwords at a rate of thousands per minute. Even if they couldn't guess your password, they could snoop on the VNC session much like someone in an Internet cafe might peer over your shoulder. If securing your connection is not an option, it's possible to provide an unsecured VNC connection with a fairly low risk of disaster, so long as you follow three basic safety precautions:

  • only allow the other person to view your desktop, not to control it
  • tell your VNC server to request permission before allowing anyone to see your desktop
  • don't do anything that you wouldn't do in an Internet cafe

If you're not comfortable with the risks, and the secure options discussed above aren't appropriate, you might be able to take|screenshots instead, and send them to the other person. Whichever of the above techniques you use, you might find that you can connect to your VNC server from computers on your local network, but that other people can't connect to your server over the Internet. If that happens, you might need to reconfigure your router. <<Anchor(port-forwarding)>>

SSH port-forwarding

SSH has a feature called local port forwarding that allows programs on a computer running an SSH client to transparently connect to servers over the SSH connection. This works by setting up a dummy server on the computer running the SSH client (the local computer) that sends everything it hears (forwards it) to a real server on the other side of the SSH connection. It's called port forwarding because different types of server listen on virtual "ports", a bit like USB ports on the back of your computer. Like with USB, any server can be plugged in to any port; but unlike USB, ports are numbered and there are strong conventions about which port you're supposed to use for which server. The convention for VNC servers is to listen on port numbers starting at 5,900 - so a computer that shared three different desktops would normally listen on ports 5,900, 5,901 and 5,902. Port-forwarding is a widely useful technique that is supported in all major SSH clients, although you will have to consult your client's documentation to find out exactly how your client does it. The command-line ssh client uses the -L option, so if you typed this for example:

ssh -L 5900:localhost:5900 joe@laptop

you would log in to Joe's laptop and forward his shared desktop to your computer. You could then start your VNC client and connect to port 5900 on your computer to see his shared desktop. 5900:localhost:5900 means start a dummy server on port 5,900 on this computer, and forward it to port 5,900 on the computer that Joe's laptop calls "localhost". The word "localhost" is the computer equivalent of the word "yourself", so the SSH server on Joe's laptop will think you mean Joe's laptop when you tell it to connect to "localhost" port 5900, but a VNC client on your computer will think you mean your computer when you tell it to connect to "localhost" port 5900. <<Anchor(vnc-clients)>>

VNC Clients

A VNC client lets you connect to a desktop that's been shared on another computer. Excellent VNC clients are available for every major Linux distribution and other operating system. Some popular clients include:

  • UbuntuHelp:Vinagre is the remote desktop viewer that comes by default with Ubuntu
  • krdc is the standard KDE client, and can also act as a Windows Terminal Services client
  • xvnc4viewer is a simplistic client recommended for Xubuntu users.<
    >

xvnc4viewer is available in the Universe repository

  • xtightvncviewer is a simplistic client recommended for use with tightvncserver<
    >

xtightvncviewer is available in the Universe repository

Other Mac clients can be found on Apple's website

  • TightVNC has a Windows version available
  • TightVNC Java client is a multiplatform Java client that can run in a web browser<
    >

If you can't install software on the machine you'll log in from, you can make this available through a web server. It's available in the vnc-java package in the Multiverse repository

{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconTip.png%7D%7D%7C%7CIf you accidentally display the remote desktop fullscreen, try pressing F8 or F11 to exit.

To connect a VNC client to a VNC server, you need to know the name or the IP address of the computer you'll connect to, and the port or display number of its VNC server. By convention, port numbers start at 5,900 and go up, so a computer that shared three different desktops would normally listen on ports 5,900, 5,901 and 5,902. Display numbers use the 5,900 convention to try to make things easier - port number 5,900 is display number :0, port number 5,901 is display number :1, and so on.

Similar applications

  • Remote Help Assistant is an application being developed to make it easier to securely acces a VNC server
  • rdesktop is a client for Windows Terminal Services, available in the Main repository
  • qtnx is an NX client for KDE, available in the Universe repository

VNC Servers

A VNC server is a program that shares a desktop with other computers over the Internet. You will need a VNC server if you want other people to see your desktop. Every VNC server has different strengths and weaknesses and is appropriate for different uses. This section will discuss each of the VNC servers available in Ubuntu, and ways to configure them for most common uses of VNC. The most important thing when setting up a VNC server is to only let the right people access your desktop. The safest way to do that is usually to have someone sitting at the desktop deciding who gets to use it, but that's not always practical - for example, if you want to log in to your own computer from somewhere else. If you want to confirm each connection manually, you should look for these options:

  • Request access each time - pop a window up asking whether to allow each connection as it comes in.
  • view-only access - allow VNC clients to view the destkop, but not to change anything. As well adding a little security, this avoids problems with both of you fighting over control of the mouse.

If you want to access your desktop when nobody is sitting at it, these options will be more useful:

  • Only allow local connections - only let people connect if they already have access to your computer.
  • Start your VNC server in "once" mode - tell your VNC server to allow one connection, then block anything after that
  • Set a password - require people to send a password before they can connect.

These options should give you a secure set-up, so long as they're used with [[UbuntuHelp:[port-forwarding|port-forwarding]]], as discussed above. Only allowing local connections means that only people with user accounts on your computer can access your desktop. Starting the server in "once" mode means that people with user accounts on your computer would have to log in to your desktop between the time you start your VNC server and the time you connect from your VNC client. Setting a password means that, if anyone did try to connect in that brief interval, they probably wouldn't be able to get in before you noticed and stopped the server. Although passwords add some security, hard-to-guess passwords are as difficult to create as they are to remember. If nobody else has access to your computer, you might want to skip passwords altogether.

Vino

Vino is the default VNC server in Ubuntu to share your existing desktop with other users. Unfortunately, a bug in the version that comes with Hardy makes it incompatible with most networks and VNC clients. To configure vino from within GNOME, go to System > Preferences > Remote Desktop

  • To set vino to request access each time, tick Allow other users to view your destkop in the Remote Desktop configuration window
  • There's no way to set vino to only listen for the next connection
  • To set a password, tick Require the user to enter this password:, and enter a hard-to-guess password
  • To put vino in view-only mode, untick Allow other users to control your desktop
  • To only allow local connections, click on the tab marked Advanced, then tick Only allow local connections.

krfb

Krfb is the default VNC server in Kubuntu, and is recommended for KDE users. Because it's highly integrated with KDE, running it in other environments is difficult. To configure krfb, go to System Settings > Sharing > Desktop Sharing > Configure....

  • To set krfb to request access each time, tick Confirm uninvited connections before accepting
  • There's no official way to set krfb to only listen for the next connection, although see below for an unofficial solution
  • To set a password, type a hard-to-guess password into the Password input box
  • To put krfb in view-only mode, untick Allow uninvited connections to control the desktop
  • There's no official way to only allow local connections, although see below for an unofficial solution

Once mode

Krfb doesn't have any official way to accept the next connection then stop listening for connection attempts. However, the following Python script will listen for a single connection then exit krfb:

#!python numbers=off
#!/usr/bin/python

# Load extra functionality from the 'socket' and 'os' modules
from socket import socket, AF_INET, SOCK_STREAM
from os import execl

# Listen for a connection
server = socket(AF_INET, SOCK_STREAM) # This is an Internet (TCP) connection
server.bind(('127.0.0.1', 5900))      # Listen for a local connection on port 5,900
server.listen(1)                      # Listen for exactly 1 connection
sock = server.accept()[0]             # Accept the connection

# Attach krfb to this connection
execl('/usr/bin/krfb', 'krfb', '--kinetd', str(sock.fileno()))

To use this script, open your favourite text editor and paste the contents in. Make sure that the initial '#' character is the very first character in the file, save the file as krfb.py, and set the file's permissions to make it executable. Although this simple program won't open a window of any kind, it will quietly wait for the next VNC client to connect to your computer, then pass the connection through to krfb. This script will only listen for local connections. To allow connections from anywhere, change '127.0.0.1' to '0.0.0.0' in the script.

Invitations

Krfb lets you create "invitations" - individual passwords that are deactivated after an hour or after one use. These are a handy way of giving people one-time access to a computer, but only provide limited security. For example, if you send someone an invitation by e-mail or instant messaging, an attacker could read your invitation message as it went over the Internet and use it to log in. Invitations can be useful when you want to let other people view your desktop, but you still need to follow the precautions discussed [[UbuntuHelp:[let-other-people|above]]].

x11vnc

X11vnc is a VNC server that doesn't depend on GNOME or KDE, and is recommended for use by Xubuntu users. It's designed to be run from the command-line, which makes it flexible but difficult to learn. The few graphical parts of the interface are quite unattractive, because they're designed to work even on a very minimal installation. X11vnc is available in the x11vnc package in the Universe repository. Although x11vnc does have a simple configuration file, it's generally easier to specify options on the command-line. To start x11vnc, type:

x11vnc -safer <options>

<options> is a series of commands separated by spaces. X11vnc has a lot of options, which are discussed fully in the x11vnc man page. Common options include:

  • To set x11vnc to request access each time, include the -nopw -accept popup:0 options
  • To set x11vnc to only listen for the next connection, include the -once option
  • To set x11vnc to continually listen for connections, include the -forever option
  • To set a password, include the -usepw option (and remove the -nopw option above)
  • To put x11vnc in view-only mode, include the -viewonly option
  • To set x11vnc to only allow local connections, include the -localhost option

For example, if you want x11vnc to grant view-only access to the next local connection after asking your permission, type this on the command-line:

x11vnc -safer -localhost -nopw -accept popup:0 -once -viewonly -display :0

If you use a password, you will first need to create a password file by doing:

x11vnc -storepasswd

Make sure to use a hard-to-guess password <<Anchor(x11vnc-before-login)>>

Connecting to your login screen

Because X11vnc is run from the command-line, it can be started while your computer is still showing a login screen. Exactly how to do this depends on which derivative of Ubuntu you use. In Ubuntu (but not Kubuntu or Xubuntu), x11vnc needs superuser access, and needs the -auth /var/lib/gdm/:0.Xauth -display :0 options to be specified on the command-line. You will also need superuser access to edit your /etc/gdm/gdm.conf file, to stop your computer from closing your VNC session after you've typed your username and password. To edit /etc/gdm/gdm.conf, type the following on a command-line:

sudo gedit /etc/gdm/gdm.conf

Search for "!KillInitClients" in that file, and you should see a line that looks like this:

#KillInitClients=true

change that line to look like this:

KillInitClients=false

Then you can run x11vnc before you've logged in by typing something like this:

sudo x11vnc -safer -localhost -once -nopw -auth /var/lib/gdm/:0.Xauth -display :0

(Thanks to the x11vnc FAQ for this tip)

tightvncserver

Whereas most VNC servers share your desktop, tightvnc creates a completely new desktop, not attached to any actual screen. This makes it much less useful for some things (like remote help), but much more useful for others (like creating a public area for collaboration). If tightvncserver won't start, you might need to uncomment the `$fontpath` lines in /etc/vnc.conf. Like x11vnc, tightvnc is designed to be run from the command-line. To start it, type:

tightvncserver -nolisten tcp :1

This will tell tightvnc to listen for VNC connections on port 5,901 from anywhere on the Internet. Without the -nolisten tcp option, tightvnc will also listen for a different type of connection (X11 instead of VNC), which isn't usually very useful. Tightvnc's unusual design means that it can't create a remote desktop on the standard VNC port (5,900) if you have an ordinary desktop running on your computer.

  • There's no way to set tightvncserver to request access each time
  • There's no way to set tightvncserver only to accept the next connection, although see below for a similar solution
  • Tightvncserver always requires a password, and will ask you to specify one the first time it's run
  • There's no way to put tightvncserver in view-only mode
  • To set tightvncserver to only allow local connections, include the -localhost option

Once mode

Tightvncserver can't be set to accept the next connection then stop listening for connection attempts. But it can be set to automatically disconnect each client when the next client connects, and can be stopped after your connection is disconnected. To only allow local connections and automatically disconnect clients, start tightvnc by typing:

tightvncserver -nolisten tcp -localhost -nevershared :1

Then when your client is disconnected by the next client connecting, type:

tightvncserver -kill :1

Similar applications

  • GNU Screen allows you to open, share, disconnect, and later return to a text-based terminal.
  • directvnc is a VNC server that shares a Linux framebuffer instead of a desktop
  • linuxvnc is a VNC server that shares a text-based console instead of a desktop
  • xrdp is a server for Microsoft's Remote Desktop protocol, a client for which comes with all modern versions of Windows
  • xserver-xephyr allows you to create a desktop within a desktop on a single computer
  • Apple Remote Desktop is a desktop sharing application for Mac OS that includes a VNC server

Guide to example scenarios

This section discusses some situations where you would want to use VNC, and how to set a server up for that situation. The first scenario ("Accessing your PC") describes how to set VNC up for a computer that logs in automatically as soon as it starts up. Because accessing a shared login screen requires more security privileges than accessing your personal desktop, the second scenario ("Accessing a family PC") describes the extra steps you need to take in order to access your computer before you've logged in. <<Anchor(accessing-your-pc)>>

Accessing your PC over the Internet

This section describes how to connect to your own desktop computer from somewhere else on the Internet. See below for instructions about logging in to a shared computer. To set your VNC server up, follow these steps. You should only need to do this once:

  1. Install the x11vnc and openssh-server packages on your PC.
  2. If you have previously reconfigured the firewall on your PC, make sure the firewall allows incoming connections on port 22 from anywhere, and on port 5900 from localhost (also known as 127.0.0.1).
  3. If your PC is behind a home router, or any other device that uses NAT, configure|your router to send connection attempts on port 22 (but not port 5900) to your computer.
  4. Choose an SSH client for the computer you'll log in from, and create a public key for that computer.
  5. In a text editor on your PC, open the file <home>/.ssh/authorized_keys, then add the public key you just created to the bottom of the file.

Each time you want to connect to your PC, follow these steps:

  1. Find your PC's public name or IP address. Unless your computer has been assigned a memorable name, the easiest way to do this is to go to www.whatismyip.com from your PC. You can assign your computer a name by getting one from a dynamic DNS provider.
  2. Start an SSH session on your PC with your SSH client, use local port-forwarding to connect port 5,900 on your desktop to port 5,900 on localhost, and run the command `x11vnc -safer -localhost -nopw -once -display :0`
  3. Start your VNC client, and connect to localhost port 5,900

If you have a dial-up Internet connection, your IP address will change every time you connect to the Internet. If you have a broadband Internet connection, your address will probably only change once every few months - usually right around the day you forget to check your address. If you were connecting from an Ubuntu computer with a command-line VNC client, you could do the following on a command-line:

ssh -f -L 5900:localhost:5900 <your-name>@<your-computer> \
	x11vnc -safer -localhost -nopw -once -display :0 \
	&& sleep 5 \
	&& vncviewer localhost:0

If the above VNC connection is terribly slow, then you may need to enable a compression mechanism, e.g., vncviewer -encodings "tight" localhost:0. Alternatively, if your VNC viewer supports the "-via" option (e.g., xtightvncviewer does so) then you need neither manual port-forwarding nor manual settings for compression. Instead, you SSH into the remote computer, start the VNC server with x11vnc -safer -localhost -nopw -once -display :0 and, again on your client machine, start the client with the following command line:

vncviewer -via <your-name>@<your-computer> localhost:0

In Ubuntu, the vncviewer command will run whichever VNC client you have installed.

Accessing a family PC over the Internet

Accessing a family PC is a similar problem to accessing your own PC, except that the VNC server needs more security privileges in order to show your login screen. First, make sure that you can [[UbuntuHelp:[accessing-your-pc|access your own desktop after logging in]]] - once you've logged in, accessing a shared PC is no different to accessing your own PC. Second, follow the instructions to [[UbuntuHelp:[x11vnc-before-login|get x11vnc working before you log in]]]. After this step, you should start the VNC server on the family PC with superuser privileges:

ssh -L 5900:localhost:5900 <your-name>@<your-computer>
sudo x11vnc -safer -localhost -nopw -once -auth /var/lib/gdm/:0.Xauth -display :0

Then connect your VNC client in the same way you did before.

Further information

Remote desktop solutions are a broad and complex topic. The following links provide more detail about the technologies involved: