Tuesday, June 7, 2011

How should a server be setup?

After recently acquiring a $75 tower, with reasonable specs, it has come to my attention that setting up a home server should have several steps that are a must. The last box died, in most part due to the age of the 15GB HDD. But Ubuntu was able to run and for a time, there was a nice little server running on it - 1 GHz, 256MB RAM (the 512 I put in wasn't detected...). After wiping the Windoze system and doing a clean install of Ubuntu 11.04 via network, I was able to get a LAMP installation running (but not utilising MySQL or PHP as these are both foreign to me), a Samba file sharing thingo, as well as installed and shared my Canon printer :).

Now, the guy I bought the $75 box from (3 GHz, 1GB RAM, 80GB HDD) suggested to use a USB stick to store important files. And while I do agree to some extent, I really just wanted to learn how to get a server going...hehehe. There may well be some extra benefits in the long run from having a file system that is accessible over the internet, however one does need to be weary of security issues and also the possibility that things might not do what you want them do - it's a learning process. With that in mind, I think Ubuntu Linux makes a very good distribution to get a server working.

Below, is a short list which is MY recommendations (and what I have done just recently) for what you should do/install after you have put an awesome distro of Linux on your box that has been sitting in the corner doing nothing for the last 4 years. My final message is as above: security is paramount. I'm not talking about physical security, although that may be important depending on which neighborhood you live in, but rather internet security. Call me paranoid, call me what you will, but there's no point setting up a server if other people are going to be able to get at it...unless you want them to of course.

Here's my list:
1) Configure sshd_config on the server so you can access it safely (in progress)
2) Setup printer
3) Move your web files to /var/www
4) Setup Samba

Here's my list - the detailed version
1) Configure sshd_config on the server so you can access it safely (in progress)
* Change the port in which SSH will listen. 22 is the default port so if you change it, unwanted guests will take longer to find your server.
* Disable root access. Allow only specific user/s, but never an account with root access.
* Setup SSH access via a public/private key. See Ubuntu Docs for more details and how to make one. Note: if after using this method and transferring the key to the server computer, you may find that the key fails to authenticate. This may be because you may not have added the ssh-server-address-thing (?) to your system. Run this command on the client computer (the computer in which you are accessing the server from), for some reason it is not mentioned in Ubuntu Docs:
ssh-add

2) Setup printer
* Make sure CUPS is up to date and all package dependencies have been met
* For my Canon PIXMA, see older posts
* If something isn't working, try turning the printer off and then on again, seems to do the trick

3) Move your web files to /var/www
* Maybe it's bad practise, but I've been getting into the habit of using /var/www as my LAMP root directory - it's the default directory anyway and I think it's safe
* If you wish to make directories that are accessible via internet, then you have to give the folder guest access. Just use chmod and chown to do this.
* I guess this is essentially how I set up my webserver. Not very flash bang and yes, update my website is one thing I need to do...

4) Setup Samba
* Only useful if you want to access your files over different OSes
* Or, if you don't like using SSH - which I kinda like...
* See next post for details

Things worth looking into:
* Logging break-in attempts: not sure how to do this but need an easier way than reading the /var/log/auth.log manually...

Tuesday, May 24, 2011

Print Server what tha?

Just about to go to bed. But probably worth remembering how I set up my print-server.

Essentially, just followed the HowTo here.

There may be a moment when you have appeared to have done everything right and have used CUPS to install your printer, but it still won't work. It is possible that there may be some unmet dependencies that have come about when you downloaded the drivers for your printer. All you may need to do is fix these dependencies:

sudo apt-get -f install

As per the HowTo I mentioned above, it is useful to install this driver:

sudo apt-get install cupsys-driver-gutenprint

Don't forget to restart cups when your done, otherwise won't get very far.

Troubleshooting
1) Giving the printer the wrong paper size may result in your printer doing nothing, not even telling you that it doesn't like the paper size.

Ciao

Sunday, May 8, 2011

Rkward and R CLI - Useful commands

Rkward (the GUI for the statistical package - R ) is a great FOSS program offered to those who choose to fly linux :). I've started using it again because it's that time of year again, where field report data needs testing. And yet again, it's time to read up on the R-project documentation, not to mention all the Rkward documentation...

There are many additional packages that are offered with Rkward, so many that the scroll bar moves about 20 lines with a small movement with the mouse. Crazy, I know. The R-project website is a very useful place and I picked up the complete manual and it is sitting on my desktop. It is about 3500 pages long, but very useable with a littler know how and the 'Find' function.

What may be unknown about R, is that much of it (the best parts) uses code. And what is good about that? Well I'm not sure yet, though I think I have an idea. I'll try and keep this post 'Open' and edit it with useful code for the R CLI. Enjoy!

Install Packages
For some reason, I always have trouble using the GUI to install packages. Workaround, use the CLI. Running rkward as sudo may also help, but not required.

> install.packages()
A window will come up and your package/s should be listed. It will download, and install the package in one go. Don't forget to load the package if you need to use it. In the R CLI, type:

> library(package.name)

Useful packages
So here is a list of the packages which I have installed on my system. These do not come installed with an R package:

-> car
-> hexbin
-> sm
-> reshape
-> sp
-> vegan
-> googleVis
-> rgl
-> zoo
-> chron
-> ggplot2
-> ecodist

NB: googleVis is an awesome package!!

To install all of the packages listed above in one go, execute:
> install.packages(c("car","hexbin","sm","reshape","sp","vegan","googleVis","rgl","zoo","chron","ggplot2","ecodist"))

Assigning data from data.table
Rkward comes with a neat way to handle data. Once Rkward is running, you can create a new data table to enter data in cell. This may not always be the best method, but this is how you store columns from that data table to a variable, ie x. This is so you can then perform various tasks comparing 2 or more of the columns of your dataset. On the CLI:

> x <- my.data[1]
> y <- my.data[2]

Unlike a typical computer language, R begins counting from 1 and so my.data[1] will be the first column, my.data[2] will be the second and so on. You can now call the column of data simply by typing the variable into CLI.

However, this method doesn't seem to work when you call the vectors for use in a function...

Scatterplot with regression line
These can be graphed from x,y dataset either by the GUI or the CLI. CLI is like this:

> plot(y ~ x, data=my.data)

Then to plot a fit line using the lm() method:

> abline(lm(y~x, data=my.data), col="red")

It will show up on the graph automatically.

Coefficients of scatterplot regression line (from above)
Print out the coefficients of the regression line:

> variable <- lm(y~x, data=my.data)

As per above, variable can be anything you want. Something more relevant is useful, ie. fit, coefs, interp etc.


Linux distribution
It came to my attention that R may very well run better on certain Linux distributions. I'm in the process of doing a clean install and am curious at this idea. I have opted for Ubuntu Server ed amd64 after being convinced that this package while being supplemented with R dependencies, is not bundled with process hog applications. I'll see how it pans out.

Emacs
So not only have I installed a light-weight yet powerful distro, I've found some useful information about using R with Emacs. Here's some helpful links to get you started:

1) Emacs commands/shortcuts - just a few of the >1000 available
2) Post by a user on how to load an .R file


Links and places to check out
http://www.statmethods.net/index.html
http://lmdvr.r-forge.r-project.org/figures/figures.htm

http://r.789695.n4.nabble.com/Best-64-bit-Linux-distro-for-R-td881882.html - a rather recent discussion is being held here about the best Linux distro to run R on

http://cran.r-project.org/bin/linux/ubuntu/ Good guide to CLI installation of R

Monday, April 25, 2011

Instant Swap_space


Just a quick one here. Need swap? Not sure why you would if you have an awesome computer, but here's the method anyway. I've just tried this, and my computer crashed. I'm guessing that I don't really need swap, although I was intrigued at the idea that "you need swap if you want to be able to Suspend/Hibernate your computer". Anyways...

This method can be found here.

1) Create an empty file - didn't know you could to that!:
sudo dd if=/dev/zero of=/swap_file bs=1M count=1000
count=1000 can be replaced with whatever filesize you wish. It has also been noted that there is an optimum ratio for RAM/Swap space so don't make it too big as it might just do the opposite of what you want it to do. of= is essentially the location and name of the file, of=/home/person/swap_file is another example.

2) Change permissions so the file is safe from others:
sudo chown root:root /swap_file
sudo chmod 600 /swap_file

3) Tell the computer that you want this file to be swap space:
sudo mkswap /swap_file

4) Turn it on - that's what she said!:
sudo swapon /swap_file

Next is the steps to make it run on bootup. I wouldn't advise this unless you have tested the swap first, and know that it is working nicely with your system.

5) Open up /etc/fstab:
sudo gedit /etc/fstab

6) And whack this on the end:
/swap_file       none            swap    sw              0       0

So I thought that this was a nifty way to add swap space, much easier than partitioning a HDD - wouldn't be so hard if I had some free space on my HDD...I'll test out and see how my system runs. See ya!

Tuesday, April 19, 2011

Installing LibreOffice on Ubuntu 10.10


Making the change from OpenOffice and can't find another word processing (WP) program? Why not try LibreOffice!

It comes as no surprise that LibreOffice was my immediate choice when the last WP program failed to do me any good. Maybe it's my fault. Maybe I was just too ignorant in my installation and forgot something. I guess I can always go back...

What I'd like to quickly outline is how to install LibreOffice using a package downloaded from their site. This is probably the preferred way to do it as the program is not found in the repository and/or repositories suggested (not sure why). So again, this is basically just some reference material for me and anyone who needs a quick HowTo on the topic of today.

1) Download package
So, and you've probably already done this, go to http://www.libreoffice.org/download/ and download the most recent package for your computer. I'm on Ubuntu 10.10 so I downloaded the "Linux x86 (deb)".

Before I start, I'd just like to make a reference to where I got my information from http://ubuntuforums.org/showthread.php?t=1585017. I'm actually reading it as I write this...

2) Remove OpenOffice
Right. So while the ~143M file downloads, remove OpenOffice. It can be done several ways - hopefully you are familiar with those. I actually ran into a wall trying to use apt-get, so instead I just opened up the Synaptic Package Manager and removed it that way.

3) Extract file
Once download is complete. Open up the directory where it is located (Nautilus or bash) and extract it. If using bash enter this to extract files - will be different if the file you downloaded wasn't .tar.gz:

sudo tar -zxvf filename

3a) Rename the extracted folder "libreoffice"
This is not required but simply saves typing later on. Bring up bash and type:

sudo mv filename libreoffice

4) Install.
In bash, just use dpkg to install the packages. And so you don't have to continually re-enter the command for every file, use the wildcard symbol:

sudo dpkg -i ~/Desktop/libreoffice/DEBS/*.deb 

Remember to check your pathway, most likely will be different. This step may take a while, I didn't time it, I just went to sleep.

5) Install the menu icons.
Lastly, if you open up the "libreoffice" folder and then click on "DEBS", there should be another folder name "desktop-integration". There will be one .deb file in here and you simply want to install that. Again, make sure pathways are correct - I'm susceptible to pathway mutations.

sudo dpkg -i ~/Desktop/libreoffice/DEBS/desktop-integration/libreoffice3.3-debian-menus_3.3-9526_all.deb 

Now go check your "Applications" menu and if everything was done right, it should be under "Office"...YAY!

So go play, frolic in the fields of LibreOffice and don't be afraid to venture further, or even Tweet comments, I'm sure they'd like to hear em.

Before I go, I want to emphasis again where I got my information from, thankyou scouser73 on Ubuntuforums.org, thread here. I'd also just like to give some experience on LibreOffice already.

I haven't actually typed anything up yet, but the Zotero extension comes pre-installed (unless it was fetch from my Download folder while I was installing it...). I've tried adding references and there has been no hiccups as yet. Problems I was having with OpenOffice-Write was some weird thing where, if my computer went into stand-by, when I came back and logged in, if I tried to type something into my document (which I usually leave open), then it would crash. Very annoying. I will be testing that today and hopefully it doesn't crash in the lecture hall! Enjoy and post me your experience.

Saturday, April 2, 2011

Wgetting


Lately, I haven't exactly been spending enough time on my AMD laptop, traversing the Brisbane landscape with my trusty Samsung Netbook - what a joy! Not knowing where a power-point is, isn't a major issue now. But unfortunately, I end up spending much of my time on my netbook even when I get home. And the downside is that I just don't have the same processing power to do some real computer stuff - sshing, reading Ubuntu Documents (on a 15" screen is the only way), and listening to the radio!

In this quick blog, I'm just going to demonstrate how to Wget some stuff such that you don't download the same thing twice. Wget is a useful tool which can be used to download files from the web without the use of a browser. If you want to get an idea of it's power, just watch 'Social Network'. Basically it can be used to download whole websites and the number of different files that a website will contain. For example, you can download the files that makeup the Google website - the logo, the html, any animations, any javascript files etc (though I probably wouldn't try download all of Google...).

Wget is a simple program to use and should come with your Ubuntu distribution, if not, just get it from the Ubuntu Software Centre.

Open terminal (I'm assuming you're using a linux distro) and go to the folder where you want to save the downloaded files. Then invoke Wget. Invoking is simple - program url:

Wget http://www.aurl.com

This is without the use of any options. To see the options available, just type:

Wget --help

Now, I won't be going through them all, but I'm just going to detail those that are useful to me.

If my friend has a folder on his server that contains a number of files which I will need for a university assignment, and I want to download that folder to my computer, then I will need to do a recursive download. But I don't want to download anything else on his server, just everything below the folder of choice. So I will need to do a recursive download with 'no parent' - Wget jargon. Do it like this:

Wget -r -np http://www.myfriendsurl.com

All files will be downloaded to the directory that the terminal is currently in and Wget will neatly put them in a folder called 'www.myfriendsurl.com'.

Having fun yet? But you're annoyed that the pathway that it is being saved to, is too long to type aren't you? Well there is a solution! --cut-dirs. That's right!

So, I'm guessing your friend is a space-freak and keeps their server nice and tidy by using some sort of naming hierarchy which doesn't use a date or data genre structure! And now you're download from a site which is longer than 60 characters and looks like http://www.thesaferhaven.com/home/themonolounge/hinduphilosophy/yoyo-sponge-cake. What a nightmare! Well, what you do, is use --cut-dir to rid the extra directory listings that you will never need. Using:

Wget -r -np --cut-dirs=4 http://www.thesaferhaven.com/home/themonolounge/hinduphilosophy/yoyo-sponge-cake

--cut-dirs=4 will cut 4 of the folders off the download saving you clicking time and your sanity.

Now, when you go to the directory where you downloaded all these files, instead of having to click www.thesaferhaven.com > home > themonolounge > hinduphilosophy > yoyo-sponge-cake, you can just click www.thesaferhaven.com, and you will be at the files which you are interested in.

The last option I'd like to tell you about is the 'no clobber' option. All it does is tell Wget that you already have one of the files (which it is trying to download) on your computer, and it will stop Wget from downloading it. Use it like this:

wget -r -np -nc http://www.myfriendsurl.com

Of course, you must be in the same directory otherwise Wget won't see the files!

Too easy! In all honesty, Wget is more useful to those who build websites and want to download whole directories in their entirety. Wget is commonly used to download websites and mirror them from a home server. Something I need to learn more about...

Hope you enjoy this instalment of my Linux knowledge and write back to me on what I should learn next!

Tuesday, March 8, 2011

Remote rhythmbox playing...teeheehee


This is awesome. I already have a very good use for this method as you will soon see...waking up my house mates by ssh-ing to my home computer and turning on Rhythmbox, and turning it on loud!

So I really just wanted to be able to play music from the terminal. Mainly, so I can do this on a remote computer via ssh. I thought it was a crazy idea and not possible, but how wrong I was. I soon realised also, that Rhythmbox probably isn't the most process efficient program to run, but hey, it was straight forward, and did what I wanted it to do so I'll stick with it for now.

This is a guide to running a program on a remote machine over ssh.

Firstly, you'll need to ssh to the desired computer. Many docs on how to do this. I used a variant of the following command with no -X option.

ssh me@192.168.1.1

Enter the password for 'me' on the host. Then, type the command below, I lost the link to where I found it sorry.

export DISPLAY=:0.0

When you press enter, nothing will happen. However, you have just given ssh somewhere to direct programs that require a GUI. This command is also used if you want to direct the program to display on the local computer, but instead of using 0.0, another option is used. This is a little more complicated though and some files need to be edited.

Ok, so to test that you can get a program to start-up, try xeyes.

xeyes

Much easier to know if it works if the computer you are ssh-ing to is right beside you. So now that it works, we want to get rhythmbox working. The command is:

rhythmbox-client

This opens rhythmbox and then allows users to send commands to the client via terminal. To find a list of options, run:

rhythmbox-client --help

Lastly, point your terminal to the folder where all your songs are located, and queue them like so:

rhythmbox-client --enqueue FOLDER-NAME

Vuola! Use the --play and --next options to get to the songs you want to play. Of course they have to be in the playlist to play.

I will probably find an easier method for playing songs soon, but hey, this works for now. The only problem I've run into thus far, is if you add a folder, it adds all the files that are in that folder, documents, images etc. Possible solution, run an ls with a grep option to select only song files. It should work, will try it soon.

Thanks and have fun waking up your neighbours!