04 02 2008

My Slicehost server setup

I set up a new slice today using the following steps, most of which have I got from these three articles.

I use Ubuntu Gutsy on my servers. This setup gets me to the stage where I can deploy rails apps (which will be the topic of another post). Note that user specific values are preceded by the dollar sign, so for example I would replace $USERNAME with ciaran.

  • Log in as root
  • Add universe and multiverse repos to the ubuntu archives in /etc/apt/sources.list
  • Update packages
    apt-get update
    apt-get upgrade
  • Change root password (I use pwgen to create passwords) by running ‘passwd’ as root
  • Change default text editor to vim by running
    update-alternatives --set editor /usr/bin/vim.basic
  • Add a standard user:
    adduser $USERNAME
  • Allow standard user to use sudo to run commands as root by adding the following line to the end of the text file that is opened when ‘visudo’ is run as root:
    $USERNAME  ALL=(ALL) ALL
  • Switch to the non-root user
  • Copy public key from my workstation to the server:
    scp ~/.ssh/id_dsa.pub $USERNAME@$SERVER_IP:
  • Then on the server add it to the /home/$USERNAME/.ssh/authorized_keys file:
    cat id_dsa.pub >>.ssh/authorized_keys
  • Log in to the server as the non-root user, there should be no password authentication now that the public key has been authorized
  • Disable root login over ssh, and disallow password logins, among other things, by making sure the following lines exists in /etc/ssh/sshd_config:
    PermitRootLogin no
    PasswordAuthentication no
    X11Forwarding no
    UsePAM no
    UseDNS no
    AllowUsers $USERNAME
  • Restart the ssh server:
    sudo /etc/init.d/ssh restart
  • Install rails + dependencies. I wouldn’t actually use the ubuntu rails package, but if you install it it pulls in some dependencies which are useful.
    sudo apt-get install rails libopenssl-ruby \
      libopenssl-ruby1.8 ri1.8 ruby1.8-dev \
      build-essential zip unzip
  • Install mysql + extras (set the root mysql password while you are at it!)
    sudo apt-get install mysql-server mysql-client \
      libmysqlclient15-dev libmysql-ruby
  • If you don’t want to use InnoDB then edit /etc/mysql/my.cnf, and uncomment the following line:
    #skip-innodb
  • Restart mysql
    sudo /etc/init.d/mysql restart
  • Download and install rubygems, then symlink gem1.8 to gem:
    sudo ln -s /usr/bin/gem1.8 /usr/bin/gem
  • Symlink irb1.8 to irb:
    sudo ln -s /usr/bin/irb1.8 /usr/bin/irb
  • Install git
    sudo apt-get install git-svn
  • Install ssmtp then edit the config file as follows:
    root=$GMAIL_USERNAME@gmail.com
    mailhub=smtp.gmail.com:587
    AuthUser=$GMAIL_USERNAME@gmail.com
    AuthPass=$GMAIL_PASSWORD
    rewriteDomain=gmail.com
    UseSTARTTLS=YES
    hostname=$HOSTNAME
    FromLineOverride=YES
Back to Articles