Sunday, May 13, 2007

Setting up a home server: Part One (Remote Access)

Recently I have been in the mood to get myself a good home multimedia, web and file server going. I have all of the networking set up already to allow me to do this and I have a spare machine knocking around which is ideal for the job. The machine in question is an AMD3200+ with 1mb RAM and 320gb of storage. My plan is to have this sat in my utility cupboard connected via WiFi to my network. I should then be able to access this nicely from my Mac.

The first job I have is installing an operating system on my server and allowing myself remote access. Ideally I should be able to get a remote desktop up and running straight from the Mac.

I decided that my operating system of choice would be Linux. Mainly because I don't want to pay for Windows. I decided that my distribution of choice would be Ubuntu. This is fairly simple to set up and so I won't bother going through that with you. For reference, when people read this hundreds of years in the future, the version I installed is Feisty Fawn (they have such stupid names).

After messing about with all of the new features in Ubuntu for a few hours I was ready to get down to some real work. By default Ubuntu comes with vino which should really offer me remote desktop access straight out of the box. It does do as promised but it is extremely slow and I don't like it one bit.

After a bit of digging around I found NoMachine's website. They offer server and client software that should be exactly what I need. This software is called NXServer and I decided that I would give this a go.

The first step was to install the Mac Client which was a piece of cake (you might need to install X11 for Mac as well). Next came the install on Linux. Not quite so simple. Firstly you will need to enable ssh access to your Linux box, to do this you need to type the following into a terminal:

sudo apt-get install openssh-server


Once this is done we can get on with installing the free NX Server software. There are three parts that are required for this. First you will need to install nxclient, then you will need nxnode and finally nxserver. These come in .deb format and the default option when downloading with Firefox is to install them so I just clicked OK.

Hopefully all of that went ok and you should now have nxserver installed. The next step is to test out our connection. On your Linux server enter into the terminal:

ifconfig


In here you should be able to find your IP address, you will need to know this to connect from the Mac.

In your Mac Applications folder you should be able to find a program called NX Connection Wizard.



Launching this will take you step by step through setting up your connection. You will need to enter the IP address in the host section of the first screen and choose Gnome as your default desktop but that's really all there is to it.



Once you are finished here you should be presented with a log in screen for your Linux username and password. Simply enter them and click Login.



If everything went well you should now have a nice Linux desktop.



Unfortunately everything is probably not as well as it looks. Try opening a terminal and typing something in. Not working as expected? It didn't work properly for me either.

This keyboard mapping issue seems to only appear if you use Gnome. If you are a KDE (or any other DE) user then everything is probably fine and you can stop reading at this point. Unfortunately, I really like Gnome so we will have to keep going.

There are a few things you need to check in X11 first. In the preferences you need to make sure that only the "Emulate three button mouse" option is selected. The others will cause more keyboard issues.



The only workaround I could find for this issue is to capture the keyboard settings from a remote login through the OS X terminal and then load them again through the nx client.

To do this we need to launch a terminal in OS X through X11 and ssh into the Linux box. You can open a terminal from the X11 applications menu and the command to use should be something along the lines of

ssh rjames@192.168.0.4


but replace rjames with your Linux username and 192.168.0.4 with your Linux box's IP address. Enter your password and we will be logged into the Linux server.

To record your keyboard settings issue the command

xmodmap -pke > keyboardsettings


This will save the keyboard layout to the file "keyboardsettings". We then want to create a little script to apply these keyboard settings. The following commands should do the trick (replacing rjames with your username):

echo "xmodmap /home/rjames/keyboardsettings" > setkeyboardsettings

chmod +x setkeyboardsettings


In your Linux window you should now be able to navigate to your home folder and double click the setkeyboardsettings file. Selecting the option to "Run" or "Run in Terminal" should now set your keyboard straight. You can open up any application and do some typing to test this.

You might still have some problems with your control and shift keys not working. In Linux you can fix this by editing the keyboardsettings file:

sudo gedit /home/rjames/keyboardsettings


As usual replace rjames with your username. Adding the following lines to the bottom of the file will enable your shift and control keys to function as they should.

clear shift
clear mod1
clear mod2
add control = Control_L Control_R
add shift = Shift_L Shift_R


If you log out then your keyboard will go back to being awkward and you will need to run the file again. If you wish to automatically run the file at login then it is quite easy to set up. Note that this will mess up the keyboard settings for this user if you log in from any other source.

In Gnome you want to navigate to your preferences and find "Sessions".



In here under startup items you want to choose "New" and enter as the command:

xmodmap /home/rjames/keyboardsettings


replacing rjames with your username. An alternative method is to just rename the keyboardsettings file to .xmodmap without doing anything in Gnome. If you do this you can also delete the setkeyboardsettings file.

mv keyboardsettings .xmodmap


I suggest logging out and in again to test that this has worked. If it has then you should have a nice easy way to access your Linux box while it is in the cupboard.

You can play about with things like the resolution in the menus in Gnome. I find this to be more effective than setting the options in NX Client. I usually set the resolution to be 800x600 in Gnome and then I can always increase the size of the Window in OS X. Once you have everything just the way you like it it's as if you were sat at the actual computer. You can even potentially open new sessions in the NX client and log back into your Linux box, or if you have the server installed, back into your Mac!

Enjoy!

4 comments:

jmax said...

This is an excellent post. I just set up an Ubuntu/NX machine, ran into the keymapping hassle, but was up and running minutes later, thanks to your post! If you're ever in Vancouver, I will certainly buy you a beer.

seneca said...

Latest 3.x version of nomachine nx + mac client finally fixes this issue with gnome and keymapping!

I was tired of going to the keyboard layout setting to use "macintosh old" for the remote sessions

Unknown said...

You may want to know about RHUB (http://www.rhubcom.com) solution to meet your remote access needs. It is a multi-platform-supportive system, and is easy, fast, and highly secure.

Unknown said...

You may want to know about RHUB http://www.rhubcom.com solution to meet your Remote Access needs. It is a multi-platform-supportive system, and is easy, fast, and highly secure.