- ThinkBlog - http://thinkblog.org -

Linux Tip 003 - VNC defaults

Posted By Michael On 8th October 2003 @ 22:25 In Linux | No Comments

When you’re setting up VNC on your Linux box, after you’ve installed it, you should be able to run a server and immediately log in. It’s a good idea to run “vncserver” with at least the following arguments:

  • Display Number. Yes, you could use the default setting for this, which is display number one, but why leave it to chance? If someone logs in before you and is already running an instance of the server, you could be kicked down to a different display number, whose ports you may not have already enabled as potentially penetrable through your firewall (you DO use a firewall, right?). So, specify the port number by using a colon followed immediately by the number of your display.

    If, for instance, I want for vncserver to start on display 1, I would do “:1″ on the command line after the name of the program itself.

  • Screen Geometry. The number of pixels, width-by-height, at which to initialize the instance of the VNC server. Usually, it’s best to make this one iteration lower than your default resolution, so that all of the remote screen will show up in yours. Of course, with resolutions as low as 640×480, this is rarely manageable.
    For instance, since I have my resolution on my main screen set to 1152×864 (read “eleven fifty-two by eight-sixty-four”), I would specify on the command line “-geometry 1024×768″. Alternately, if my local geometry is set to 1024×768 already, I would specify “-geometry 800×600″.
  • Bit Depth. Bit depth is a number specifying how deep your colors will be. Essentially, the higher this number is, the more space each pixel (”picture element,” or little dot) on your screen takes up in memory. Since I only have 256MB RAM in my local computer and even less in my remote Linux box, I set this to 16, one of three plausible settings. The reasonable settings are 8-bit (which renders 256 colors, like an old VGA display from the days of denim and leather), 16-bit (sixteen million plus colors), or 32-bit (virtually every color discernible by the average human eye). Sixteen bits is the best compromise between speed and usability, because let’s face it–there are few programs these days optimized for viewing at 256 colors, and fewer still apart from games that can take advantage of the highest setting).
    So then, on the command line, “-depth 16″.
  • Color Compression. This is a rather VNC-specific setting expressed in a range from 1 to 4, lowest to highest quality. 1 is the highest compression, which renders more quickly through thin pipes (low-bandwidth situations), but looks hazy and grainy, uncomfortably pixellated. 4 is the highest quality, lowest compression, and is suitable for high-bandwidth situations, such as a LAN like the one connecting my local box to the “remote” Linux server.
    The command line option for color compression is “-cc”, so for my setting, “-cc 4″.

So to recap, the full command line would read thus:

$ vncserver :1 -geometry 1024x768 -depth 16 -cc 4

Now, when you log in for the first time, you might be surprised to find yourself staring at a simple command line window sitting on a barren checkerboard background; and if you run a program from the command line, it pops up with an outline window that you must manually place with the mouse! This is what a [1] Motif setup looks like, and is the most bare-bones graphical user interface available. You’re not actually running Motif, though, you’re running TWM, a highly sparse window manager for POSIX-compliant operating systems (Linux and UNIX are two major ones). This is because, for whatever reason, your Xstartup file wasn’t copied correctly to VNC, so vncserver wrote its own little startup file. If you want to see what it looks like, you can do a “cat ~/.vnc/xstartup” from the commandline when you’re logged in, and the last line on there you’ll see will have “twm&“, which basically tells the window manager you’re looking at right now to run itself.

To correct this problem, assuming you already have a startup file for the X Window System (if you can log in locally to your box and it’s all nice and pretty and comes up with a GNOME or KDE system, you’re fine), you’ll just need a solid text editor (like [2] Emacs or vi, though the former is FAR SUPERIOR). You can stay in your TWM commandline or log in through SSH and execute the following commands to rectify this situation.

FIRST, back up your existing VNC xstartup file:
$ mv ~/.vnc/xstartup ~/.vnc/xstartup.BAK

SECOND, initialize your text editor with a replacement copy of xstartup:
$ emacs ~/.vnc/xstartup

THIRD, place into the file the following text:
#!/bin/sh
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc

Save and close the file (”C-x C-s C-x C-c” in Emacs), and kill the current VNC server. Assuming that your display is 1, the command follows:
$ vncserver -kill :1

Then, restart the VNC server thus (or however you usually do):
$ vncserver :1 -geometry 1024x768 -depth 16 -cc 4

Log in to your server through VNC—behold! There have you your precious GUI!

Linux Tip 003 - VNC defaults

Posted By Michael On 8th October 2003 @ 22:25 In Linux | No Comments

When you’re setting up VNC on your Linux box, after you’ve installed it, you should be able to run a server and immediately log in. It’s a good idea to run “vncserver” with at least the following arguments:

  • Display Number. Yes, you could use the default setting for this, which is display number one, but why leave it to chance? If someone logs in before you and is already running an instance of the server, you could be kicked down to a different display number, whose ports you may not have already enabled as potentially penetrable through your firewall (you DO use a firewall, right?). So, specify the port number by using a colon followed immediately by the number of your display.

    If, for instance, I want for vncserver to start on display 1, I would do “:1″ on the command line after the name of the program itself.

  • Screen Geometry. The number of pixels, width-by-height, at which to initialize the instance of the VNC server. Usually, it’s best to make this one iteration lower than your default resolution, so that all of the remote screen will show up in yours. Of course, with resolutions as low as 640×480, this is rarely manageable.
    For instance, since I have my resolution on my main screen set to 1152×864 (read “eleven fifty-two by eight-sixty-four”), I would specify on the command line “-geometry 1024×768″. Alternately, if my local geometry is set to 1024×768 already, I would specify “-geometry 800×600″.
  • Bit Depth. Bit depth is a number specifying how deep your colors will be. Essentially, the higher this number is, the more space each pixel (”picture element,” or little dot) on your screen takes up in memory. Since I only have 256MB RAM in my local computer and even less in my remote Linux box, I set this to 16, one of three plausible settings. The reasonable settings are 8-bit (which renders 256 colors, like an old VGA display from the days of denim and leather), 16-bit (sixteen million plus colors), or 32-bit (virtually every color discernible by the average human eye). Sixteen bits is the best compromise between speed and usability, because let’s face it–there are few programs these days optimized for viewing at 256 colors, and fewer still apart from games that can take advantage of the highest setting).
    So then, on the command line, “-depth 16″.
  • Color Compression. This is a rather VNC-specific setting expressed in a range from 1 to 4, lowest to highest quality. 1 is the highest compression, which renders more quickly through thin pipes (low-bandwidth situations), but looks hazy and grainy, uncomfortably pixellated. 4 is the highest quality, lowest compression, and is suitable for high-bandwidth situations, such as a LAN like the one connecting my local box to the “remote” Linux server.
    The command line option for color compression is “-cc”, so for my setting, “-cc 4″.

So to recap, the full command line would read thus:

$ vncserver :1 -geometry 1024x768 -depth 16 -cc 4

Now, when you log in for the first time, you might be surprised to find yourself staring at a simple command line window sitting on a barren checkerboard background; and if you run a program from the command line, it pops up with an outline window that you must manually place with the mouse! This is what a [7] Motif setup looks like, and is the most bare-bones graphical user interface available. You’re not actually running Motif, though, you’re running TWM, a highly sparse window manager for POSIX-compliant operating systems (Linux and UNIX are two major ones). This is because, for whatever reason, your Xstartup file wasn’t copied correctly to VNC, so vncserver wrote its own little startup file. If you want to see what it looks like, you can do a “cat ~/.vnc/xstartup” from the commandline when you’re logged in, and the last line on there you’ll see will have “twm&“, which basically tells the window manager you’re looking at right now to run itself.

To correct this problem, assuming you already have a startup file for the X Window System (if you can log in locally to your box and it’s all nice and pretty and comes up with a GNOME or KDE system, you’re fine), you’ll just need a solid text editor (like [8] Emacs or vi, though the former is FAR SUPERIOR). You can stay in your TWM commandline or log in through SSH and execute the following commands to rectify this situation.

FIRST, back up your existing VNC xstartup file:
$ mv ~/.vnc/xstartup ~/.vnc/xstartup.BAK

SECOND, initialize your text editor with a replacement copy of xstartup:
$ emacs ~/.vnc/xstartup

THIRD, place into the file the following text:
#!/bin/sh
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc

Save and close the file (”C-x C-s C-x C-c” in Emacs), and kill the current VNC server. Assuming that your display is 1, the command follows:
$ vncserver -kill :1

Then, restart the VNC server thus (or however you usually do):
$ vncserver :1 -geometry 1024x768 -depth 16 -cc 4

Log in to your server through VNC—behold! There have you your precious GUI!

  • Learn more about [9] VNC.
  • Learn more about [8] Emacs.
  • Learn more about [11] denim and [12] leather!

Article printed from ThinkBlog: http://thinkblog.org

URL to article: http://thinkblog.org/2003/10/08/linux_tip_003_vnc_defaults/

URLs in this post:
[1] Motif: http://www.opengroup.org/motif/
[2] Emacs: http://www.gnu.org/software/emacs/emacs.html
[3] VNC: http://www.realvnc.com/
[4] Emacs: http://www.gnu.org/software/emacs/emacs.html
[5] denim: http://www.inthe80s.com/clothes/d.shtml
[6] leather: http://www.inthe80s.com/clothes/l.shtml
[7] Motif: http://www.opengroup.org/motif/
[8] Emacs: http://www.gnu.org/software/emacs/emacs.html
[9] VNC: http://www.realvnc.com/
[10] Emacs: http://www.gnu.org/software/emacs/emacs.html
[11] denim: http://www.inthe80s.com/clothes/d.shtml
[12] leather: http://www.inthe80s.com/clothes/l.shtml

Click here to print.