# Running a lightweight GUI on your vps



## wlanboy (Nov 29, 2013)

Even on a low RAM vps you are able to run a desktop environment.

If you do have a lot of free RAM you can even run desktop apps and IDEs like Eclipse on your vps.

I use my KVM vps to have a portable and accessable Ruby and Java development environment.

One of the desktop managers that do have a small footprint is xfce4. So this tutorial is based on that peace of software.

1. Install xfce and a browser (I take iceweasel - well Firefox - due to the Debian Free Software Guidelines)


sudo apt-get install xfce4 xfce4-clipman xfce4-goodies vnc4server iceweasel

2. Configure vnc4server

First of all run vnc4server to generate the configs and to setup the password:


vnc4server 

Type in your password twice and kill the vnc instance:


vncserver -kill :1

Vnc is about virtual displays. Like any x-based system it counts the displays. So ":1" stands for the first display.

Now we change the x windows manager to xfc4:


nano ~/.vnc/xstartup

Exchange "x-window-manager" with "startxfce4":


#!/bin/sh

# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
startxfce4 &

3. Run it

You can start the vnc instance with following command:


vnc4server :1 -geometry 1280x960 -depth 16 -screen scrn 1280x960x16 &

We use "&" to background the process.

Some words to the parameters (manpage):


-geometry widthxheight
Specify the size of the desktop to be created. Default is
1024x768.

-depth depth
Specify the pixel depth in bits of the desktop to be created.
Default is 16, other possible values are 8, 15 and 24 - anything
else is likely to cause strange behaviour by applications.

So why the "-screen" parameter?

Well to do everything twice - or (better idea) to keep my scripts compatible to the package vncserver.

4. Keep it running

One thing that annoys me about this way to startup the vnc server is that it does not survive restarts.

One dirty simple way is to use rc.local


sudo nano /etc/rc.local

With following content:


#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
vncserver -kill :1
su - wlanboy -c "cd /home/wlanboy && vnc4server :1 -geometry 1280x960 -depth 16 -screen scrn 1280x960x16" 2>/dev/null &
exit 0


So what do we do?


Stop a allready running vncserver instance on disply 1
Run a given command (-c) using the user "wlanboy"
The command itself switches to the home direcoty and runs the vnc4server command
You can copy the commands to start additional vnc instances.

Just double check that you alter the display numbers.



One note:

Please deactivate the screen saver because most of them are quite cpu consuming.

*Things to change if you want to run openbox:*

1. Install openbox


apt-get install openbox obconf obmenu menu conky nitrogen

So what are we installing?


openbox - the GUI itself
obconf - the configuration manager of openbox
obmenu - well the menu (right click) of openbox
conky - a nice system monitor
nitrogen - a lightweight desktop background browser
tint2 - a lightweight window manager for openbox
2. Change vnc config


nano ~/.vnc/xstartup


```
#!/bin/sh

# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
openbox-session &
```
Just the last line has to be modified.


----------



## Francisco (Nov 29, 2013)

Post a free -m 

Francisco


----------



## nunim (Nov 30, 2013)

You should look into NX, I prefer the NoMachine version but FreeNX isn't bad.  They just discontinued their 3.5.x series to try and push their newer 4.x which I think is crap, it gobbles way more resources but it does have an Android client coming "Soon™"..  One of the good things about NX is that you can copy/paste across it, which is something I've never had much luck with in VNC.  I feel that NX is just like RDP, except it seems slightly faster.

I used to have a guide for it on my blog but I haven't bothered to put it back up, I managed to snag copies of all the most recent NX binaries and I have a script to install NoMachine+LXDE or XFCE, if anyone's interested. I prefer LXDE if you're trying to use it in a low memory environment as it uses less resources, I had a desktop running on a SecureDragon 128 for awhile, you really don't need anything fancy 

For Fran (it would be lighter with LXDE and without IceWeasel eating 60% of the ram):


----------



## fixidixi (Nov 30, 2013)

Yeah definately: you should stick wit nomachine or x2go. much better perfomance..


----------



## professionalxen (Nov 30, 2013)

Fairly good & useful tutorial.

Good job.


----------



## WelltodoInformalCattle (Nov 30, 2013)

nunim said:


> You should look into NX, I prefer the NoMachine version but FreeNX isn't bad.  They just discontinued their 3.5.x series to try and push their newer 4.x which I think is crap, it gobbles way more resources but it does have an Android client coming "Soon™"..  One of the good things about NX is that you can copy/paste across it, which is something I've never had much luck with in VNC.  I feel that NX is just like RDP, except it seems slightly faster.
> 
> I used to have a guide for it on my blog but I haven't bothered to put it back up, I managed to snag copies of all the most recent NX binaries and I have a script to install NoMachine+LXDE or XFCE, if anyone's interested. I prefer LXDE if you're trying to use it in a low memory environment as it uses less resources, I had a desktop running on a SecureDragon 128 for awhile, you really don't need anything fancy
> 
> For Fran (it would be lighter with LXDE and without IceWeasel eating 60% of the ram):


 
How did you manage to grab 3.5? Is there any way that this script could be updated or if you would kindly send me the link? http://lowendtalk.com/discussion/3603/remote-desktop-vps


----------



## nunim (Dec 1, 2013)

WelltodoInformalCattle said:


> How did you manage to grab 3.5? Is there any way that this script could be updated or if you would kindly send me the link? http://lowendtalk.com/discussion/3603/remote-desktop-vps


Updated to what?
I have all the 3.5.x binaries saved, for Linux, Mac & Win.  If I have time tomorrow I'll double check the support for newer Ubuntus and post it.


----------



## WelltodoInformalCattle (Dec 1, 2013)

nunim said:


> Updated to what?
> 
> I have all the 3.5.x binaries saved, for Linux, Mac & Win.  If I have time tomorrow I'll double check the support for newer Ubuntus and post it.


Couldn't edit out the "updated" bit. But yes, it would be amazing if you by any chance could get it up pllleeeeeeeeaaaaaseeeeeee


----------



## bauhaus (Dec 2, 2013)

Your tuto is great as always @wlanboy, but LXDE or OpenBox are more lightweight than XFCE as window manager. Personally, I like the OpenBox+XFCE approach in this type of scenario.


----------



## wlanboy (Dec 2, 2013)

nunim said:


> You should look into NX, I prefer the NoMachine version but FreeNX isn't bad.  They just discontinued their 3.5.x series to try and push their newer 4.x which I think is crap, it gobbles way more resources but it does have an Android client coming "Soon™"..  One of the good things about NX is that you can copy/paste across it, which is something I've never had much luck with in VNC.  I feel that NX is just like RDP, except it seems slightly faster.
> 
> I used to have a guide for it on my blog but I haven't bothered to put it back up, I managed to snag copies of all the most recent NX binaries and I have a script to install NoMachine+LXDE or XFCE, if anyone's interested. I prefer LXDE if you're trying to use it in a low memory environment as it uses less resources, I had a desktop running on a SecureDragon 128 for awhile, you really don't need anything fancy


Same with me - don't like 4.x and did not want to post an tutorial with following line:


"Please download binaries from my homepage..."



nunim said:


> Updated to what?
> 
> I have all the 3.5.x binaries saved, for Linux, Mac & Win.  If I have time tomorrow I'll double check the support for newer Ubuntus and post it.


Looking forward to your post.



bauhaus said:


> Your tuto is great as always @wlanboy, but LXDE or OpenBox are more lightweight than XFCE as window manager. Personally, I like the OpenBox+XFCE approach in this type of scenario.


Yup the old discussion of XFCE vs LXDE. I do prefer xfce4. Maybe my decission is based on Lubuntu and I have to look again at LXDE again because Linux Mint did a good job.


Maybe you can add some lines for the LXDE path?

Beside that I allready started to look into OpenBox:





Francisco said:


> Post a free -m
> 
> 
> Francisco


It is the "vnc" container running xfce4.


----------



## WelltodoInformalCattle (Dec 3, 2013)

Tried XFCE and LXDE simply to see which one seemed to be less of a resource hog (this clearly wasn't an exhaustive test) than the other and it seemed like LXDE won that 'competition'.


----------



## InertiaNetworks-John (Dec 3, 2013)

Thnaks for the tutorial!


----------



## bauhaus (Dec 3, 2013)

wlanboy said:


> Yup the old discussion of XFCE vs LXDE. I do prefer xfce4. Maybe my decission is based on Lubuntu and I have to look again at LXDE again because Linux Mint did a good job.


I'm not a LXDE fan, I just mentioned because if you are using a Desktop Environment for you remote desktop, LXDE is more lightweight than XFCE. Now if you choose OpenBox as a Window Manager and keeping XFCE without xfwm4 that is a winning solution. Of course, the differences between xfwm4 and openbox are really more about choice, as always in linux world. Both are fast, small memory footprint, etc. But in my experience for a remote desktop openbox is better because is more efficient and less obtrusive. Good to see you are already checking it out.


----------



## nunim (Dec 4, 2013)

I've been pretty busy, had a nasty bug to fix in Debian x64 before I could release this into the wild but here it is:

Tested on Debian 7 & Ubuntu 12-13


wget http://www.sonicboxes.com/nx/autolxde.sh
chmod 755 autolxde.sh
./autolxde.sh

For full tutorial & links to Clients for Win, Linux, OSX & Solaris, See - http://www.sonicboxes.com/lowmem-debian-lxde-nomachine-script/

I believe you can also use the OpenNX as their client is supposed to be a drop in replacement but I have not tested these and thus cannot offer any support  When I get some time I'll write up an actual VPSB tutorial for this, in the meantime enjoy the script..


----------



## wlanboy (Dec 7, 2013)

I have updated the tutorial to add information about openbox.


----------



## Alto (Dec 9, 2013)

@nunim, I've been using that script whenever I needed a quick RDP setup for the last year or so, never realised it was yours, so thanks for putting it together; it's been a massive help to me on a number of occasions.

My only issue with NX 3.5 is that there's no way of getting it to play nice with iOS devices, but for desktop OS it's pretty much perfect IMO.


----------



## nunim (Dec 9, 2013)

Alto said:


> @nunim, I've been using that script whenever I needed a quick RDP setup for the last year or so, never realised it was yours, so thanks for putting it together; it's been a massive help to me on a number of occasions.
> 
> My only issue with NX 3.5 is that there's no way of getting it to play nice with iOS devices, but for desktop OS it's pretty much perfect IMO.


You're welcome   That's about my only complaint with NX, NoMachine is working on an iOS/Android client but it will likely be 4.x only when it is released.


----------



## WelltodoInformalCattle (Dec 9, 2013)

4.x currently just seems like such a pain in the arse to get up and running, thanks for the script @nunim, my lazy ass can't be bothered to spend so much time trying to get things functioning as desired.


----------



## wlanboy (Dec 10, 2013)

Thank you for the input - like your script and will look into the internals too.


----------



## ubayogi (Mar 23, 2014)

nunim said:


> I've been pretty busy, had a nasty bug to fix in Debian x64 before I could release this into the wild but here it is:
> 
> Tested on Debian 7 & Ubuntu 12-13
> 
> ...


Could you please restore the various download links referred by the script as well as the client download link provided in your tutorial. I used to use 3.5 on several Ubuntu LTS 12.04 amd64 machines last year. Worked fantastic. Now I don't have the binaries and NX 4 sucks. Spent a whole day & unable to get it working.


----------



## nunim (Mar 23, 2014)

ubayogi said:


> Could you please restore the various download links referred by the script as well as the client download link provided in your tutorial. I used to use 3.5 on several Ubuntu LTS 12.04 amd64 machines last year. Worked fantastic. Now I don't have the binaries and NX 4 sucks. Spent a whole day & unable to get it working.


Apologies, I recently changed my website configuration, moved away from VestaCP on that server and forgot to restore the subdomain with the NX files, it should be working properly now.


----------



## ubayogi (Mar 24, 2014)

nunim said:


> Apologies, I recently changed my website configuration, moved away from VestaCP on that server and forgot to restore the subdomain with the NX files, it should be working properly now.


No need to apologize. You did us a favor. Runs fantastic and able to connect now. Thanks a million. 


su username
Now just got to figure how to switch from nomachine user to default ubuntu user on AWS. AWS issues private key and no password for default user. *su* expects a password.  :unsure:


----------



## nunim (Mar 25, 2014)

ubayogi said:


> No need to apologize. You did us a favor. Runs fantastic and able to connect now. Thanks a million.
> 
> 
> su username
> Now just got to figure how to switch from nomachine user to default ubuntu user on AWS. AWS issues private key and no password for default user. *su* expects a password.  :unsure:


My suggestion would be to add your NoMachine user to sudoers, then do sudo su after you've logged into NX.


----------



## ubayogi (Mar 25, 2014)

nunim said:


> My suggestion would be to add your NoMachine user to sudoers, then do sudo su after you've logged into NX.


Perfect, that got me to where I wanted. Ran into another roadblock. As nomachine user I'm able to launch GUI programs from a LXTerminal (say Firefox). When I try the same after switching to user ubuntu, I get the following error:



[email protected]:~$ firefox
No protocol specified
No protocol specified
No protocol specified
No protocol specified
Error: cannot open display: :1002

What I notice is user nomachine has the following additional files and folders. Not sure if that makes any difference.



```
.config  Desktop  .kde  .mcoprc  .nx .qt  .Xauthority
```


----------



## drmike (Mar 25, 2014)

Folks here like to lure me and have me spend days on these ideas  Cruel.

Been using x2go.   I can't speak highly enough of it.  1GB VPS with 1GB of swap.... Runs better than my idiotic old dumb-like terminals which I run the client from.

Blows VNC away, way more responsive.   Plus it's wrapped in SSH tunnel so snooping takes some crypto conquering.


----------



## nunim (Mar 25, 2014)

ubayogi said:


> Perfect, that got me to where I wanted. Ran into another roadblock. As nomachine user I'm able to launch GUI programs from a LXTerminal (say Firefox). When I try the same after switching to user ubuntu, I get the following error:
> 
> 
> 
> ...


Run the following as your NX user:


sudo apt-get -y --no-install-recommends install gksu
gksudo firefox
FireFox will now be running as root.


----------



## ubayogi (Mar 25, 2014)

nunim said:


> Run the following as your NX user:
> 
> 
> sudo apt-get -y --no-install-recommends install gksu
> ...


We are using ubuntu as a service account to run several applications. I now want to install and run an additional software as user ubuntu. Unfortunately this particular software is GUI only and no command line. Doing it through X forwarding was very painful and hence adopted NX. As much as I can, don't want to move away from service account just to run something GUI.


----------



## ubayogi (Mar 29, 2014)

I was able to set a password for user ubuntu and now it allows me to connect to NX. I'm able to run and view GUI as user ubuntu. However, I'm ran into a different issue. Took an Amazon image backup of existing NX machine that works good and launched a new instance from the image. Attempting to connect to it from nx client, I get,


The session negotiation failed.
Error: Authentication failed
Checked no change in username, password across both instances. Checked NX server is running in the new instance. Checked authentication for user: ubuntu is: system. Checked passwordauthentication is set to yes in sshd_config. Basically all settings are ditto in both machines. NX works good in the parent machine where it was originally installed but not on the child created from an image.

Any pointers on where I should start looking at? (I know hostname & internal IP changes for each instance. Will that be causing issues? I tried grep'ing for hostname references inside ~/.nx and /usr/NX directories, no luck so far.)


----------



## nunim (Mar 29, 2014)

ubayogi said:


> I was able to set a password for user ubuntu and now it allows me to connect to NX. I'm able to run and view GUI as user ubuntu. However, I'm ran into a different issue. Took an Amazon image backup of existing NX machine that works good and launched a new instance from the image. Attempting to connect to it from nx client, I get,
> 
> 
> The session negotiation failed.
> ...


Have you checked the NX log and see if it reveals the error?  I'm not that familiar with the AWS template system, is all information saved across, i.e. SSH keys?  

See this page for NoMachine error log info:

https://www.nomachine.com/AR08J00651


----------



## ubayogi (Mar 30, 2014)

Thanks for the link, I'll check the logs. Curious why you mention SSH keys since I been using username password to login via NX and not key based login.

Could you please also let me know how to correctly uninstall/roll back the NX installation done by the script. The lxde stuff can stay, just the NX portions. What I'm thinking as a workaround is to uninstall NX completely and re-install again to see if that helps.


----------



## nunim (Mar 30, 2014)

ubayogi said:


> Thanks for the link, I'll check the logs. Curious why you mention SSH keys since I been using username password to login via NX and not key based login.
> 
> Could you please also let me know how to correctly uninstall/roll back the NX installation done by the script. The lxde stuff can stay, just the NX portions. What I'm thinking as a workaround is to uninstall NX completely and re-install again to see if that helps.


 

I'm just wondering, as I said I'm not that familiar with the template system on AWS.  If it's an auth problem then I was thinking maybe the keys are mismatched or something similar, however I'm not sure. 

 

Did the error log shed any light on the problem? 


 

To remove all NoMachine software:

 

apt-get purge nxnode nxclient nxserver


----------



## ubayogi (Mar 31, 2014)

@nunim You were spot on. It was in fact the SSH keys that was causing the problem. Relevant lines from the log.



NXSERVER-3.5.0-11[3345]: Failed SSHd authentication for user 'ubuntu', to '127.0.0.1', port '22': 'NX> 204 Authentication failed.

WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the-middle attack) It is also possible that the RSA host key has just been changed. The fingerprint for the RSA key sentby the remote host is x6:73:00:78:82:xx:3x:xx:xx:6x:x9:xx:13:00:13:x0

Please contact your system administrator. Add correct host key in /usr/NX/home/nx/.ssh/known_hosts to get rid of this message. Offending key in /usr/NX/home/nx/.ssh/known_hosts

Password authentication is disabled to avoid man-in-the-middle attacks. Keyboard-interactive authentication is disabled to avoid man-in-the-middle attacks.
Not sure if its the right thing to do, but, following steps made it work.


Edited /home/ubuntu/.ssh/authorized_keys2 and changed the [email protected] reference to point to the current hostname. It was pointing to the name of the original machine on which AMI image was taken.
Copied private key contents in /etc/ssh/ssh_host_rsa_key from the original machine (AMI image source) to the same file in problem machine.
Restarted sshd and NX started working  
The above steps worked irrespective of new instance sharing the same SSH keypair as the original machine or launched with its own new keypair. I'm sure I maybe violating few unwritten SSH laws by doing this copying thing. If any of you know the right way to go about this, I'm all ears  

Purpose is to have NX pre-installed & available on AMI image. And get NX working in new child instances with minimal effort. I could have as well run nunim's script on new instances, but I went ahead and built several custom images before running into this issue. Each image has a lot of other software combinations. Don't want to redo all of them now.


----------



## nunim (Mar 31, 2014)

ubayogi said:


> ... The above steps worked irrespective of new instance sharing the same SSH keypair as the original machine or launched with its own new keypair. I'm sure I maybe violating few unwritten SSH laws by doing this copying thing. If any of you know the right way to go about this, I'm all ears ...


If it works, it works   Glad to hear that you've gotten it working.


----------



## mikedep333 (May 2, 2014)

drmike said:


> Folks here like to lure me and have me spend days on these ideas  Cruel.
> 
> Been using x2go.   I can't speak highly enough of it.  1GB VPS with 1GB of swap.... Runs better than my idiotic old dumb-like terminals which I run the client from.
> 
> Blows VNC away, way more responsive.   Plus it's wrapped in SSH tunnel so snooping takes some crypto conquering.


As an X2Go Developer, this warms my heart.

To be fair, VNC can be tunneled over SSH also.

We have basically the same performance as NX3 because we use their code for graphics and input. X2Go, NX3, RDP, SPICE and Citrix all use client-side rendering. VNC uses server-side rendering instead, which we consider a worse design, especially in terms of performance. However, unlike NX3, we are actively maintained. (NX4 is maintained, but is proprietary.) And we have additional features such as folder sharing.

Anyway, I just wrote this thread with instructions on using X2Go instead of VNC:


----------



## TheSkyspace_Natalie (May 27, 2014)

Fairly good & useful tutorial.

Good job.


----------



## cspacews (May 29, 2014)

Good Job :lol:

Thanks


----------



## willie (May 29, 2014)

Man I'm horrified.  VNC has been useful for KVM configuration and could be ok for occasionally poking things, but trying to get real work done on it sounds unbearable.  Maybe it's better with superfast internet.  Also it's usually unencrypted so you're sending all your passwords etc. in the clear.  Are you tunnelling it through a vpn or anything?

My favorite lightweight window manager is xmonad (xmonad.org).


----------



## nunim (Jan 20, 2015)

Alto said:


> @nunim, I've been using that script whenever I needed a quick RDP setup for the last year or so, never realised it was yours, so thanks for putting it together; it's been a massive help to me on a number of occasions.
> 
> My only issue with NX 3.5 is that there's no way of getting it to play nice with iOS devices, but for desktop OS it's pretty much perfect IMO.


*Update:*  There is a NoMachine client available for Android/iOS, it supports 3.5 and 4.0 and it works perfectly with my script with a little configuration on the client end.

*Android:*

APK -  https://www.nomachine.com/download/download&id=68

Google Play - https://play.google.com/store/apps/details?id=com.nomachine.nxplayer

*iOS* - https://itunes.apple.com/us/app/nomachine/id874286563?mt=8


----------



## mehargags (Feb 25, 2015)

So now at present in 2015 -- which version of NoMachine you still prefer ? 3.5 or 4.x ?

which one works better than tightVNC ?


----------



## nunim (Mar 1, 2015)

mehargags said:


> So now at present in 2015 -- which version of NoMachine you still prefer ? 3.5 or 4.x ?
> 
> which one works better than tightVNC ?


I still prefer 3.5 by a long shot as 4.x is an entirely different beast.

Taken from the NoMachine download page:


NoMachine NX Free Edition 3 users read here:

The free NoMachine 4 is a new product aimed at a different use case. While NoMachine NX Free Edition 3 offered a free terminal server with virtual desktops created on demand, the free NoMachine 4 is designed to work the same across Windows, Mac and Linux and give users access to the physical desktop of the remote computer. If you need to create virtual desktops on demand, want to limit the logins to SSH, or are using NIS, Kerberos or other enterprise server functionalities, you need one of the NoMachine Enterprise server products you can download here. 

Note that you can use NoMachine 4 as a client of an Enterprise server, or you can download the free Enterprise client here.

[SIZE=10.5pt]Essentially the free version of NX 4 is VNC while free 3.5 offered up to 2(?) simultaneous virtual terminal sessions.[/SIZE]

[SIZE=10.5pt]I tried a fresh installation of 4.x to see if I liked it any better but it's just as awful as ever.  There's seemingly a lack of documentation/guides for 4.x, the installation was far more confusing (especially vs. using my script for 3.5) not made any better by my lack of familiarity with RunAbove's network management system.  An important note is that free 4.x doesn't allow connections via SSH, only via the NX protocol (Port 4000).[/SIZE]


----------



## howardsl2 (Mar 1, 2015)

Personally I like NoMachine 3.5. Version 4 is a pain to use. Unfortunately they had pulled version 3.5 downloads from the official NX website. I managed to get them from an alternative site.


----------



## VENETX (Mar 2, 2015)

Thanks for the tutorial.

A lot of people were asking me If I knew a light weigh GUI. Ill just link them to here 

Thanks again


----------

