I have been struggling for a few days getting a vnc server to work in my new Debian server with xfce desktop. Doing google searches returns a wealth of “try this and see if it sticks to the wall” type approach. Well, not satisfied with that I am attempting to explain here every line in a common /home/username/.vnc/xstartup file, so when you go for troubleshooting you can fix things yourself more intelligently. Feel free to comment if you can add more to this thread.
Common xstartup file lines and their meaning:
#!/bin/sh
First line of any executable script. The file needs execute permissions to run (obviously). That’s “chmod 755 xstartup” if you have issues there. Don’t let the leading # comment tag fool you, as this is not really a comment, this is necessary to invoke the /bin/sh shell to run the rest of the lines of the script. This is explained in wikipedia under “shebang (unix)”
# Uncomment the following two lines for normal desktop: unset SESSION_MANAGER exec /etc/X11/xinit/xinitrc
TBD
/usr/bin/xfce4-session
This is where you start your window manager. I am using xfce4. You can also use gnome, kde, cinnamon, etc.
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
The [ -x /something ] construct means “if /something file eXists then”. && is the logical and operator (if 1 and if 2). The way it is implemented here is an if then. Basically this is saying if the /etc/vnc/xstartup file exists then execute it. Otherwise continue on. The /etc/vnc/xstartup file is a system wide kind of file, where the user based xstartup is specific to that user.
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
Same as above. FWIW, I don’t have an /etc/vnc/ directory or a $HOME/.Xresources file, so I could remove / comment these.
xrdb sets the contents of the RESOURCE_MANAGER property on the root window of screen 0. This is where apps get user preferences on color and fonts.
xsetroot -solid grey
Tailors the background of the window, if the widow manager (xfce4) goes away. So, not that important because a vncserver without a xfce4 (or similar) desktop — what’s the point?
vncconfig -iconic &
A helper application for vnc. The option forces it to be iconized
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
This one is odd. You would think the -geometry refers to the geometry of the vnc session, but it does not. This is saying start a console (xterm, or x-terminal-emulator, all programs found in /usr/bin) that is 80 columns wide, 24 columns tall and spaced 10 pixels (both the x and y axis) from the top left corner of the screen. What’s odd? This terminal is behind the vnc x session, so you only see it when you log out of your vnc desktop. Because you don’t go back to a login window manager, only then you see this command prompt. Really, you don’t need this line.
You will set the geometry of the screen elsewhere, in your user profile at computer startup time in the file
/etc/systemd/system/vncserver.service
- or -
/lib/systemd/system/vncserver.service
twm &
or could be x-windows-manager &. This says start the window manager and is the last line in the file.