Kickstarting a Linode Server

Michael Shepanski
January 15, 2011
Jan
15

First, I would like to thank Brett Hoerner for providing the initial details for this setup on my old Slicehost server. Without his previous post I would be a little duck in the middle of the ocean. This walk through will cover the following setup:

  • Create a New User and Disable Root Login
  • Update and Install Common Packages
  • Setup Postfix for Email Forwarding
  • Install Basic Apache2 Configuration
  • Install Basic PHP5 Libraries
  • Install Basic Python Libraries
  • Install & Setup Postgresql
  • Create a better SSH Motd

These exact steps we're used to install my server environment on Ubuntu 10.10. I happen to use Linode for my VPS hosting, but these steps could also work for Slicehost or any other VPS running Ubuntu.

Create a New User; Disable Root Login

# Connect and create new user
> ssh root@<NODEIP>
$ useradd -G users,sudo -m -p -c "<FULLNAME>" -s /bin/bash <USERNAME>
$ passwd <USER>
$ exit

# Login as user & Test sudo
> ssh <USER>@<NODEIP>
$ sudo whoami    # Test sudo; should say 'root'

# Disable root ssh; Reload ssh; Remove root password
$ sudo vim /etc/ssh/sshd_config  # Change "PermitRootLogin yes" to "PermitRootLogin no"
$ sudo /etc/init.d/ssh reload    # Reload the ssh config
$ sudo passwd -d root            # Remove root's password

Update & Install Common Packages

# Update the System Distribution
$ sudo apt-get update
$ sudo apt-get dist-upgrade -y

# Install Common Packages
$ sudo apt-get install aptitude bash-completion command-not-found
$ sudo apt-get install dnsutils file info logrotate lsof mlocate
$ sudo apt-get install mailutils telnet postfix
$ sudo apt-get install openssl rsync screen unzip autoconf build-essential
$ sudo apt-get install cdecl colordiff libtool make patch
$ sudo apt-get install memcached imagemagick
$ sudo apt-get install mercurial mercurial_keyring git subversion csstidy

Setup Postfix for Email Forwarding

Reference: Mail forwarding domains

# Re-configure Postfix
$ sudo dpkg-reconfigure postfix
# General Type: Internet Site
# System mail name: <DOMAIN> ex: pushingkarma.com
# Root receipt: USER
# Destinations: localhost
# Force synchronous updates: no
# Local networks: 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
# Use procmail for local delivery: yes
# Mailbox size limit: 0
# Local address extension character: +
# Internet protocols to use: all

# Edit the Postfix config
$ sudo vim /etc/postfix/main.cf
# Add the following:
# virtual_alias_domains = <DOMAIN1> <DOMAIN2> ...
# virtual_alias_maps = hash:/etc/postfix/virtual
# smtpd_helo_required = yes
# strict_rfc821_envelopes = yes

# Create virtual emails to forward to
$ sudo vim /etc/postfix/virtual
# Add one email alias per line
# original@domain.com forward.to@domain.com
$ sudo postmap /etc/postfix/virtual

# Update user aliases to root mail goes to <USER>@<DOMAIN>
$ sudo vim /etc/aliases
# Append the following line:
# root: USER
$ sudo newaliases

# Restart postfix for changes to take effect
$ sudo /etc/init.d/postfix restart

Install Basic Apache2 Configuration

$ sudo apt-get install apache2 apache2.2-common apache2-mpm-prefork
$ sudo apt-get install apache2-utils libexpat1 ssl-cert
$ sudo service apache2 reload    # Make sure it says [ OK ]
# Visit http://<DOMAIN>          # Make sure you get "It Works!"

# Update a few Apache configuration variables
$ sudo vim /etc/apache2/apache2.conf
# Lower "Timeout 300" to "Timeout 45"
# Lower "KeepAliveTimeout 15" to "KeepAliveTimeout 3"
# Lower "MaxClients 150" to "MaxClients 20" in mpm_prefork_module section

Install Basic PHP5 Libraries

$ sudo apt-get install php5 php5-common libapache2-mod-php5
$ sudo apt-get install php5-curl php5-mhash php5-mcrypt php5-memcache
$ sudo apt-get install php5-sqlite php5-pgsql php5-xmlrpc php5-xsl
$ sudo apt-get install php5-gd php5-imagick
# Find any other modules you want using "sudo aptitude search php5-"
$ sudo service apache2 reload

Install Basic Python Libraries

$ sudo apt-get install libapache2-mod-wsgi python-setuptools python-pip
$ sudo apt-get build-dep python-psycopg2
$ sudo pip install -U pip
# Any additional packages should be installed using pip
$ sudo pip install virtualenv virtualenvwrapper ipython
$ sudo service apache2 reload

# Any packages required by your webapp should be installed into a Virtualenv

Install & Setup Postgresql

$ sudo apt-get install postgresql

# Setup the Postgres user
$ sudo passwd -d postgres
$ sudo su postgres -c passwd    # Enter new password
$ su postgres -c psql template1
> ALTER USER postgres WITH PASSWORD '<PASSWORD>';
> \q

# Create a Postgres user matching your Linux username & password. These steps are
# for convenience. It's annoying to always access psql via the Postgres user.
$ sudo -u postgres createuser -P <YOUR_USERNAME>
# Enter password for new role: <PASSWORD>
# Shall the new role be a superuser? (y/n) y
$ createdb mjs7231 --owner=mjs7231

# When creating new Postgres users, use the following
$ createuser -P <USERNAME>
# Enter password for new role: <PASSWORD>
# Shall the new role be a superuser? (y/n) n
# Shall the new role be allowed to create databases? (y/n) n
# Shall the new role be allowed to create more new roles? (y/n) n
$ createdb <DBNAME> --owner=<USERNAME>

Install & Setup Rabbitmq / Celery

$ sudo apt-get install rabbitmq-server
# Remember your Django project needs to install celery and django-celery

Create a better SSH Motd

$ sudo rm /etc/update-motd.d/10-help-text
$ sudo vim /etc/motd.tail
# Edit this file to your liking

Comments

avioli
Nov. 16, 2011, 7:47 p.m.

What about user permissions for apache? or upload user for php?

Michael Shepanski
Nov. 23, 2011, 8:51 p.m.

@avioli - By default, when install Apache on Ubuntu through apt-get, only root has permission to execute and edit the configuration. This is a good thing. If you mean allowing permission of your user account to edit the Apache config, this is a bad idea. There is a good article on devshed.com explaining it a little better.

I personally don't use PHP much, but choose to install it on my servers for the occasional useful script that someone else wrote. If you have the steps for that, I would love to add them.