Thursday, July 24, 2008

讓FreeRadius Server整合Linux上的帳號做認證

很久以前有介紹透過FreeRadius Server裡的users來做使用者認證,在此update一下透過Linux本機帳號來做認證。

Step1. 將啟動radius server的使用者改為root
# vi /etc/raddb/radiusd.conf


如果不這麼做的話,當啟動radius server時,由於radiusd user對於/etc/shadow沒有讀取的權限,故會發生permission denied。網路上有找到PAM Support for FreeRadius (http://www.sfr-fresh.com/unix/misc/freeradius-1.0.5.tar.gz:a/freeradius-1.0.5/doc/rlm_pam)的文章,可是照著做還是不能work,所以先以此方法來實現。

Step2. Enable Unix account authentication
# vi /etc/raddb/radiusd.conf
unix {
cache=yes
passwd= /etc/passwd
group=/etc/group
shadow=/etc/shadow
radwtmp=${logdir}/radwtmp
}




Step3. 以debug mode啟動
先以debug mode啟動radius server看看是否能啟動成功:

………………. Message

如果看到Ready to process requests的話就代表成功了。
Note: 目前只允許localhost (127.0.0.1)可以連線,如果要允許別的網段或IP連線到本機認證的話請修改 /etc/raddb/clients.conf

Step4. 以本機使用者認證:
Usage: radtest

如果看到回應Access-Accept ……… 那麼就是代表認證成功。

Step6.以daemon方式啟動radius server,並測試:


成功的以daemon的方法啟動radius server,並且能正常工作。

Wednesday, July 23, 2008

Tcl + expect 簡單實作

這陣子在幫公司做些自動化測試的環境,故常利用到tcl搭配expect故在此做個雜記:
舉個簡單的例子,透過tcl與expect ssh login到遠端機器並將它reboot:

整個tcl的內容如下:
#!/usr/bin/tclsh
package require Expect
set ip [lindex $argv 0]
spawn ssh -o StrictHostKeyChecking=no Administrator@$ip
expect "Password: "
send "aaaa\r"
expect ">"
send "reboot\r"
expect "(y/n)"
send "y\r"
expect "# "

以expect期待得到怎樣的輸出後,便使用send輸入命令,而每台機器所吐出來的prompt都不相同,請自行更改。

執行: ./reboot.tcl 192.168.0.1

Saturday, July 19, 2008

赤壁

今天跟老婆請了特休幫小女開戶,之後到中和的環球國賓影城去看赤壁,說起來不難看但是也沒說多好看到那邊去,也許是因為我看過大陸電視版的三國演義,每個段落總是會比較一下,電影場面雖大,但是人物的刻化似乎就沒有那麼傳神了,特別是諸葛亮說服東吳參戰的過程實在不夠精彩,電視版的諸葛亮(唐國強先生飾演)舌戰群臣的一慕實在是令人非常之佩服,相比之下,電影就有點遜色了,想起電視版星落五丈原的那幕:亮不能臨陣討賊,憂憂蒼天,何薄於我。總是會忍不住內心的激動而落下眼淚,唐國強先生的確是把諸葛亮演得非常之成功!

話題扯遠了,回歸正題,我覺得赤壁還算是這幾年來華語片中挺好看的片子,雖然有幾段劇情與史實不太符合但也不至於被改得太誇張,精彩的戰鬥場面替整部片加分了不少,我不是影評人,但是如果要我給分數的話那麼我會給它79分,主要是因為我覺得很多橋段是多餘的,如果能多加強以下幾點那麼整部片將更加完美了:
- 長板坡上的英雄,趙子龍的冷靜與霸氣,浴血救少主,七進七出呀!
- 張飛喝退曹軍百萬雄兵,大喝一聲使曹將摔馬
- 諸葛亮舌戰群臣,製造與論,說服東吳參戰,讓劉軍從中得利

BTW, 老婆不懂三國歷史,一直問我接下來會如何,所以剛剛在網路上買了電視版三國演義全集幫她惡補一下。

Wednesday, July 16, 2008

Kernel Vulnerability in Ubuntu 8.04, 7.10, 7.04 and 6.06 LTS. Upgrade Now!

得到消息Ubuntu Linux Kernel有安全性的漏洞,將導致DOS攻擊。詳情請參考以下連結:

Kernel Vulnerability in Ubuntu 8.04, 7.10, 7.04 and 6.06 LTS. Upgrade Now!



看來我又要recompile一些套件了。

Friday, July 04, 2008

To disable the remote host key checking

最近用Tcl配合Expect SSH至遠端DUT自動測試並產生結果,比較麻煩的是因為測試的緣故,會有很多相同IP但不同DUT的狀況發生,這時我的script裡就要在for loop的開始去砍掉~/.ssh/known_hosts所對應的IP,有點麻煩,經高人指定原來是可以讓SSH不檢查key,實作的方法是:

ssh -o StrictHostKeyChecking=no

不過要小心中間人攻擊唷~ 帽客是在Lab裡面這樣做,倒是不用擔心到這一點 :p

Wednesday, July 02, 2008

Tcl語法雜記

將一些我常用的Tcl語法記錄與此,以後好備查:

1.宣告變數:
set A 100

2.列印變數的值:
puts $A

3.Append變數:
set a {QA Engineer: }
set b {Lawrence Chiu}
puts $a
puts $b
append a $b
puts $a

4.Array:
#Set value to array
for {set i 5} {$i >= 0} {incr i -1} {
set myarray($i) $i
}
#Print array value
for {set i 0} {$i <= 5} {incr i +1} { puts "myarray($i)=$myarray($i)" }

5.將指令結果存於變數內:

set var [exec ifconfig]
puts $var
set var2 [exec ifconfig | grep "inet\ addr" | grep -v 127.0.0.1]
puts $var2

6.eval & subst:
set age 28
set str {I'm $age years old}
set cmd {puts "$str"}
eval $cmd
eval [subst $cmd]

7.foreach:
set SUM 0
foreach test {1 2 3 4 5} {
puts "$test"
set SUM [expr $SUM + $test]
}
puts "SUM=$SUM"

8.if:
set A 100
if {$A==101} {
puts "A=101"
} else { puts "A=100" }

9.開關檔:
set ls [exec ls]
set file [open file w]
puts $file $ls
close $file

10.positional應用:
set count [llength $argv]
puts $count
for { set i 0 } { $i <= [expr $count-1] } { incr i +1} { puts [lindex $argv $i] } 11.positional應用, foreach:
foreach a $argv {
puts $a
}

11.proc:
#functin f1
proc f1 {a b} {
return [expr $a + $b]
}

#Main program
set A 100
set B 150

set sum [f1 $A $B]
puts "A=$A"
puts "B=$B"
puts "A+B=$sum"

12. RE:
set var1 {abcde}
set var2 {b1234}
set var3 {aabcd}

puts "var1=$var1"
puts "var2=$var2"
puts "var3=$var3"
puts "\r"

puts "Which variable have a character?"
if {[regexp {a} $var1]} {
puts "var1 have a character"
} else { puts "var1 haven't a character" }

if {[regexp {a} $var2]} {
puts "var2 have a character"
} else { puts "var2 haven't a character" }

if {[regexp {a} $var3]} {
puts "var3 have a character"
} else { puts "var3 haven't a character" }
puts "\r"
puts "Which variable include number?"

if {[regexp {[0-9]} $var1]} {
puts "var1 have number"
} else { puts "var1 haven't a number" }

if {[regexp {[0-9]} $var2]} {
puts "var2 have number"
} else { puts "var2 haven't number" }

if {[regexp {[0-9]} $var3]} {
puts "var3 have number"
} else { puts "var3 haven't number" }

13.string:
set A "hello world!"
puts $A
puts [string length $A]
puts [string index $A 4]
puts [string range $A 6 9]
puts [string range $A 6 end]
puts [string toupper $A]
puts [string tolower $A]

14.switch:
set A yes
switch $A {
yes { puts "yes"}
no { puts "no" }
YES { puts "YES" }
default { puts "Not match!" }
}

15.while
set SUM 0
set i 1
while { $i <= 100} {
set SUM [expr $SUM + $i]
incr i 1
}
puts "SUM=$SUM"

Tcl online man page: http://www.tcl.tk/man/

Wednesday, June 25, 2008

Install OpenSUSE 11.0 on VirtualBox

把前幾天所抓下來的OpenSUSE11.0安裝到VirtualBox中,目前還在安裝中,大致上應該沒有什麼問題,值得一提的是安裝畫面還真是漂亮。




裝起來後就玩看看吧~

Friday, June 20, 2008

Study TCL

最近被上頭老大要求去玩一下TCL,所以這幾天就去玩玩,目前的心得它的語法真是有點簡單過了頭 :p 不過基本上我覺得還不錯用,結合expect遠端登入到別台機器自動處理些原本要手動且重覆性高的工作,就覺得愉快。

目前覺得最不方便的是要將執行結果存入檔案了,還要開檔關檔@@,不像BASH直接給它 ">"就好。

接下來學結合curl自動登入網頁做些事情,初步已經成功login網頁且取得我需要的資料了,不過此項技能還沒很熟練,還需練練。

Monday, June 16, 2008

sudo 免輸入密碼

這其實不是一個非常好的習慣,但是帽客在Ubuntu下常常sudo來sudo去的,有時跑些script或是執行命令時被要求輸入password,久了就有點煩,所以剛剛決定讓我自己的帳號免輸入password就可以執行所有的指令,方法非常簡單只要將下列敘述新增於/etc/sudoers就可以了,不需重新開機:

lawrence ALL=(ALL) NOPASSWD: ALL

Thursday, June 12, 2008

新增X字型

簡單記錄一下如何在Linux下新增X字型:

1.建立字型檔案:
-將要新增的字型檔案copy到/opt/myfonts下 (隨便哪個目錄都可以)
-執行mkfontscale;mkfontdir產生字型Summary (產生fonts.scale與fonts.dir)

2.將字型加入到X字型路徑 (不透過XFS)
- vi /etc/X11/xorg.conf
-在Section "Files"與EndSection中間 加入 FontPath "/opt/myfonts"
(先後順序是有差的,當兩目錄中存放相同名稱的字型時,會優先使用第一個。)

3.重新執行X,或透過xset fp rehash重新檢查所有字型目錄。

Note: 快速檢查是否有新增成功,可透過xfontsel來測試看看。

Thursday, May 29, 2008

忘記SUSE Linux root密碼時的解決方法

使用SUSE Linux的朋友們,如果您不小心忘了root密碼時,可以採取以下的補救方法:

1. 在boot options輸入 init=/bin/sh:

2. 此時如果直接以passwd嘗試修改的話,系統會報錯:

3. 原因是/此時為read-only,請將它remount成read-write,再次執行passwd,即可成功修改root password:

Tuesday, May 27, 2008

Bind view

透過bind view的功能,我們可以讓DNS Server見人說人話,見鬼說鬼話囉~怎麼說呢?比如說公司中Internet/Intranet的DNS名稱解析都是用同一台,但我不想讓Internet上的machine可以查詢到我內部的hostname時,此時透過bind view的功能,看是誰來查詢,並回應相關的結果。

整個named.conf的架構舉例如下:

22 view "intranet" {
23 match-clients {"192.168.1.0/24";};
24 zone "." IN {
25 type hint;
26 file "named.root";
27 };
28
29 zone "localdomain." IN {
30 type master;
31 file "localdomain.zone";
32 allow-update { none; };
33 };
34
35 zone "localhost." IN {
36 type master;
37 file "localhost.zone";
38 allow-update { none; };
39 };
40
41 zone "0.0.127.in-addr.arpa." IN {
42 type master;
43 file "named.local";
44 allow-update { none; };
45 };
46
47 zone "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa." IN {
48 type master;
49 file "named.ip6.local";
50 allow-update { none; };
51 };
52
53 zone "255.in-addr.arpa." IN {
54 type master;
55 file "named.broadcast";
56 allow-update { none; };
57 };
58
59 zone "0.in-addr.arpa." IN {
60 type master;
61 file "named.zero";
62 allow-update { none; };
63 };
64
65 zone "example.com" {
66 type master;
67 file "example.com.zone";
68 };
69 };
70
71
72 view "internet" {
73 match-clients {"!192.168.1.0/24";};
74 zone "." IN {
75 type hint;
76 file "named.root";
77 };
78
79 zone "localdomain." IN {
80 type master;
81 file "localdomain.zone";
82 allow-update { none; };
83 };
84
85 zone "localhost." IN {
86 type master;
87 file "localhost.zone";
88 allow-update { none; };
89 };
90
91 zone "0.0.127.in-addr.arpa." IN {
92 type master;
93 file "named.local";
94 allow-update { none; };
95 };
96
97 zone "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa." IN {
98 type master;
99 file "named.ip6.local";
100 allow-update { none; };
101 };
102
103 zone "255.in-addr.arpa." IN {
104 type master;
105 file "named.broadcast";
106 allow-update { none; };
107 };
108
109 zone "0.in-addr.arpa." IN {
110 type master;
111 file "named.zero";
112 allow-update { none; };
113 };
114 };
115
116 include "/etc/rndc.key";

其實就是多了
view "internet" {
match-clients {"!192.168.1.0/24";};
};

view "intranet" {
match-clients {"192.168.1.0/24";};
};

在這兩個區域內設定相關的zone/zone file就可以了。

Monday, May 26, 2008

Check user mailbox

以往測end user有沒有收到信時,總是習慣切到此使用者執行mail看看有沒有收到信件,今天發現了兩個方法可以不用這麼地麻煩的切換到此使用者,方法如下:

[root@vir1 ~]# mail -u lawrence
Mail version 8.1 6/6/93. Type ? for help.
"/var/mail/lawrence": 2 messages 1 new
1 MAILER-DAEMON@vir1.e Mon May 26 13:42 13/552 "DON'T DELETE THIS MES"
>N 2 root@vir1.example.co Mon May 26 17:35 20/714 "test1"
&
Message 2:
From root@vir1.example.com Mon May 26 17:35:49 2008
X-Original-To: qa@vir1.example.com
Delivered-To: qa@vir1.example.com
Date: Mon, 26 May 2008 17:35:48 +0800
From: root
To: qa@vir1.example.com
Subject: test1

CentOS release 5 (Final)
Kernel \r on an \m

or

[root@vir1 ~]# mail -f /var/spool/mail/lawrence
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/lawrence": 2 messages 1 new
1 MAILER-DAEMON@vir1.e Mon May 26 13:42 13/552 "DON'T DELETE THIS MES"
>N 2 root@vir1.example.co Mon May 26 17:35 20/714 "test1"
&
Message 2:
From root@vir1.example.com Mon May 26 17:35:49 2008
X-Original-To: qa@vir1.example.com
Delivered-To: qa@vir1.example.com
Date: Mon, 26 May 2008 17:35:48 +0800
From: root
To: qa@vir1.example.com
Subject: test1

CentOS release 5 (Final)
Kernel \r on an \m

Wednesday, May 21, 2008

SSH Server allow authorized_keys only

帽客家裡目前總共有2台Linux machines與一台iBook,一台安裝CentOS5.1當作file server使用,而iBook與HP NB分別安裝Mac OSX10.4與Ubuntu7.10,透過rsync的方法將資料update至file server,由於都有使用key作為ssh認證的方法,於是乎想把透過password認證方式取消掉,透過以下的方法完成了需求:

#vi /etc/ssh/sshd_config
-> UsePAM no
-> PasswordAuthentication no
#service sshd restart

Thursday, May 15, 2008

Fedora 9 available to download

前些日子出國,所以晚了些日子post到Blog上,有點想從Ubuntu轉回用Fedora,主要是因為我透過網路upgrade system時,Ubuntu 8.04在我的HP NB上運轉的很不順,3D桌面總是卡卡的,當然還有一些其它的問題,比如撥放rmvb時,超卡的根本無法看,只好用partimage recovery回7.10(好險升級前有backup),既然有備份了,那麼就安裝Fedora 9看看吧,事實上我還是使用Fedora/SUSE順手一點 :)

當然Ubuntu還是很棒的!是我目前感覺最親切的Linux distribution.

Thursday, April 24, 2008

Tcpreplay

Tcpreplay可說是從事網通研發人員的一個好工具,它可以將libpcap format的封包記錄檔,重新reply出來,以利除錯或是regression test,不論是In-line mode或是Routing mode的device,它都有辦法可以將封包pass through device,除了replay,它還可透過tcprewrite修改封包的內容,這麼強大的工具您怎麼可以錯過呢?

Tcpreplay website: http://tcpreplay.synfin.net/trac/


Thursday, April 17, 2008

虛擬機器軟體大集合

今天發現到有個forum針對各家虛擬機器的軟體加以整理與介紹,非常棒!值得收藏起來。

Welcome : Links to get started with Virtualization

Tuesday, April 15, 2008

Linux下的partition magic: GParted

經過測試對ext3的partition做放大與縮小都沒有問題,至於FAT與NTFS就抱歉了,因為很少用Windows所以就不驗證了。

Gparted 官網:
http://gparted.sourceforge.net/

Ubuntu Wiki對於Gparted的教學文件:
http://wiki.ubuntu.org.tw/index.php/GParted

Gparted Live-CD:
http://gparted-livecd.tuxfamily.org/

Saturday, April 12, 2008

固定指定的DNS Server

帽客自己在使用Linux作業系統時,當把NIC設定成透過DHCP Server取得IP時,往往會把我自己所指定好的DNS Server覆蓋掉成DHCP Server所配置的DNS Server address,近日拜讀Cd Chen大大的書時,發現到了一個參數PEERDNS,當在NIC設定檔中把它設定成PEERDNS=no時,那麼/etc/resolv.confnameserver就不會被覆蓋掉了。

Friday, April 11, 2008

Apache stress test tool

今天發現到一個針對Apache Web Server的壓力/效能測試工具,在此做個簡單的筆記:
Tools: ApacheBench
Function: 針對某一Web Server提出連線請求,並且在同一時間內可設定幾個連線請求
Usage: # ab -n N -c N http://server1.example.com/index.html
-c concurrency
Number of multiple requests to perform at a time. Default is one request at a time.
-n requests
Number of requests to perform for the benchmarking session. The default is to just perform
single request which usually leads to non-representative benchmarking results.

Executed Result:
[root@server2 ~]# ab -n 100 -c 100 https://10.5.40.195/script/login.php
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking 10.5.40.195 (be patient).....done


Server Software: Apache
Server Hostname: 10.5.40.195
Server Port: 443
SSL/TLS Protocol: TLSv1/SSLv3,DHE-RSA-AES256-SHA,1024,256

Document Path: /script/login.php
Document Length: 5953 bytes

Concurrency Level: 100
Time taken for tests: 14.492808 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 635400 bytes
HTML transferred: 595300 bytes
Requests per second: 6.90 [#/sec] (mean)
Time per request: 14492.808 [ms] (mean)
Time per request: 144.928 [ms] (mean, across all concurrent requests)
Transfer rate: 42.78 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 680 5075 3167.2 4795 14099
Processing: 114 959 1238.7 540 6085
Waiting: 112 913 1240.5 506 6082
Total: 896 6035 3844.3 5503 14470

Percentage of the requests served within a certain time (ms)
50% 5503
66% 6735
75% 7557
80% 8250
90% 14178
95% 14334
98% 14444
99% 14470
100% 14470 (longest request)