2009年6月21日 星期日

Secure your Linux Server

1. disable ssh login as root

vi /etc/ssh/sshd_config
--

..
PermitRootLogin no
..

2. disable root login in phpmyadmin

vi config.inc.php
--

..
$cfg['Servers'][$i]['AllowRoot'] = FALSE;
..

2009年6月15日 星期一

MySQL Backup and Recovery with Command-Line

the mysqldump client is a backup program which can be used to dump a database or a collection of databases for backup or transfer to another sql server. the dump typically contains sql statements to create the table, populate it, or both.

backup an entire database

mysqldump -u username -p db_name > backup.sql

-p, --password
-u, --user=username

backup a table

mysqldump db_name table > backup.sql

dump several databases with one command

mysqldump --databse db_name1 db_name2 .. > databases.sql

dump all databases

mysqldump --all-databases > all_databases.sql



you need to create the databases manually if your target mysql server has no database with same name before recovery

mysql> create database db_name;

restore

mysql -u username -p < backup.sql

2009年6月9日 星期二

Wireless USB Network Card WIFI-Link WL-USB-RSMA-27 on Arch Linux

when you plug the card into the usb slot, arch linux will modprobe rtl8187 module automatically. the driver is mac80211 based. then you can see interface wlan0 registered. it is pity it doesn't work with WIFI-Link WL-USB-RSMA-27 though aircrack-ng indicates 2.6.27 and newer kernel contain a fully-functional driver for rtl8187b and rtl8187l. so we got to compile the module by ourselves

some errors cause the newest driver rtl8187_linux_26.1025.0328.2007 cannot be compiled on arch linux and modern distributions. fortunately aircrack-ng has a patch for compiling the old driver rtl8187_linux_26.1010.0622.2006

1. unload rtl8187 module

rmmod rtl8187

wlan0 should be disappeared

2. download the old one

wget http://dl.aircrack-ng.org/drivers/rtl8187_linux_26.1010.zip

3. unzip

7z x rtl8187_linux_26.1010.zip

4. change to the extracted directory

cd rtl8187_linux_26.1010.0622.2006

5. download the patch

wget http://patches.aircrack-ng.org/rtl8187_2.6.27.patch

6. extract some components

tar xzf drv.tar.gz
tar xzf stack.tar.g

7. apply patch to source code

patch -Np1 -i rtl8187_2.6.27.patch

8. one more step to pass through compiling

vi beta-8187/r8187.h
--
change
#include <asm/semaphore.h>
to
#include <linux/semaphore.h>

9. compile and install

make && make install

i know the interface name would be wlan0 after new installed module r8187 loaded. so i write wlan0 directly in the following steps

10. if you need to load settings while booting, wlan_<interface>= in rc.conf isn't working. so i pick rc.local for use

vi /etc/rc.local
--

iwconfig wlan0 essid <ESSID> mode Ad-Hoc key 1234567890
ifconfig wlan0 up <IP> netmask <MASK>

remember to install wireless_tools package before iwconfig. and if you need sharing ppp connection with wlan interface, set mode to Ad-Hoc. although iwconfig supports Master, Repeater mode. only Ad-Hoc and Managed modes work on WL-USB-RSMA-27

11. block old rtl8187 and load new r8187 module when booting

vi /etc/rc.conf
--

..
MODULES=(r8187 !rtl8187)
..

12. reboot then done

Subversion Setup on Arch Linux

1. install subversion

pacman -Sy subversion

2. create a folder for svn service

mkdir /srv/svn

3. create the first svn repository which includes conf, locks, etc

svnadmin create /srv/svn/myproject

4. setup authentication

vi /srv/svn/myproject/conf/svnserve.conf
--

[general]
anon-access = none
auth-access = write

password-db = passwd

anon-access is access right for unauthenticated users
auth-access is access right for authenticated users
password-db is password file, the syntax is as follows

username = password


5. start svn server

svnserve -d -r /srv/svn

for more usage details, please refer,

svnserve --help

-d [--daemon] : daemon mode
-r [--root] ARG : root of directory to serve
--config-file ARG : read configuration from file ARG
--listen-port ARG : listen port
--listen-host ARG : listen hostname or IP address

2009年6月3日 星期三

WiFi / Wireless USB Network Card Edimax EW-7318UG on Arch Linux

1. identify the card

check /var/log/message when you plug your card into usb slot
you'll see

kernel: wmaster0 (rt73usb): not using net_device_ops yet
kernel: wlan0 (rt73usb): not using net_device_ops yet
kernel: Registered led device: rt73usb-phy0:radio
kernel: Registered led device: rt73usb-phy0:assoc
kernel: Registered led device: rt73usb-phy0:quality
kernel: usbcore: registered new interface driver rt73usb
kernel: usbcore: registered new interface driver rt2500usb

or lsusb command
or check your card if is linux supported
https://help.ubuntu.com/community/WifiDocs/WirelessCardsSupported

2. you can see the interface from iwconfig command

3. bring the interface up

ifconfig wlan0 up
--

SIOCSIFFLAGS: No such file or directory

that means you need a firmware file. below is the error log appearing in /var/log/message at the same time

kernel: rt73usb 1-4:1.0: firmware: requesting rt73.bin
firmware.sh[19027]: Cannot find firmware file 'rt73

4. install the corresponding firmware packages

pacman -S rt2x00-rt71w-fw ( or rt2x00-rt61-fw )

5. in order to install package from http://repo.arch-linux.pl/, add the following setting to /etc/pacman.conf

[archlinux.pl]
Server = ftp://repo.arch-linux.pl/i686

6. install the package, RaLink RT73 USB Enhanced Drivers

pacman -Sy rt73-k2wrlz
--

Drivers installed, but not loaded. To enable it: 'rmmod rt73usb && modprobe rt73

7. to avoid conflict between modules, block the modules which would be loaded automatically
these module was observed from lsmod command

vi /etc/modprobe.d/blacklist
--

blacklist rt2500usb
blacklist rt73usb
blacklist rt2x00usb
blacklist rt2x00lib

8. add rt73 to MODULES in /etc/rc.conf then reboot

9. iwconfig

rausb0 RT73 WLAN ESSID:""
Mode:Ad-Hoc Frequency=2.412 GHz Cell: XX:XX:XX:XX:XX:XX
Bit Rate=11 Mb/s
RTS thr:off Fragment thr:off
Link Quality=65/100 Signal level:-54 dBm Noise level:-143 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0

10. ifconfig rausb0 up

11. scan for available access points for testing

iwlist rausb0 scan

12. usage of iwconfig

iwconfig rausb0 essid "SSID" key 1234567890

if your wep key is ascii, prefix with s:

iwconfig rausb0 essid "SSID" key s:asciikey

13. automatical setup while booting

vi /etc/rc.conf
--

..
wlan_rausb0="rausb0 essid SSID mode Ad-Hoc key 1234567890"
rausb0="rausb0 XXX.XXX.XXX.XXX netmask XXX.XXX.XXX.XXX"
INTERFACES=(eth0 rausb0)
..