LongSpine.com Yes, we are lazy.

24Sep/090

Install Lighttpd and Subversion on Debian Lenny

Introduction

This article is a step-by-step guide for installing Lighttpd (pronounced lighty) and Subversion on Debian Lenny. My previous setup was Subversion with Apache, however Apache was too heavy for my virtual private server so I had to move to Lighttpd. Most resources from the previous article are used in this article as well.

Sadly, however, there is no mod_svn for Lighttpd, and it will not be implemented in the near future. This is one of the good reasons why not.

The most common solution is to use mod_proxy and forward the command to Apache with the module dav_svn, but it doesn't make sense to run Apache in parallel with Lighttpd if we tried to avoid using Apache since the beginning.

My solution was to use svnserve, which is the default server for svn and has a relatively better performance than WebDAV on Apache. The operations of lighttpd and svnserve are totally decoupled, which means we do not need to configure Lighttpd for svnserve and vice versa.

If you prefer using Apache than svnserve, as many people did, use this very simple guide.

Otherwise, please follow the following steps:

Install and Configure Lighttpd

Install the package from aptitude:

sudo aptitude install lighttpd

Edit the config file:

sudo vi /etc/lighttpd/lighttpd.conf

Change the default document root by editing server.document-root:

server.document-root = "/var/www/example1.com/"

Where example1.com is the directory where you default website is located.

If you need to create a virtual host, add the following virtual host at the end of the file (otherwise skip this step):

$HTTP["host"] == "(^|\.)example2\.com" {
  server.document-root = "/var/www/example2.com/"
}

Don't forget to change example2.com to your own directory.

Noted that Lighttpd has a module called simple-vhost, however, it's not the robust choice and I don't recommend it.

Now save the file and reload Lightty by:

sudo /etc/init.d/lighttpd force-reload

Try accessing the website by using your browsers. The default location is at /var/www/example1.com/, but if you enter your website with the name example2.com you'll be redirected to your virtual host at /var/www/example2.com/ instead (this requires a DNS).

Install and Configure Subversion

Install subversion from aptitude:

sudo aptitude install subversion

A new subversion user group should be created. this can be done by creating a new user called svn and and the existing users to this group, as follows:

sudo useradd svn
sudo usermod -a -G svn user1

Where user1 is an existing user that is added to the group svn.

Set a new password for the user svn:

sudo passwd svn

Create a new directory for repositories, and create a new repository for testing:

sudo mkdir /var/svn
sudo svnadmin create /var/svn/test
sudo chown -R svn:svn /var/svn

This will create a new directory called /var/svn which contains a new testing repository test.

Don't forget to change the permission for all users in the group svn for the test project:

sudo chmod -R g+w /var/svn/test

Test the setting by usinf the file protocol:

svn co file:///var/svn/test /tmp/test

This will check out our test project to /tmp/test. You should get an output like "Checked out revision 0".

Using svnserve

Now, assuming that you need some level of security for your code which will be transmitted through the Internet or LAN, we need to enable ssh tunneling for svnserve. The good news is that you can use the protocol svn+ssh, by default. This will make a ssh connection to you server, run svnserver, and stop svnserver after the command is executed. This is an example:

(on the client side)

svn list svn+ssh://example.com/var/svn/test

This command will list the subversion project at the location /var/svn/test of the server example.com. If you want to specify the username, just add the username and @ before the hostname as in this example:

svn list svn+ssh://user1@example.com/var/svn/test

Don't forget to change user1, example.com, and /var/svn/test to your own setting.

If SSH key authentication was not set, you will be asked for your password twice. If you feel annoyed by this strange design, set the public key authentication up. If you don't know how to do it, I found this a simple and quick guide for beginners.

Other port than 22?

If, for a security reason, your ssh server doesn't run on port 22, you need to edit /etc/subvesion/config in the client side (assuming you client also uses Debian Lenny):

sudo vi /etc/subversion/config

Now in the [tunnel] section add the following line:

ssh2222 = $SVN_SSH_2222 ssh -p 2222 -o ControlMaster=no

This will use ssh tunneling on port 2222 instead of the default port 22. You can change the port to you own setting and also change ssh2222 and SVN_SSH_2222 to the name you prefer. ControlMaster option must be turned off, according to the default configuration file.

On the client side you can list the repository by using the command:

svn list svn+ssh2222://user1@example.com/var/svn/test

Good luck.

14Sep/090

Opera 10 with Qt4 on Debian Lenny

Opera uses Qt3 interface by default. I didn't find it disturbing, just until when I installed Opera 10 on my workstation today. It seems like there's some kind of bugs or problems with the configuration file, which makes the interface looks really ugly and runs incredibly slow.

My solution was to install the Qt4 version of Opera, and here is a simple step-by-step guide:

Download Opera

Look for the newest version of Opera on it's FTP archive. If you have no clues which version you should download, you probably need this version.

Install Opera

First you need to remove the previous version of opera, if you have one.

sudo aptitude remove opera

Now go to the directory where you downloaded your opera and install it using dpkg.

sudo dpkg -i opera_10.00.4585.gcc4.qt4_i386.deb

Change opera_10.00.4585.gcc4.qt4_i386.deb to the name of the file you downloaded.

If it asks for the replacement of the configuration, simply say no since you don't want to set everything up again. But if it doesn't work try to reinstall it and now have the configuration file replaced as well.

That's all. This could be the easiest how-to I've ever written in my life though.

Category: How-to
Tagged as: , , , ,
No Comments
2Sep/094

Install Apache/Subversion on Debian Lenny and Migrate the Repositories

Install Subversion/Apache

sudo aptitude install subversion apache2 libapache2-svn

Subversion Configuration

Create subversion repositories:

sudo mkdir /var/svn
sudo chown -R www-data:www-data /var/svn

All our subversion repositories should be located in /var/svn in order to be visible to Apache (you can change /var/svn to something else).

SSL (Secure Sockets Layer)

The following steps are required if you need SSL, otherwise skip this chapter.

sudo aptitude install openssl ssl-cert
a2enmod ssl

"Listen 443" should already exist in /etc/apache2/ports.conf, otherwise add it manually:

sudo vi /etc/apache2/ports.conf

Create a new SSL config file (replace ssl.new.site with your preferred name):

sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/ssl.new.site

Edit the file:

sudo vi /etc/apache2/sites-available/ssl.new.site

Replace:

<VirtualHost *:80>

with

<VirtualHost *:443>

Before </VirtualHost>, add:

SSLEngine on
SSLCertificateFile /etc/apache2/ssl/ssl.new.site.pem

You can try using the template from "default-ssl" instead of "default", which is easier and more reliable since many SSL-related configurations are already handled. However, I haven't tried this method and I'm not sure if it works without modifications.

Create SSL certificate file:

sudo mkdir /etc/apache2/ssl
sudo make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/ssl.new.site.pem

Enable the new site:

sudo a2ensite ssl.new.site
sudo /etc/init.d/apache2 reload

To see if the setup works, use your web browser to visit:

https://server.ip/

Replace server.ip with the ip of your server. There should be a pop-up or an alert about the new certificate.

DAV_SVN Configuration

Edit /etc/apache2/mods-available/dav_svn.conf and follow the guidline:

sudo vi /etc/apache2/mods-available/dav_svn.conf

Normally it looks like this:

<Location /svn>
DAV svn
SVNParentPath /var/svn

AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd

Require valid-user
SSLRequireSSL      # this line must be added if you want SSL enabled

</Location>

Enable the mod and restart:

sudo a2enmod dav_svn
sudo /etc/init.d/apache2 restart

Create a user account for dav_svn:

sudo htpasswd -c /etc/apache2/dav_svn.passwd user1

To add more users, use:

sudo htpasswd /etc/apache2/dav_svn.passwd user2

Subversion Testing

sudo svnadmin create /var/svn/test
sudo chown -R www-data:www-data /var/svn/test

svn co https://new.site/svn/test

It should says "Checked out revision 0.", otherwise try looking for the errors on the Internet. You probably forgot some steps or I forgot to mention some details.

Migration

Skip this chapter if you don't need to migrate you data from your old server.

On the old server, we need to dump all updates into a single file. Each repository must be done separately.

mkdir svndump
cd svndump

sudo svnadmin dump /var/svn/repository > ./repository.dump

cd ..
tar zcvf svndump.tgz svndump
scp svndump.tgz username@new.server.ip:./

Those dump files must be applied on the new system's repositories.

tar zxvf svndump.tgz
cd /var/svn/repository

sudo svnadmin create repository-name
sudo svnadmin load repository-name < ~/svndump/repository.dump

sudo chown -R www-data:www-data /var/svn/*

Congratulations, all your source code has been migrated!

2Sep/090

Securing SSH in Debian Lenny

เรื่องนี้เริ่มมาจากเมือสิบนาทีที่ผ่านมาได้เข้าไปดูเซิร์ฟเวอร์ที่ใช้อยู่ ปรากฎว่ามีการใช้แบนวิดท์ที่สูงมากโดยที่ผมไม่ได้ใช้งาน จึงเกิดเอะใจขึ้นมาว่ามีใรมาเล่นอะไรแผลงๆรึเปล่าเลยเข้าไปดูที่ /var/log/auth.log ก็พบว่ามีบางคนทำ brute force attack กับเครื่องผม ผมจึงต้องทำอะไรซักอย่างเพื่อป้องกันการถูกเจาะเข้าระบบ

การใช้ ssh นั้นเป็นช่องทางที่สะดวกและแพร่หลาย แต่ในขณะเดียวกันก็เหมือนกับเป็นช่องทางมาตรฐานสำหรับผู้ไม่ประสงค์ดีเข้ามารบกวน เราสามารถป้องกันในเบื้องต้นได้ง่ายๆคือ

  1. ใช้รหัสผ่านที่ดี แต่รหัสผ่านที่ดีนั้นคืออะไร? จากประสพการณ์รหัสผ่านที่ดีมักจะมีลักษณะดังนี้
    • มีจำนวนอักษรหลายตัว
    • ใช้เลข พยัญชนะ และเครื่องหมายผสมกัน
    • ไม่ใช่คำที่พบได้ตามพจนานุกรม หรือคำที่พบเห็นได้ทั่วไป
    • เจ้าของต้องจำได้ (สำคัญมาก!)
  2. แก้ไข /etc/ssh/sshd_config
    Protocol 2          # โปรโตคอล 2 ปลอดภัยกว่าโปรโตคอล 1
    PermitRootLogin no  # ห้ามล็อกอินโดย root
    AllowUsers username # ให้ล็อกอินได้เฉพาะ username ที่ระบุ
    หลังจากนั้นอย่าลืมสั่ง
    sudo /etc/init.d/ssh restart
    นอกจากนี้ยังสามารถทำให้ปลอดภัยขึ้นได้โดยการเปลี่ยนพอร์ท และการบังคับให้ผู้ใช้ใช้กุญแจแทนที่รหัสผ่าน แต่เนื่องจากมันทำให้ใช้งานได้ไม่สะดวก วิธีพวกนี้จึงไม่ใช่วิธีที่ผมจะใช้สำหรับเซิร์ฟเวอร์สันหลังยาว
  3. ทำการ Blacklist ผู้ที่อาจจะมีประสงค์ร้าย วิธีการนั้นมีหลายแบบ เช่นการแก้ไข iptables แต่สำหรับผู้ใช้ที่ไม่อยากไปทำอะไรซับซ้อนและเสี่ยงต่อการผิดพลาด ดังนั้นเราจึงแนะนำโปรแกรม DenyHosts ที่มีหลักการคือเมื่อมีการค้นพบว่ามีหมายเลขไอพีไหนพยายามโจมตีเครื่องของเรา โปรแกรมนี้ก็จำทำการแบนไอพีนั้นเป็นช่วงเวลาหนึ่ง ซึ่งนานพอที่จะทำให้การโจมนี้นั้นไร้ประโยชน์ไปเลย การติดตั้งใน Lenny นั้นทำได้ง่ายๆโดย
    sudo aptitude install denyhosts

วิธีการเหล่านี้อาจแปลกใหม่สำหรับผู้ใช้หลายๆคน แต่สำหรับผู้ไม่ประสงค์ดีนั้นมันแสนจะธรรมดายิ่งกว่าปลอกกล้วย การเรียนรู้เรื่องเหล่านี้จึงสำคัญหลีกเลี่ยงไม่ได้ โดยเฉพาะผู้ที่ต้องดูแลเซิร์ฟเวอร์ของตัวเองแบบถูๆไถๆ เช่นตัวผมเอง

Category: How-to
Tagged as: , , , , ,
No Comments
   

Recommended Reading

Recent Comments

Archives

Meta