Debian Lenny setup - page 2

Now that we've secured access to our Debian Lenny slice we can update it and get it ready for the rest of the server install.

In part 1 of the Debian 5.0 (Lenny) setup, we completed the ssh configuration along with a basic iptables setup.

Now let's run some checks and install some personal configuration files to make life easier. Once done, we can update the install and create a solid base for the 'meat' of the server.

OS check

First thing is to confirm what OS we're using. We know we should be using Debian Lenny but let's see:

cat /etc/debian_version

You should get an output similar to this:


Good enough.

Using free

Memory usage should be very low at this point but let's check using 'free -m' (the -m suffix displays the result in MB's which I find easier to read):

free -m

It's nice to know what is going on so let's look at that output:

.                  total       used       free     shared    buffers     cached
Mem:           254        55          199          0           2               21
-/+ buffers/cache:      30          223
Swap:            511        0           511

The line to take notice of is the second one as the first line includes cached memory - in this demo slice I have 254MB memory in total with 30MB actually used, 223MB free and no swap used. Nice.


Normally the "ls" command doesn't list files that start with a period. Those are usually configuration files or directories, and ls hides them so they don't clutter up your directory view. To see all of what's there, run:

ls -a ~

The "-a" option is what tells ls to list all files, not just the non-configuration files.

You'll see several files, but let's focus on ".bashrc" right now. This is ultimately where your user environment (the "shell") will look for its settings. Go ahead and open it for editing:

nano ~/.bashrc

Inside you'll see a lot of shell script commands — don't worry if you don't understand it all. Anything we add at the end of the file will override what came before. If you want to, say, change your prompt, you don't necessarily need to figure out what all the "if" statements in there by default are for, and which line you need to edit. You can just add your own setting at the end.

Custom prompt

With that in mind, let's look at how to change your prompt. At its simplest, the prompt's format is set with the "PS1" environment variable. It consists of some numbers that determine color and some codes that act as stand-ins for variables like the current working directory and your hostname. To set your prompt to just your hostname and working directory, both in different colors, you could add this line to the end of the .bashrc file:

PS1='\[\033[0;35m\]\h\[\033[0;33m\] \w\[\033[00m\]: '

The chunks like "0;35m" and "0;33m" are what control the colors - those are pink and brown, for example. Other colors you can substitute include "0;32m" for green and "0;36m" for blue — it's just a matter of changing those numbers.

Other important parts of that jumbled collection of characters are "\h" and "\w", which represent the hostname and working directory, respectively. If you wanted to include your username in the prompt you could add the "\u" code along with an "@" symbol, and it would look like this:

PS1='\[\033[0;35m\]\u@\h\[\033[0;33m\] \w\[\033[00m\]: '

Before we see what that will look like, however, let's also look at another useful feature of your shell, aliases.


The "alias" keyword lets you set a shortcut for another command. Some examples to get you started, which can be added to the end of your .bashrc file:

alias free="free -m"
alias update="sudo aptitude update"
alias install="sudo aptitude install"
alias upgrade="sudo aptitude safe-upgrade"
alias remove="sudo aptitude remove"

They're pretty simple examples, and are just meant to save you a little typing. Notice that you can essentially replace a command with an alias, like we did by setting the alias "free" to be a shortcut for "free -m". With that alias set, when you type "free" on the command line, behind the scenes the shell actually runs "free -m", so you don't have to type the extra characters to get the memory usage numbers in megabytes.

Similarly, those other aliases are shorthand for some aptitude commands to update or install packages. Since "sudo" is run behind the scenes you'll still have to type your password, but at least before that you won't have to type as much to run an update or install a package.

To activate the changes you've made to the .bashrc file, either log out and log back in or enter this command:

source ~/.bashrc

If you set a value for "PS1" above, you'll see your prompt change. Feel free to go back and change the colors or format of the prompt, or add your own aliases.

Set locale

You can check the current locale setting for your slice by running:


If the code doesn't match what it should be for the localization you would like to use for your slice (or if it uses a generic locale like 'POSIX'), run something like the following commands:

sudo aptitude update
sudo aptitude install locales
sudo dpkg-reconfigure locales

Running that last command will bring up a menu listing a bunch of locales. Scroll down to the one (or ones) you'd like to support on your VPS, like 'en_US.UTF-8' for US English, or 'cy_GB.UTF-8' for Great Britain Welsh. A complete list of language and region codes can be found here.

To select a locale to install from this menu, hit "space" while the selection is highlighted. When you've enabled all the locales you want, hit 'tab' to get to the 'OK' button, then hit enter.

The next screen will ask which locale you want to use as the default. Highlight that locale, then hit enter, and you're set.

If you change the default locale for your slice you will need to log out and log back in to see the change when running 'locale' by itself again.

Package repositories

A Debian server comes with a basic set of repositories.

Have a look at the enabled repositories by running:

sudo nano /etc/apt/sources.list

You should see something very much like:

deb lenny main contrib non-free
deb-src lenny main contrib non-free

deb lenny/updates main contrib
deb-src lenny/updates main contrib

deb lenny/volatile main contrib non-free
deb-src lenny/volatile main contrib non-free

Each line specifies either a binary package repository ('deb') or a source package repository ('deb-src').

You can, of course, add more repositories whenever you want to but I would just give a word of caution: Some of the available repositories are not officially supported and may not receive any security updates should a flaw be discovered.

Keep in mind it is a server we are building and security and stability are paramount.


Now we can update the package list that aptitude uses.

sudo aptitude update

NOTE: If you have used the .bashrc aliases shown above you just need to enter 'update' as the alias will use the entire command. I've put the whole thing here so you know what is happening.

Now we have set the locale and updated the sources.list repositories, let's see if there are any upgraded packages available:

sudo aptitude safe-upgrade

As with all installs have a careful look at the list and, once happy, press 'y' to continue.

That's really the basics done for the Slice.

Once any updates have been installed, we can move on to installing some essential packages.

Development Tools

Debian has some handy meta-packages that include sets of pre-defined programs required for a single purpose.

So instead of installing a dozen different package names, you can install just one meta-package. One such package is called 'build-essential'. Issue the command:

sudo aptitude install build-essential

Notice the programs that are to be installed include gcc, make, patch and so on. All these are needed for many other programs to install properly. A neat system indeed.

Enter 'y' and install them.

Now we have the necessary packages should we want to build an application from source.


The console is now informative and less drab, locales have been configured and basic compile tools have been installed. Quite a lot happening here but now we have a more secured Slice with updated packages ready for the meat of the server to be put in place.

  • -- Ben B. (updated by Jered)

Article Comments:

Phil G. commented Thu Apr 02 19:53:24 UTC 2009:

cat /etc/lsb-release didn't seem to work. I was able to cat /etc/debian_version to get the version of the OS.

Also the verbiage at the at the top of this page says "We know we should be using Ubuntu Intrepid but let's see". Just a heads up. :)


Ben commented Fri Apr 03 01:34:28 UTC 2009:

Phil, thanks for pointing that out. I have updated the article with those changes.

Jeff Schwab commented Sun Apr 05 00:22:49 UTC 2009:

This was excellent. Thank you.

michael commented Thu Apr 23 15:51:51 UTC 2009:

I would highly recommend everyone setting up a new server to install etckeeper. Just type

sudo aptitude install etckeeper

cd /etc

etckeeper init -m "initial commit"


Jeff commented Tue Apr 28 04:23:35 UTC 2009:

Under the heading "Disk Usage", you've put the command line prompt in the code box as well. If users enter the line as is shown, it of course will not work!

It should only be:

df -h

Ben B commented Wed Apr 29 00:40:34 UTC 2009:

Thanks Jeff, I have fixed that up.

moped commented Sun May 17 14:54:53 UTC 2009:

following along, i'm seeing a lot of errors around locales:

manconv: can't set the locale; make sure $LC_* and $LANG are correct

and "setting locale failed".

i've followed along flawlessly, so has the lenny image recently changed, and not been reflected here?

moped commented Sun May 17 16:16:25 UTC 2009:

regarding the above problem, i'm not alone, as it seems to be a bug in debian

this fixed it for me by using locales-gen (solution 1), though maybe it'd be best for ppl following along to try solution 2 first?:

Ben commented Thu Jun 04 18:23:51 UTC 2009:

Thanks for that moped. That wasn't an issue when the article was written but I will take a deeper look and update the article if needed.

Chris commented Fri Jun 19 09:46:33 UTC 2009:

sudo dpkg-reconfigure tzdata also a good idea to set your timezone

Ben B commented Sat Jun 20 05:00:50 UTC 2009:

@moped - I ran through this article again from scratch and was unable to reproduce those errors you were seeing. Did you do an aptitude upgrade before generating the locales perhaps? That is the only way I can think of that a bug that doesn't exist in our image made its way onto your slice.

@Chris - Nice suggestion. So nice that I added it to the article. Thanks!

john commented Sat Jul 25 20:51:16 UTC 2009:

Hi, I have the same problem as Moped. Most likely caused by doing an 'aptitude upgrade' before generating the locales. How would I fix this?

many thanks, John

bravo commented Wed Oct 21 16:40:40 UTC 2009:

just a quick note to let you know how handy the two 'lenny' setup articles were...saved me a bunch of time! Many thanks.

Rich commented Tue Nov 03 05:38:13 UTC 2009:

When I ran sudo aptitude safe-upgrade, I got this dialog:

Configuration file /etc/udev/rules.d/75-persistent-net-generator.rules ==> Deleted (by you or by a script) since installation. ==> Package distributor has shipped an updated version. What would you like to do about it ? [...] (Y/I/N/O/D/Z) [default=N] ?

Which is the best answer?

Douglas commented Tue Dec 01 21:54:40 UTC 2009:

Hey. A tip for those who have their slice in DFW, you can have in you /etc/apt/sources.list to speed up things a bit.

Max commented Tue Dec 08 19:44:16 UTC 2009:

Rich: take a look at . From what I gather, this file is related to device setup and it is not present currently (according to the notes on the page, it can conflict with other files) - the best action would be the default, N.

luis commented Sat Jul 03 16:46:35 UTC 2010:

gracias men me servira de muxo =)

Mike commented Sun Jul 25 18:57:43 UTC 2010:

* update-locale: Error: invalid locale settings: LANG=en_US.UTF-8 when running the locale commands.

It looks like these changed in this article, I used to use this article all the time and the locale generation stuff worked fine. The article appears to have been modified though and no longer works as expected.

Jered commented Mon Jul 26 18:14:28 UTC 2010:

The mistake was entirely my fault, Mike. I updated the article to try and make it consistent with the other slice setup articles, and got the locale stuff wrong for Debian. I've reverted the commands to what Ben had originally written since he had it right. Sorry about that.

Want to comment?

(not made public)


(use plain text or Markdown syntax)