Wednesday, August 26, 2009

HTTP Server Benchmark Test Tool: WBox

WBox aims to help you having fun while testing HTTP related stuff. You can use it to perform many tasks, including the following:

- Benchmarking how much time it takes to generate content for your web application.
- Web server and web application stressing.
- Testing virtual domains configuration without the need to alter your local resolver.
- Check if your redirects are working correctly emitting the right HTTP code.
- Test if the HTTP compression is working and if it is actually serving pages faster.
- Use it as a configuration-less HTTP server to share files! (see the server mode documentation at the end of the Wbox tutorial in this page, but it's as simple as % wbox servermode webroot /tmp)

Wbox is free software under the GPL version 2 license and was written in ANSI C (POSIX runtime required) by Salvatore 'antirez' Sanfilippo

使用過後,個人感覺比ab強大好用!

Thursday, July 30, 2009

Deny SSH brute attack via iptables

iptables rules:
#iptables -A INPUT -p tcp --dport 22 -i ethx -m state --state NEW -m recent --set
#iptables -A INPUT -p tcp --dport 22 -i ethx -m state --state NEW -m recent --update --seconds 60 --hitcount 5 -j DROP
如此一來,本機於1分鐘內收到超過5個以上的SSH連線需求時,第5個SSH connection就會被drop掉.

緊接著用hping測試連續送出n個TCP port 22 SYN,看看第5個SSH connection是否會被drop:


Reference:
http://www.cyberciti.biz/tips/linux-unix-bsd-openssh-server-best-practices.html
http://tuxtraining.com/2009/06/23/stop-ssh-brute-force-attack-using-susefirewall

Thursday, July 23, 2009

Suspend Linux to swap

分享一個在console下將Linux系統休眠到swap的方法:

Tested on CentOS5.3:
Step1. 設定STD(suspend to disk)到swap:
[root@localhost ~]# fdisk -l
Disk /dev/hda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14         842     6658942+  83  Linux
/dev/hda3             843         907      522112+  82  Linux swap / Solaris
/dev/hda4             908        1044     1100452+   5  Extended
/dev/hda5             908         972      522081   83  Linux
[root@localhost ~]# ls -ld /dev/hda3
brw-r----- 1 root disk 3, 3 Jul 23  2009 /dev/hda3

由此得知swap partition的major與minor ID是3.3,接著修改參數如下 (預設是0:0):
[root@localhost power]# echo "3:3" > /sys/power/resume 

Step2. 啟動休眠:
[root@localhost ~]# echo "disk" > /sys/power/state 

此時系統將立刻進入休眠狀態,並於下次重開機時回到剛剛的環境。

Step3. 設定永久suspend到swap:
修改/boot/grub/grub.conf並設定Kernel參數如下:
kernel /vmlinuz-2.6.18-128.2.1.el5 ro root=LABEL=/ rhgb quiet resume=/dev/hda3

Tuesday, July 14, 2009

善用tmpfs當Firefox的cache

現在的電腦記憶體很夠用, Redhat/CentOS預設又將/dev/shm當成tmpfs掛載起來, 所以也就別辜負了它的美意吧! 把它拿來當成Firefox cache的RAMDisk用吧!

至於如何將Firefox的cache指定到/dev/shm呢? 實作上非常簡單, 只要開啟Firefox並於網址列上輸入about:config, 然後點擊滑鼠右鍵->新增->字串後輸入: browser.cache.disk.parent_directory, 內容則輸入/dev/shm就完成了.


成功的話, 當使用Firefox瀏覽網頁時就會看到/dev/shm會新增Cache目錄.
當然系統重新開機後, cache就會消失了!
Note: Redhat/CentOS預設並不特別指定/dev/shm的大小為何, 記憶體剩下多少就允許/dev/shm使用, 如果想要改變此行為的話可開啟/dev/fstab,找到mount /dev/shm的那一列並修改如下:
tmpfs /dev/shm tmpfs defaults,size=100M 0 0
以上希望對大家使用Linux有幫助.

Thursday, July 02, 2009

Compress and encrypt directory in Linux

直接進入實作步驟~
Compress tools: tar
Data encrypt tools: AES Crypt (http://www.aescrypt.com/)

Objective-1, To backup /etc and encrypt it:
1. 壓縮並加密/etc:
# tar cvf - /etc | aescrypt -e -p 123456 -> etc.tar.aes
(-e: encrypt, -p password)

2. 測試etc.tar.aes是否有加密:
[root@localhost ~]# file etc.tar.aes
etc.tar.aes: data
[root@localhost ~]# tar tvf etc.tar.aes
tar: This does not look like a tar archive
tar: Skipping to next header
tar: Archive contains obsolescent base-64 headers
tar: Read 300 bytes from etc.tar.aes
tar: Error exit delayed from previous errors
測試結果發現到etc.tar.aes已經被AES加密了,故無法直接以tar觀看壓縮檔的內容。

Objective-2 To decrypt and uncompress data:
1. 將壓縮檔解密:
# aescrypt -d -p 123456 etc.tgz.aes 
解密後會新增一檔案為etc.tar
2. 解壓縮:
# tar xvf etc.tar
如此一來便可解開加密過後的壓縮檔了。

其它在Linux上常見的加密工具還有openssl與gpg。

Monday, June 29, 2009

20個Linux系統/網路偵測的好工具

發現到一篇介紹20個Linux系統/網路偵測工具的好網頁,挺多我沒有使用過的,所以特別收錄起來,FYI。

Sunday, June 21, 2009

Free online file conversion: Zamzar

很多人為了轉換檔案格式,總是會在電腦上裝載各種轉換的軟體,甚至有時收到了不能讀取的檔案時就更是令人感到心煩了,比如Office 2007的docx,像我的Linux與OSX都沒辦法讀取docx的文件,偏偏有人就是很喜歡寄給我但也總不能去請人家去轉換好再寄給我吧,此時只好自己開啟Windows的office 2007來看,挺浪費時間,嘿嘿~不過今天真是個好日子,讓我發現了一個能解決我這種困擾的服務,Zamzar!

Zamzar它是一個免費的線上格式轉換的服務,不論您使用那種OS(事實上跟OS一點關係都沒有),只要將檔案透過Web browser上傳後,選擇想轉換成的檔案格式,它就會幫你將檔案轉換好並透過mail告訴你檔案下載的連結,真的是非常之方便呀!目前檔案的上限為100MB,而能轉換的格式真是包山包海呀!


Wednesday, June 10, 2009

[Shell script] Remote Services watchdog

以下的script是針對偵測到對方的service沒有正常運作時則發mail給所指定的使用者,請參考:

#!/bin/bash

SRVLIST='192.168.0.100:80
192.168.0.100:53'
MAILACCOUNT="root@server1.example.com"

for SRV in `echo $SRVLIST`
do
 IP=`echo $SRV | cut -d: -f1`
 PORT=`echo $SRV | cut -d: -f2`
 nc -w 1 $IP $PORT > /dev/null 2>&1 || echo "Port $PORT on Server $IP is failed" | mail -s "Error: Service failed" $MAILACCOUNT
done

Monday, June 08, 2009

Install AWstats on CentOS 5.x

What's AWstats?
AWStats is a free powerful and featureful tool that generates advanced web, streaming, ftp or mail server statistics, graphically. This log analyzer works as a CGI or from command line and shows you all possible information your log contains, in few graphical web pages. It uses a partial information file to be able to process large log files, often and quickly. It can analyze log files from all major server tools like Apache log files (NCSA combined/XLF/ELF log format or common/CLF log format), WebStar, IIS (W3C log format) and a lot of other web, proxy, wap, streaming servers, mail servers and some ftp servers.
http://awstats.sourceforge.net/

安裝步驟:
1. 於rpmfind.net 搜尋並下載awstat*rpm for RHEL5.x (awstats-6.9-2.el5.rf.noarch.rpm)
2. # rpm -ivh awstat*rpm
3. 修改/etc/httpd/conf/httpd.conf:
AddHandler cgi-script .cgi .pl
4. 修改/etc/httpd/conf.d/awstats.conf :
Alias /awstats/icon/ /var/www/awstats/icon/
ScriptAlias /awstats/ /var/www/awstats/
        DirectoryIndex awstats.pl
        Options ExecCGI
        Order allow,deny
        Allow from all
#       order deny,allow
#       deny from all
#       allow from 127.0.0.1
5. 將/etc/awstats/awstats.localhost.localdomain.conf改成/etc/awstats/awstats.IPADDRESS.conf (e.g., IPADDRESS=192.168.0.1)

6.手動執行/etc/cron.hourly/00awstats
如此一來就馬上有資料產生了,之後就交給system crontable更新吧!

7. 開啟瀏覽器並輸入 http://192.168.0.1/awstats/awstats.pl,成功的話應該會看到以下的畫面:

Note: awstats.IPADDRESS.conf 有許多參數可調整,請參考裡面的說明。

Sunday, June 07, 2009

帽客剛整理好的桌面

剛整理好,乾淨了一些,拍個照紀錄一下。


Saturday, June 06, 2009

[Shell script] Services watchdog

這隻script的功能就是當偵測到所指定的port於本機沒有啟動的話,就會將它自動重啟,放在cron table裡定時檢查吧!

#!/bin/bash

SRVLIST='80:/etc/init.d/httpd
25:/etc/init.d/postfix
22:/etc/init.d/sshd
110:/etc/init.d/dovecot'

for SRV in `echo $SRVLIST`
do
 nc -w 1 localhost `echo $SRV | cut -d: -f1` > /dev/null 2>&1 && echo "Port $SRV fine" || `echo $SRV|cut -d: -f2` restart
done


[Shell script] Monitor process cpu loading and count

1. 當process CPU loading超過90%, 就先行刪除:
#!/bin/bash
CPULOADING=90
ps auxh | \
while read pro
do
set -- $pro
if [ `echo $3 | cut -d"." -f1` -gt $CPULOADING ]; then
kill $2
fi
done

2.當process數目超過50時, 就先行刪除:
#!/bin/bash
PSCOUNT=50
ps axh -o "cmd" | sort | uniq -d -c | \
while read ps
do
set -- $ps
if [ $1 -gt $PSCOUNT ]; then
killall $2
fi
done

Reference: Linux網路安全管理與監控

Friday, June 05, 2009

[Shell script] Monitor Disk space

#!/bin/bash
USAGE_SPACE=20

df | grep '[0-9]%' | egrep 'sd|hd' | \
while read line 
do
# if [ `echo $line | awk -F" " '{ print $5 }' | cut -d% -f1` -gt "$USAGE_SPACE" ]; then
# echo "Disk space of `echo $line | awk -F" " '{ print $6}'` belongs to `hostname` is over $USAGE_SPACE%" | mail -s "HD DISK is not enough" $USER
# fi

set -- $line
if [ `echo $5 | cut -d% -f1` -gt $USAGE_SPACE ]; then
echo "Disk space of `echo $6` belongs to `hostname` is over $USAGE_SPACE%" | mail -s "HD DISK is not enough" $USER
fi
done

Remark的部份是小弟以前的做法,利用awk去filter出硬碟使用的百分比與目錄名稱,但拜讀了新書"Linux 網路安全管理與監控",學到了可透過set --$line方便取出某行的資料為引數使用,好用!


Sunday, May 31, 2009

Eason Chen Moving on stage 21 part II

昨晚陪老婆去台北小巨蛋聽陳奕迅Moving on stage 21 part II的演唱會,老實說我並非Eason的歌迷,對他的歌比較熟悉的是只有K歌之王,你的背包,婚禮的祝福(這張專輯我有買)。
整體聽下來我可以了解為何老婆這麼喜歡Eason了,他真的很有實力,歌曲確實能打動人心, 感覺上他真的唱得很賣力,連唱了四個小時吧!有幸能參加這種實力派歌手的演唱會真是我們的幸福,可惜我只聽到11:00多就先行離場回家去哄小朋友睡覺了,不然真的很想跟Eason待到最後。

Anyway Eason期待你下一次再來台北開唱!婚禮的祝福真是太好聽了!

Wednesday, May 20, 2009

Moving SUSE Linux to another system

工作用的一台PC可能太過老舊,常常跑到一半就system freeze,懷疑是熱當,然而剛好有一台idle的機器,想說就將hard drive換到那台機器就好了,本以為應該會很順利,沒想到系統重開時SUSE回報:
waiting for device /dev/hda2 to appear
waiting for device /dev/hda4 to appear
然後整個系統就停止了.... 事情似乎沒有我想像得單純..... :p
進入rescue mode查看hard drive也沒損壞呀? 只好上google查看看吧~

後來查到原來是當更換到另一台機器時,由於主機板上的controller是不一樣的! SUSE需要重新make initrd, Redhat不用! 呵呵.... 整個救援的方法如下:

hard drive partition information:
/dev/hda1 -> /boot
/dev/hda2 -> swap
/dev/hda3 -> /home
/dev/hda4 -> /

1. 利用SUSE安裝光碟進入rescue mode
2. 將root partition掛載: mount /dev/hda4 /mnt
3. 將rescue mode的/dev與/proc分別掛載到 /mnt/dev與/mnt/proc: mount --bind /dev /mnt/dev; mount --bind /proc /mnt/proc
4. 將目前的rescue mode的single-root轉成實際上的root partition: chroot /mnt
5. 將/boot掛載: mount /dev/hda1 /boot
6. 切換到/boot目錄,並執行mkinitrd: cd /boot; mkinitrd

Accomplished!

Monday, May 18, 2009

快速取得路由路徑資訊

在Linux下,要確定或查看到某一個destination的方法,比較傳統的方法是執行route -n 或是netstat -rn取得routing table後,再以肉眼判斷讀出,不過我看過有些人管控的機器其routing table內容非常之可怕! 眼睛可能會看到"脫窗", 所幸我今天發現到了一個新的指令可以幫助苦命的IT/MIS.

# ip route get x.x.x.x
-> 系統就會回報到x.x.x.x會經由哪個gateway出去, e.g.,
ip route get 168.95.1.1
168.95.1.1 via 192.168.1.254 dev br0 src 192.168.1.100
cache mtu 1500 advmss 1460 hoplimit 64
解讀: 從src 192.168.1.100到dst 168.95.1.1是透過192.168.1.254出去

Tuesday, May 12, 2009

[Shell script] 讓/etc/passwd更利於閱讀

#!/bin/bash
IFS=:
echo "System User list:"
echo "-------------------------------------"
while read username shapass uid gid comm home shell
do
echo "UserName:$username"
echo " 1.password:$shapass"
echo " 2.uid:$uid"
echo " 3.gid:$gid"
echo " 4.comment:$comm"
echo " 5.home:$home"
echo " 6.default shell:$shell"
echo "------------------------------------"
done < /etc/passwd

參考Linux-101 Hacks, hack 88. Read data file fields inside a shell script

Monday, May 11, 2009

Get Ready for openSUSE Community Week!

The first openSUSE Community Week is just around the corner. May 11 through May 17 we’ll be hosting live sessions in IRC to help grow the openSUSE Community.
Community week is all about helping new contributors get started with openSUSE and getting existing contributors together to mentor new contributors, and working together on major projects.
We’ll be hosting a week of IRC tutorials, Q&A’s, and jam sessions on a number of topics. Learn to work with the testing/QA team, create packages, work with the openSUSE Build Service, help work on the wiki, or get involved with the GNOME and KDE teams. There’s something for everybody.


Schedule:
http://en.opensuse.org/Community_Week

Tuesday, May 05, 2009

Ubuntu and Upstart

Ubuntu與Fedora都採用了upstart模擬跑SysV. 但是OpenSUSE11.1/SLES11 whereas.... 還是採用大家熟悉的SysV, 讓我們來看看Novell的concern吧:

http://en.opensuse.org/Ubuntu_and_Upstart

是不是差點沒說出脫褲子放屁~ XD

Thursday, April 23, 2009

wget useful parameters

遇到了所以在此做個紀錄,雜記一下:

# wget -r -np -A img,txt,gz,pcap,cap http://xxx.xxx.xxx
-r --recursive
-np --no-parent
-A --accept=LIST
-> 如此一來就會對xxx.xxx.xxx的網站以遞迴的方式,抓取以img,txt,gz,pcap與cap類型的檔案,其它的都會忽視。

更多的參數可透過wget --help或是man wget獲得更進一步的資訊。

Monday, April 13, 2009

忽視記錄指定的指令於history中

上次介紹可用HISTCONTROL="ignorespace"來忽視開頭為"空白"的指令記錄於history中,今天再提供另一種可行的方法,當看到特定的指令時,也將不記錄於history中,實作的方法如下:

Usage: HISTIGNORE="cmd1:cmd2"

Example1: 忽視記錄pwd,useradd,userdel,passwd等指令:
# export HISTIGNORE="pwd:useradd:userdel:passwd"

Example2: 開機即套用:
Redhat/SUSE: echo 'export HISTIGNORE="pwd:useradd:userdel:passwd"' >> /etc/profile
Note: 如果系統不允許重開機,可以透過source /etc/profile來生效。

Friday, April 10, 2009

不紀錄開頭為space的指令於history中

直接來看如何實作吧!
舉個常會碰到的例子, 如果在console下需輸入敏感的資料時, 不要讓它記錄到history中:
#HISTCONTROL=ignorespace
# echo "redhat" | passwd --stdin lawrence (注意開頭必需為空白)
#history

如此一來echo "redhat" | passwd --stdin lawrence 就不會記錄到history中.

Wednesday, April 08, 2009

Modify Linux prompt

改變一下原本CentOS5.x黑底白字的prompt為黑底綠字如下, 有小學時用DOS的fu ~ XD



加入以下的設定於 /etc/profile讓每個使用者都有這種fu ~
PS1="\e[0;32m[\u@\h \W]$ \e[m"

Cocoa Packet Analyzer in OSX

以前帽客要在OSX下抓網路封包, 有兩種方法:
1. 開啟終端機, 執行tcpdump -> 只有文字模式
2. 安裝X11-> 透過某個在OSX下能安裝Linux apps的工具(Fink)安裝wireshark -> 有圖形可看了, 但是挺麻煩.

現在不用囉! 直接給它安裝Cocoa Packet Analyzer就可以在OSX下抓網路封包啦!
About Cocoa Packet Analyzer
A native Mac OS X implementation of a network protocol analyzer and packet sniffer. It is able to do basic network capturing (incl. packet filtering), analyze and display packet trace files. CPA supports the industry-standard PCAP packet capture format for reading, capturing and writing packet trace files. Further more the libPCAP/ tcpdump filter expressions may be used during capturing network traffic. It supports a variety of network protocols and can be enhanced using the Cocoa bundle plugin technology. Features a quicklook plugin so you can get an overview of you trace file even in finder.

Support libpcap format, 太棒了正是我需要的, 因為我 慣用的packet playback tools只支援libpcap format.

Download: http://www.apple.com/downloads/macosx/networking_security/cocoapacketanalyzer.html

Friday, April 03, 2009

透過ac command 顯示所有使用者登入的時間

今天看書,學習到利用ac指令來獲取系統上所有使用者上線的總時間,帽客覺得這是非常實用的指令,故於此分享給大家,以下是ac的簡單說明: (man page description)
ac prints out a report of connect time (in hours) based on the logins/logouts in the current wtmp file. A total is also printed out.

ok, 再來以上線跑不久的OpenSUSE11.1來做個例子:

Example1: 顯示每天所有使用者上線的時間總和:
linux-xgby:~ # ac -d
Mar 7 total 28.81
Mar 9 total 0.14
Mar 13 total 17.35
Mar 15 total 32.28
Mar 20 total 8.09
Mar 21 total 3.00
Mar 22 total 44.08
Mar 23 total 10.44
Mar 24 total 33.19
Mar 25 total 29.43
Mar 31 total 0.03
Apr 1 total 15.17
Apr 2 total 4.47
Apr 2 total 14.60
Apr 3 total 21.09
Today total 1.67

Example2: 顯示個別使用者上線的時間總和:
linux-xgby:~ # ac -p
lawrence 258.67
root 5.31
total 263.98

如何,夠簡單又實用吧!

Thursday, April 02, 2009

To compile polygraph network benchmark tools on CentOS5.2

What's polygraph?
"Web Polygraph is a freely available performance testing tool for caching proxies, origin server accelerators, L4/7 switches, content filters, and other Web intermediaries. Polygraph's features include:
high-performance HTTP clients and servers
realistic HTTP and SSL traffic generation
HTTP Basic, NTLM, and Negotiate proxy authentication
LDAP-friendly generation of user credentials
flexible content simulation
ready-to-use standard workloads for benchmarking
powerful domain-specific configuration language
portable open-source implementation
friendly commercial support "


http://www.web-polygraph.org/

在CentOS5.2下編譯polygraph v3.1.5時會發生SslWrap.cc的問題,解決的方法是:
http://www.linuxquestions.org/questions/linux-server-73/problem-compiling-web-polygraph-689766/

./configure;make;make install 好搞定了! Enjoy it!

Thursday, March 26, 2009

Novell SLES11 Server/Desktop is available to download

哇哈哈~ Novell SLES11 Server/Desktop總算是釋出了,目前家裡一台P4 2.4GHz的老PC跑OpenSUSE 11.0讓我非常滿意,之前有聽說過SLES11是基於OpenSUSE 11.1開發的。

打算先找台NB裝一下看看,BTW Novell SLES11與SLES10一樣提供60天的免費更新,哈!還算ok!
謎之音: 之前在某家公司內部所架設的SLES10 <- 提供挺多services 沒當過,不知還在運作否 XD

Monday, March 16, 2009

OSX: 螢幕抓圖利器 InstantShot!


InstantShot! 是帽客在OSX環境下慣用的螢幕抓圖軟體,個人覺得非常直覺好用,重點是它支援中文又是free的,這麼好用的軟體希望Mac fans不要錯過囉。

Friday, March 13, 2009

Linux管理小技巧: CDPATH

預設上, RHEL5.x與CentOS5.x的bind有chroot的機制, 所以當系統管理者要去更改named.conf或是相關的DNS zonefile時就必需要輸入/var/named/chroot/etc/ or /var/named/chroot/var/named/ 恩... 有點長, tab要按好幾次, 於是乎帽客想到了一個好用的偷懶方法, CDPATH.

透過CDPATH可以設定parent directory然後透過cd指令切入到subdirectories, 看起來有點抽象? 實際看看例子吧:


上面的例子是設定CDPATH為DNS Server chroot的路徑(/var/named/chroot), 並將它變成環境變數, 之後只要輸入cd etc就會切入到/var/named/chroot/etc, 而cd var/named就會切入到/var/named/chroot/var/named.

看起來方便多了吧!

update:
讓CDPATH重開機時就生效吧:
echo "CDPATH=/var/named/chroot" >> /root/.bash_profile

2009.3.16 update:
今天發現到bash內建的command,pushd與popd也有著類似的功能:
先將/var/named/chroot 透過pushd新增至stack中,並用dirs確定目前stack的內容(第一筆永遠是current directory),之後透過cd就可以切換到subdirectories。

Thursday, March 12, 2009

經濟愈差 病毒愈多

我的好朋友Mark給我以下的消息,網路實在是不安全。

Tuesday, March 10, 2009

Compile Linux kernel "2.6.28.7" on CentOS5.2

想玩看看EXT4,所以下載了最新版有支援EXT4的kernel於CentOS5.2上,以下是compile的雜記:

1. 於/usr/src/kernels/解開2.6.28.7的kernel source (download: www.kernel.org)
2. 將目前的kernel config 從/boot下copy到/usr/src/kernels/2.6.28.7/.config
3. 於/usr/src/kernels/2.6.28.7執行make menuconfig
-> Add EXT4
-> Remove Bluetooth
-> Remove wireless
4. 執行make bzImage
5. 執行make modules
6. 執行make modules_install
7. 執行make install
8. 檢查/boot/*, /boot/grub/grub.conf
-> 開機選用kernel 2.6.28.7開機。
2009.3.25 update:
Tested ext3 and ext4 performance on kernel 2.6.29 and result as below:
It looks like ext4 is better than ext3.
Note: To clean HD cache for each test processing by hdparm -f command.

Tuesday, February 24, 2009

列印出每個使用者登入至Linux主機的總次數

這麼下達就可以得到結果了 :

# last|awk -F" " '{print $1}'|grep -v "^$"|grep -v reboot|grep -v wtmp|sort|uniq -c

Monday, February 16, 2009

Check Linux NIC driver

工作需求所以用到了, 在此記錄:

#ethtool -i eth0
driver: e1000e
version: 0.3.3.3-k6
firmware-version: 5.7-6
bus-info: 0000:0c:00.0

Linux liveUSB creator

發現了一套可執行於Linux與Windows的Linux liveUSB creator: liveusb-creator 透過它, 可以很方便的透過iso檔製作出liveusb, usb開機比DVD/CD-ROM開機不僅來得快也來得方便多了, 畢竟現在很多notebook/netbook預設都不搭配DVD/CD-ROM.

安裝:
-如果你要運行於Windows在可於此下載, 解開並執行liveusb-creator.exe: liveusb-creator-3.2.zip
-然而如果要運行於Linux的話, 以Fedora9/10來說, 可直接透過yum安裝: # yum install liveusb-creator

測試:
Under Windows XP SP3
1. 插入USB device
2. Fdisk/Format USB device 為單一主要分割區, 格式為FAT32 (目前只能運作於FAT32/EXT)
3. 執行liveusb-creator.exe
4. 選擇來源ISO: systemrescuecd-x86-1.1.5.iso
5. 選擇Target Device為USB device partition
-> Completed

之後透過USB device開機, systemrescuecd Linux正常開機且運作順利.
更多的資訊可參考官方的FAQ: https://fedorahosted.org/liveusb-creator/wiki/FAQ

Thursday, January 22, 2009

Disable bug buddy in OpenSUSE11.1

這幾天OpenSUSE在X環境下(GNOME)不斷跳出bug buddy的popup message, 而我也已經將系統錯誤訊息回傳給OpenSUSE研發團隊了,但是它還是不斷地popup,有點惱人,決定先行關掉它了:

Disable bug buddy message method:
編輯家目錄下的 .profile:
vi ~/.profile
#Disable bug buddy message
export GNOME_DISABLE_CRASH_DIALOG=1

重新登入或重開機後就不再popup了.

Tuesday, January 20, 2009

iptstate tools

利用iptstate tools你可以觀察到netfilter中每一筆connection的狀況, 真是隻好工具! 使用時請先記得將ip_conntrack kernel module 掛載起來, 否則將無任何資料顯示出來.

# modprobe ip_conntrack

http://phildev.net/iptstate/

Tuesday, December 30, 2008

Linux4One for Acer Aspire One

有小萬朋友可以考慮安裝此發行版本Linux4One, 它針對小萬做了最佳化, 並包含了所有的硬體驅動程式, 且是基於Ubuntu加以修改.

http://www.linux4one.it/
http://downloads.agrilan.net/Linux4one_RC_1.iso

Thursday, December 25, 2008

一樣的blog name?

最近在google search自己的blog時(不是自戀,只是在別台電腦要找一下自己以前寫的文章參考),發現到竟然有人跟我用雷同的Blog name?! 只是他是熱愛Linux的電腦癡漢,而不是同時熱愛Linux與Mac OSX的電腦癡漢 XD。

在此想聲明一下那個人不是我唷!呵呵~那不是我的私生活呀~~~ 大家千萬別誤會。

Wednesday, December 24, 2008

OpenSUSE 11.1 特別的GRUB畫面

今天啟動OpenSUSE 11.1的機器時, 發現到讓我驚喜的畫面如下, 企鵝過聖誕?! 圖中的企鵝還會動哩.. 真是別具巧思的設計, 應該是利用gfxmenu美化的吧?

Monday, December 22, 2008

Add third-party repository for openSUSE 11.1

Step:
# zypper addrepo --repo http://packman.mirrors.skynet.be/pub/packman/suse/11.1/Packman.repo

Packman is the most popular third-party repository available for openSUSE. It contains many packages that aren't in the openSUSE version; either because they cannot be included for legal reasons, because the distribution contains an older version, or simply because it was never packaged for the distribution release.

This is the repository where you can acquire the relevant mp3 and other codecs, as well as many multimedia applications (such as mplayer), torrent clients, games, etc...

之後透過yast的Software/Software Management來安裝所需要的套件就方便了許多.

Thursday, December 18, 2008

Monitor Linux machine status (cpu, memory, traffic) via MRTG

有興趣的朋友, 請到以下的連結download小弟拙作:
http://www.nakido.com/B8DD850DCFA3C65697D5C5371559FBE6E6EA2E55

Note: 文章中的cpu.cfg與mem.cfg是參考阿駕零零壹 © 學習筆記 加以修改.

Tuesday, December 16, 2008

OSX: 在文字模式下執行修復檔案權限

透過GUI實在是太慢了,可開啟Terminal執行 sudo diskutil repairpermissions /
搞定收工~

UUID使用小技巧

在網路上看到了一篇關於UUID的使用好方法,整理如下:
1. 查看device的UUID:
1.1 blkid:

1.2 查看/dev/disk/by-uuid directory:


2.透過UUID反查device name:


補充:
亂數產生UUID: uuidgen
Clone UUID: tune2fs -U /dev/hdax

Friday, December 05, 2008

Fedora10: 在滑鼠右鍵中增加"終端機"

帽客習慣使用Console來操作Linux, 而Fedora 10 預設於GNOME中按下滑鼠右鍵並沒有開啟終端機的選項, 對於我來說實在是有點麻煩, 然而其實只要安裝上nautilus-open-terminal並重新登入GNOME就可以了.

Step: # yum -y install nautilus-open-terminal


PS. Ubuntu預設也應該是如此, 只是安裝完後上了Lazybuntu就包含了進去.

Thursday, December 04, 2008

Clonezilla

昨天在逛Linux today時, 無意中發現到有篇介紹Clonezilla的文章, 看完後感到非常有興趣, 所以就連到Clonezilla official website, 猛然發覺這套軟體是"MIT"的, 台灣人製造的哩! 當然要給它推一下.

Clonezilla經過帽客實際的測試過後, 的確是非常好用又簡單, 我採用的備份政策是backup full HD to remote samba server, 並用Virtualbox故意建立一個比原本HD還大容量的HD來測試從Samba server restore full HD, 結果完全沒有出錯.

測試的作業系統是Fedora10, file system是ext3與swap.

下一次我想試看看:

-Backup/restore specify partition via remote file server.
-Backup/restore OSX10.5.5 (HFS+)

Monday, November 17, 2008

expect example

In bash:
#!/bin/bash
expect -c "
spawn ssh root@1.1.1.1
expect password:
send \"1234\r\"
expect ]#
send \"ls -l\r\"
expect ]#
send \"uname -r\r\"
expect -timeout 1
"
Not in bash:
#!/usr/bin/expect
spawn ssh root@1.1.1.1
expect "password: "
send "1234\r"
expect "]# "
send "uname -r\r"
expect -timeout 1

Friday, October 31, 2008

dmidecode

Windows下相信大家常用cpuz去查看主機板的詳細資訊,而Linux下則可用dmidecode這個工具來查看,這邊是dmidecode官網的example: dmidecode example。

安裝的方法非常簡單,將tarball檔抓下來後,進入到解開的目錄中執行:make;make install即可安裝成功,而執行時直接打dmidecode就可以了,配合重新輸出導向,就可將此info記錄到某一檔案中。

Wednesday, October 22, 2008

Check USB status in Linux

簡單介紹一下如何在Linux OS下查看USB的控制器與其它資訊,一個非常簡單的方法是透過lspci,如下所示:
[root@s1 ~]# lspci | grep -i usb
00:07.2 USB Controller: VIA Technologies, Inc. VT82xxxxx UHCI USB 1.1 Controller (rev 16)
00:07.3 USB Controller: VIA Technologies, Inc. VT82xxxxx UHCI USB 1.1 Controller (rev 16)

可以看出這台老PC只支援USB 1.x 
PS. USB 控制器:
-UHCI: USB 1.x Inetl/VIA mb
-OHCI: USB 1.x 非Intel/VIA mb
-EHCI: USB 2.0

另外一個包含非常多USB資訊的檔案:
[root@s1 ~]# cat /proc/bus/usb/devices 
T:  Bus=02 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
B:  Alloc=  0/900 us ( 0%), #Int=  0, #Iso=  0
D:  Ver= 1.10 Cls=09(hub  ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=0000 ProdID=0000 Rev= 2.06
S:  Manufacturer=Linux 2.6.18-53.el5 uhci_hcd
S:  Product=UHCI Host Controller
S:  SerialNumber=0000:00:07.3
C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=  0mA
I:  If#= 0 Alt= 0 #EPs= 1 Cls=09(hub  ) Sub=00 Prot=00 Driver=hub
E:  Ad=81(I) Atr=03(Int.) MxPS=   2 Ivl=255ms

T:  Bus=01 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
B:  Alloc=  0/900 us ( 0%), #Int=  0, #Iso=  0
D:  Ver= 1.10 Cls=09(hub  ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=0000 ProdID=0000 Rev= 2.06
S:  Manufacturer=Linux 2.6.18-53.el5 uhci_hcd
S:  Product=UHCI Host Controller
S:  SerialNumber=0000:00:07.2
C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=  0mA
I:  If#= 0 Alt= 0 #EPs= 1 Cls=09(hub  ) Sub=00 Prot=00 Driver=hub
E:  Ad=81(I) Atr=03(Int.) MxPS=   2 Ivl=255ms


Wednesday, October 15, 2008

利用PAM限制SSH login的user account

實作起來非常簡單,兩個設定即可,請參考如下:

需求:只允許root與u1可以ssh login至本機

1. 建立user list:
# vi /etc/ssh/ssh_users
root
u1

2. 修改/etc/pam.d/sshd:
#%PAM-1.0
#auth       include      system-auth
auth       required     pam_listfile.so item=user sense=allow file=/etc/ssh/ssh_users onerr=fail
account    required     pam_nologin.so
account    include      system-auth
password   include      system-auth
session    optional     pam_keyinit.so force revoke
session    include      system-auth
session    required     pam_loginuid.so

立即生效~
* sense=allow 代表名列於/etc/ssh/ssh_users的user才可ssh login, 反過來說當sense=deny時代表ssh_users中的account不可ssh login。
*onerr=fail 代表當/etc/ssh/ssh_users無法開啟或是檔案不存在時,當作失敗,反之onerr=succeed代表不管能不能讀取到檔案都成功。

Monday, September 22, 2008

翻得真好~

最近常看三國演義, 並看到這句話: A good bird chooses (for himself) the tree upon which to perch, the talented subject chooses (for himself) the lord that he shall.

有人知道怎麼將它翻回原文嗎? 先賣個關子

Friday, September 19, 2008

讓Windows XP也有Mac or Linux-like multiple desktop

帽客的小萬螢幕不夠大, 往往開了一堆App後Windows的工具列就雜亂很難看, 然而這個情況改變了, 今天碰巧的發現到原來老M也出了類似Mac與Linux的多工桌面環境, 你可以至以下的MS官方網址抓取使用:

http://technet.microsoft.com/en-us/sysinternals/cc817881.aspx


謎之音: 小萬:[快把我改裝成Linux啦~~~~]
我: [先用Virtualbox撐一下吧~]

Thursday, September 18, 2008

Acer ASPIRE one BIOS update

New BIOS of Acer ASPIRE one (AOA110/AOA150) is available to download:
http://www.acer.com.tw/driver.asp

V.3304

Thursday, September 11, 2008

LDIF generate tools: OpenDS內附的"makeldif"

提供一個大量產生LDIF user entries的產生器:
https://www.opends.org/wiki/page/MakeLdif
Download site

執行makeldif前,系統必須安裝JRE的環境,所以請到Sun官網抓吧:
Sun JRE

安裝好JRE後, 就可以順利透過makeldif產生大量的資料了,預設是10K.

最後提供一套在Windows下查詢LDAP Server user entries的好工具, 一樣Windows也必須有JRE:
LDAP Browser/Editor

Note:
Tested on CentOS5.2

Friday, September 05, 2008

更新Acer Aspire one BIOS

上星期帽客到黃色小屋敗了一台小筆電 Acer Aspire one XP120G(金色的那款), 目前使用上沒有遇到太大的問題, 唯一的就是當LCD亮度調到比較暗時, LCD會閃爍不停 :(

這個問題還挺多人遇到的, 不過Acer已經有釋放出BIOS來解決這個問題了, 新BIOS的版本為3301, 但是此時我需要USB開機碟, 上google爬了爬文, 發現到BootFlashDOS這個製作USB開機碟的好東東, 簡單又快速 XD

製作好USB開機碟後於XP中重新開機Acer Aspire one, 並按下F12選擇用USB開機, 開完後執行3301.bat, 待重開機後, BIOS更新成功, LCD閃爍的問題似乎也得到了改善, 且讓我再觀察一陣子看看.

另外還有人抱怨Aspire one 無線訊號不良與底座不平這兩個主要問題, 我使用上的感覺是:
-無線訊號不良: 還ok 連公司的AP都算順暢, 不過只有用MAC filter,如果有跑加密呢? 呵~應該跟我的3com AP來連看看, anyway我很少用wireless所以這點對我問題不大

-底座不平: 這點到還好, 如果拔掉電池, 一點也沒有不平的感覺, 裝上電池呢? 這點容我再留意一下

Tuesday, September 02, 2008

永久掛載smbfs/cifs filesystem時 於/etc/fstab不顯示user info

以前帽客在/etc/fstab mount smb/cifs的遠端FileServer時, 總是壞習慣的把username與password寫在/etc/fstab中, 不太好也不建議, 所以目前改用以下的方法將username與password存入到別的檔案, 而在/etc/fstab中則指定去讀這個檔案以取得user的相關info, 整個fstab的格式改變如下:

-before:
//172.17.1.254/homes /mnt/smb cifs defaults,username=lawrence%redhat

-after:
//172.17.1.254/homes /mnt/smb cifs defaults,credentials=/root/creds

/root/creds 內容:
username=lawrence
password=redhat

* /root/creds 權限建議設定為400

Friday, August 29, 2008

queryperf: 測試DNS Server的效能/壓力工具

今天找到了一個對於DNS Server做stress test的好工具: queryperf,這個工具事實上內建於bind套件中,不過我的Centos5.2與OpenSUSE10是透過rpm安裝bind的,利用rpm -ql | grep -i queryperf卻找不到相關的檔案?於是乎我去抓了bind tarball檔,將queryperf compile起來,產生queryperf binary file就可以使用了。

使用的語法也不難主要如下:

./queryperf -d -s

-d 是讀取測試RR文檔的意思
-s 是指定所要測試的DNS Server

RR_document的格式也是很簡單的,請參考以下範例:
server1.example.com A -> query server1.example.com A Record
example.com MX -> query example.com domain mx Record
mail.example.com CNAME -> query mail.example.com CNAME
server1.example.com TXT -> query server1.example.com TXT Record
example.com TXT -> query example.com domain TXT Record
example.com NS -> query example.com domain NS Record
100.10.10.10.in-addr.arpa PTR -> query 10.10.10.100 PTR Record
101.10.10.10.in-addr.arpa PTR -> query 10.10.10.101 PTR Record

Note: ->是說明,不需要加入到RR_document

執行結果:
Statistics:

Parse input file: once
Ended due to: reaching end of file

Queries sent: 8 queries
Queries completed: 8 queries
Queries lost: 0 queries
Queries delayed(?): 0 queries

RTT max: 0.033874 sec
RTT min: 0.013128 sec
RTT average: 0.023992 sec
RTT std deviation: 0.007508 sec
RTT out of range: 0 queries

Percentage completed: 100.00%
Percentage lost: 0.00%

Started at: Mon Aug 25 03:33:47 2008
Finished at: Mon Aug 25 03:33:47 2008
Ran for: 0.034861 seconds

Queries per second: 229.482803 qps

緊接著來寫個簡單的script讓他不斷的執行queryperf吧!
#!/bin/bash
while true
do
./queryperf -d dnstest -s $1 -v
done

把DNS所有的RR都寫入RR_document,這麼一來,就可以來試看看你的DNS Server耐不耐操了 XD!

Friday, August 22, 2008

控管非Linux風格的file system的權限

現今Linux已經可以支援許多非Linux的檔案系統了,比如vfat,ntfs,hpfs,hfs等等,而預設上只有root可以對這些非Linux風格的檔案系統做新增與刪除的動作,其他一般user是不被允許的,或許有人覺得,還好吧!那我用chown硬上看看,但得到的結果會是.... Operation not permitted,非常遺憾呢~ 然而小弟不才今天發現到了可行的方案,在此提供給各位參考:

解決的方法非常簡單,用mount參數就可以解決了!
uid=lawrence ->代表此檔案系統中所有的檔案的使用者都是lawrence
gid=qa -> 代表此檔案系統中所有的檔案的群組都是qa
umask=027 -> 類似原本umask的功能,只不過不分檔案與目錄所有預設的權限都是777 (Linux filesystem 新增檔案時權限為666,目錄為777),所以此檔案系統的權限為750

整個mount指令下達: mount -t vfat -o uid=lawrence,gid=qa,umask=027 /dev/hdaX /mnt/msdos
(-t vfat可不輸入)

Thursday, August 21, 2008

Colasoft Packet Builder

帽客很少介紹在Windows上的軟體,不過我覺得從事網通業的各位朋友們如果使用了這套軟體,對於網路行為的除錯應該是有些幫助,Colasoft Packet Builder是一套在Windows作業系統上的免費軟體,透過它我們可以製造出想要的TCP, UDP, IP, ARP的封包,好用的是我發現到它還load一些capture packets的紀錄檔(sniffer/wireshark),修改過後再產生packets,感謝D-Link大大Dennis的介紹~

Colasoft Packet Builder

Friday, August 15, 2008

忽視fsck 當mount filesystem達到指定的數量

有使用Ubuntu的朋友們應該有發現到,有時開機時會顯示正在fsck filesystem,這時只能去泡杯茶等它檢查完畢了,當然這樣對於filesystem的完整性並避免磁碟的錯誤是有幫助的,但是有時帽客實在是不太想等Ubuntu的這個好意,所以我用以下的方法將它取消:

1.先使用dumpe2fs得到mount幾次後就會fsck filesystem:
lawrence@lawrence-x24:~$ sudo dumpe2fs /dev/sda3 | grep -i mount
dumpe2fs 1.40.8 (13-Mar-2008)
Last mounted on:
Default mount options: (none)
Last mount time: Fri Aug 15 09:03:55 2008
Mount count: 27
Maximum mount count: 35
得到目前mount 27次,並於第35次時會fsck filesystem。

2.使用tune2fs修改Maximum mount count為-1(永不fck):
lawrence@lawrence-x24:~$ sudo tune2fs -c -1 /dev/sda3
tune2fs 1.40.8 (13-Mar-2008)
Setting maximal mount count to -1
lawrence@lawrence-x24:~$ sudo dumpe2fs /dev/sda3 | grep -i mount
dumpe2fs 1.40.8 (13-Mar-2008)
Last mounted on:
Default mount options: (none)
Last mount time: Fri Aug 15 09:03:55 2008
Mount count: 27
Maximum mount count: -1

實際上還有個參數,當經過多久後,也會fsck filesystem:
lawrence@lawrence-x24:~$ sudo dumpe2fs /dev/sda3 | grep -i inter
dumpe2fs 1.40.8 (13-Mar-2008)
Check interval: 15552000 (6 months)

看來預設是6個月,恩這樣倒不錯。

Thursday, August 14, 2008

Process執行中止時便停止追蹤(tail -f)

tail -f 可以持續顯示新增的檔案內容,對於協助追蹤某些檔案的內容變化非常有幫助,但事實上如果process已經沒有繼續執行的時候,那麼意義可能不大,所幸還是有解決的方法,利用--pid= 就可以做到,以下是實際演練:

1. ping hinet苦命的DNS 168.95.1.1,並將結果redirect到/tmp/test
# ping 168.95.1.1 > /tmp/test &

2.利用tail持續追蹤/tmp/test,並輸入ping process的pid
# tail -f --pid=xxxx /tmp/test

3. 中止ping
# killall ping

此時應該會看到類似這樣的行為:
[root@server2 tmp]# ping 168.95.1.1 > /tmp/test &
[1] 11024
[root@server2 tmp]# tail -f --pid=11024 /tmp/test
64 bytes from 168.95.1.1: icmp_seq=1 ttl=239 time=52.6 ms
64 bytes from 168.95.1.1: icmp_seq=2 ttl=246 time=21.4 ms
64 bytes from 168.95.1.1: icmp_seq=3 ttl=246 time=19.9 ms
64 bytes from 168.95.1.1: icmp_seq=4 ttl=246 time=19.6 ms
64 bytes from 168.95.1.1: icmp_seq=5 ttl=246 time=18.4 ms
64 bytes from 168.95.1.1: icmp_seq=6 ttl=239 time=50.9 ms
64 bytes from 168.95.1.1: icmp_seq=7 ttl=246 time=17.6 ms
64 bytes from 168.95.1.1: icmp_seq=8 ttl=246 time=19.1 ms
64 bytes from 168.95.1.1: icmp_seq=9 ttl=239 time=51.4 ms
64 bytes from 168.95.1.1: icmp_seq=10 ttl=246 time=18.1 ms
64 bytes from 168.95.1.1: icmp_seq=11 ttl=239 time=52.3 ms
64 bytes from 168.95.1.1: icmp_seq=12 ttl=246 time=20.6 ms
64 bytes from 168.95.1.1: icmp_seq=13 ttl=246 time=18.9 ms
64 bytes from 168.95.1.1: icmp_seq=14 ttl=239 time=53.4 ms
64 bytes from 168.95.1.1: icmp_seq=15 ttl=246 time=18.6 ms
64 bytes from 168.95.1.1: icmp_seq=16 ttl=246 time=18.5 ms
64 bytes from 168.95.1.1: icmp_seq=17 ttl=246 time=18.9 ms
[1]+ Terminated ping 168.95.1.1 >/tmp/test ping被kill了所以也就停止追蹤了。

Wednesday, August 13, 2008

刪除當前目錄備份檔(*~)的方法

我想到的方法分別有三種如下:

1. find ./ -iname "*~" -exec rm {} \;
2. find ./ -iname "*~" | xargs rm
3. rm `find ./ -iname "*~"`

如果您有更好的方法,煩請告知囉~

Thursday, August 07, 2008

Howto mount disk image

如果你今天面對的是disk image而不是一般的partition image,當使用mount -o loop時會無法mount成功。這很容易理解,因為你必須知道disk image中partition的位置後才能mount起來,怎麼做呢?以下將會說明:

需求: mount test.img 並更改第一個partition中的某個檔案

我們先看看如果直接用mount -o loop會如何:
lawrence@lawrence-x24:~/Desktop$ sudo mount -o loop test.img /mnt/test/
mount: you must specify the filesystem type
lawrence@lawrence-x24:~/Desktop$ sudo mount -o loop -t ext3 test.img /mnt/test/
mount: wrong fs type, bad option, bad superblock on /dev/loop0,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so

恩,看起來是不work......

所以我必須先知道test.img的磁軌與磁區大小才能算出第一個partition的位置:
lawrence@lawrence-x24:~/Desktop$ fdisk -l test.img
You must set cylinders.
You can do this from the extra functions menu.

Disk test.img: 0 MB, 0 bytes
16 heads, 63 sectors/track, 0 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Disk identifier: 0x00000000

所用裝置 Boot Start End Blocks Id System
test.img1 1 32 16096+ 83 Linux

得知每個 track 共 63 sectors, 每個 sector 是 512bytes,故得知第一個partition是在63*512=32256

接下來利用losetup將第一個partition先掛到/dev/loop0,並驗證:
lawrence@lawrence-x24:~/Desktop$ sudo losetup --offset 32256 /dev/loop0 test.img
lawrence@lawrence-x24:~/Desktop$ sudo losetup /dev/loop0
/dev/loop0: [0803]:865823 (test.img), offset 32256

好了,將它mount起來吧!
lawrence@lawrence-x24:~/Desktop$ sudo mount /dev/loop0 /mnt/test/
lawrence@lawrence-x24:~/Desktop$ df -h | grep test
/dev/loop0 16M 7.9M 6.6M 55% /mnt/test

修改完畢後,一樣將他umount掉並detach /dev/loop0
lawrence@lawrence-x24:/mnt/test$ cd
lawrence@lawrence-x24:~$ sudo umount /mnt/test
lawrence@lawrence-x24:~$ df -h | grep test
lawrence@lawrence-x24:~$ sudo losetup -d /dev/loop0
lawrence@lawrence-x24:~$ sudo losetup /dev/loop0
loop: can't get info on device /dev/loop0: 沒有此一裝置或位址

以上希望對大家有幫助。

PS. Redhat中如果要位移,是下達losetup -o 32256而不是losetup --offset 32256

Friday, August 01, 2008

線上學習Linux

發現到一個線上學習Linux的好地方,文章非常豐富,英文用詞也不會太難,且也提供html與PDF的下載,真是滿不錯的,非常感謝這些無私奉獻的人。

http://learnlinux.tsf.org.za/index.html

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)

Thursday, April 10, 2008

IP alias

在Linux實現IP alias,一般來說大家第一個想到的方法是使用ifconfig,但其實用ifconfig來做IP alias,當要查看IP address時,會dump出一大堆IP alias的介面(ethN:N),不太容易閱讀(最近的測試在網卡上bind 16384個IP),所幸可以使用ip指令來做IP alias,簡單又方便閱讀。
怎麼做呢?非常簡單,只要下達以下指令就好了:
# ip addr add 192.168.1.102/24 dev ethN (N代表0,1,2,.... i.e.網卡編號)

查看:
# ip addr show


192.168.1.102與192.168.1.103是IP alias,如果使用ifconfig來做的話,那麼將會多出兩個ethN:N。提醒一下如果是以ip指令來做IP alias時,使用ifconfig是查看不到IP alias的IP address.

Thursday, March 27, 2008

Check Linux distribution

以往帽客都是去cat /etc/issue這個檔案來查看是那個Linux的版本,但事實上這個檔案是可被修改的。今天找到了一個能100%確認是那一套Linux distribution的指令了,lsb_release,以下列出了cat /etc/issue與lsb_release去確認Linux distribution的結果:

1. cat /etc/issue
[root@server2 tmp]# cat /etc/issue
CentOS release 5 (Final)
Kernel \r on an \m

2. lsb_release
[root@server2 tmp]# lsb_release -a
LSB Version: :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch
Distributor ID: CentOS
Description: CentOS release 5 (Final)
Release: 5
Codename: Final

Tuesday, March 18, 2008

selinux on RHEL5.1

今天在RHEL5.1中,將selinux enable起來,在此分享一下心得:

1. Enable selinux:
[root@dns html]# vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - SELinux is fully disabled.
SELINUX=enforcing
# SELINUXTYPE= type of policy in use. Possible values are:
# targeted - Only targeted network daemons are protected.
# strict - Full SELinux protection.
SELINUXTYPE=targeted
-> 將SELINUX=disabled改成SELINUX=enforcing,並重新開機。

2.查看目前selinux的狀態:
[root@dns html]# sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: enforcing
Policy version: 21
Policy from config file: targeted
如果要查詢到更多的資訊,可加上 -v參數:
[root@dns html]# sestatus -v
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: enforcing
Policy version: 21
Policy from config file: targeted

Process contexts:
Current context: root:system_r:unconfined_t:SystemLow-SystemHigh
Init context: system_u:system_r:init_t
/sbin/mingetty system_u:system_r:getty_t
/usr/sbin/sshd system_u:system_r:unconfined_t:SystemLow-SystemHigh

File contexts:
Controlling term: root:object_r:devpts_t
/etc/passwd system_u:object_r:etc_t
/etc/shadow system_u:object_r:shadow_t
/bin/bash system_u:object_r:shell_exec_t
/bin/login system_u:object_r:login_exec_t
/bin/sh system_u:object_r:bin_t -> system_u:object_r:shell_exec_t
/sbin/agetty system_u:object_r:getty_exec_t
/sbin/init system_u:object_r:init_exec_t
/sbin/mingetty system_u:object_r:getty_exec_t
/usr/sbin/sshd system_u:object_r:sshd_exec_t
/lib/libc.so.6 system_u:object_r:lib_t -> system_u:object_r:lib_t
/lib/ld-linux.so.2 system_u:object_r:lib_t -> system_u:object_r:ld_so_t

3.查看selinux對daemon的booleans,以查尋httpd為例:
[root@dns html]# getsebool -a | grep httpd
allow_httpd_anon_write --> off
allow_httpd_mod_auth_pam --> off
allow_httpd_sys_script_anon_write --> off
httpd_builtin_scripting --> on
httpd_can_network_connect --> off
httpd_can_network_connect_db --> off
httpd_can_network_relay --> off
httpd_disable_trans --> off
httpd_enable_cgi --> on
httpd_enable_ftp_server --> off
httpd_enable_homedirs --> on
httpd_rotatelogs_disable_trans --> off
httpd_ssi_exec --> off
httpd_suexec_disable_trans --> off
httpd_tty_comm --> off
httpd_unified --> on

如果要設定booleans,可利用setsebool,比如說當我不想要selinux控管httpd時,可以這樣做:
[root@dns html]# setsebool -P httpd_disable_trans 1
[root@dns html]# getsebool -a | grep httpd_disable_trans
httpd_disable_trans --> on
其中0代表off,1代表on,而-P的參數是代表下次開機時套用新的boolean值。

現在來個狀況練習一下,在selinux enable的狀況下,允許匿名的ftp account可以get與put file,並且可以overwrite。

1. 設定vsftpd(請參考以下的configure):
[root@dns html]# cat /etc/vsftpd/vsftpd.conf | grep -v "^$" | grep -v "^#"
anonymous_enable=YES
anon_other_write_enable=YES
local_enable=YES
write_enable=YES
local_umask=022
anon_upload_enable=YES
anon_mkdir_write_enable=YES
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES

在以往沒有開啟selinux時,已經達成了題目需求,但當selinux開啟時,是會踢到鐵板的,看一下以下的示範吧:
chiu-lawrencede-ibook-g4:~ Lawrence$ ftp 10.5.30.147
Connected to 10.5.30.147.
220 (vsFTPd 2.0.5)
Name (10.5.30.147:Lawrence): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd pub
250 Directory successfully changed.
ftp> put backup.sh
local: backup.sh remote: backup.sh
229 Entering Extended Passive Mode (|||50891|)
553 Could not create file.
ftp>

查看一下ftp的booleans:
[root@dns pub]# getsebool -a | grep ftp
allow_ftpd_anon_write --> off
allow_ftpd_full_access --> off
allow_ftpd_use_cifs --> off
allow_ftpd_use_nfs --> off
ftp_home_dir --> off
ftpd_disable_trans --> off
ftpd_is_daemon --> on
httpd_enable_ftp_server --> off
tftpd_disable_trans --> off
看到了嗎?allow_ftpd_anon_write --> off與allow_ftpd_full_access --> off,來enable它們吧!
[root@dns pub]# setsebool -P allow_ftpd_anon_write 1
[root@dns pub]# setsebool -P allow_ftpd_full_access 1

再試一次put檔案:
chiu-lawrencede-ibook-g4:~ Lawrence$ ftp 10.5.30.147
Connected to 10.5.30.147.
220 (vsFTPd 2.0.5)
Name (10.5.30.147:Lawrence): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd pub
250 Directory successfully changed.
ftp> put backup.sh
local: backup.sh remote: backup.sh
229 Entering Extended Passive Mode (|||50580|)
150 Ok to send data.
100% |***********************************************************************************| 666 1.92 MB/s 00:00
226 File receive OK.
666 bytes sent in 00:00 (1.62 KB/s)
ftp> put backup.sh
local: backup.sh remote: backup.sh
229 Entering Extended Passive Mode (|||37711|)
150 Ok to send data.
100% |***********************************************************************************| 666 2.76 MB/s 00:00
226 File receive OK.
666 bytes sent in 00:00 (2.92 KB/s)
ftp>

完成。

Thursday, March 13, 2008

RHEL5 群組管理員

這是以前沒有的觀念,故在此做個筆記:

Objective: 讓一般user可以控管(新增/刪除)群組的成員

Environment:
law -> g1 group的群組管理員
g1 -> 測試用的group
alex -> 將被law assign到g1 group
/home/g1 -> g1 group的共用目錄,權限為770

Setup1. 將law設定為g1群組管理員:
[root@server3 home]# gpasswd -A law g1
[root@server3 home]# grep law /etc/gshadow
law:!::
g1:!:law:
(可在/etc/gshadow中,每個群組的第三個欄位查詢群組管理員

Setup2. 將alex加讓到g1 group:
[law@server3 ~]$ id alex
uid=502(alex) gid=503(alex) groups=503(alex)
[law@server3 ~]$ gpasswd -a alex g1
Adding user alex to group g1
[law@server3 ~]$ id alex
uid=502(alex) gid=503(alex) groups=503(alex),502(g1)

Setup3. 驗證一下alex可至/home/g1 建立檔案:
[alex@server3 home]$ ls -dl /home/g1/
drwxrwx--- 2 root g1 4096 Oct 21 05:06 /home/g1/
[alex@server3 home]$ cd g1
[alex@server3 g1]$ touch alex
[alex@server3 g1]$ ls -l alex
-rw-rw-r-- 1 alex alex 0 Oct 21 05:13 alex

Friday, March 07, 2008

RHEL5 系統管理寶典 基礎篇

最近獲贈永昇兄(Cd Chen)的近期新作"RHEL5 系統管理寶典 基礎篇",在此非常感謝永昇兄,這本新書算是永昇兄對於Redhat Linux系統管理介紹的第二版,因為撰寫第一版時有些原因,故以Fedora來介紹,難免有些遺憾,如今這本新作完全是以RHEL5來介紹,內容與前版相比也更新了許多,是非常值得有心學習Linux系統管理的讀者可參考的一本書物,如果有上過RHCE培訓課程的學生,這本書就等於是RH133的中文參考書,帽客當然不是在打廣告,而是好東西一定要推薦給大家知道,帽客這幾天也開始拜讀這本書了,雖然大部份的知識都知道,但真正的了解應該是: 懂->很懂->精通->分享&教導,所以帽客每次看不同的Linux書物時,都會有不同的收穫。

Friday, February 15, 2008

Linux存取Windows網芳

今天使用Linux machine去mount Windows網芳所分享出來的目錄時,發生了以下的錯誤:
# smbclient //X.X.X.X/temp -U lawrence
Password:
session setup failed: NT_STATUS_LOGON_FAILURE

怪了,帳號跟密碼都正確呀!看看能不能瀏覽,於是乎執行以下的command:
[root@server2 ~]# smbclient -L //X.X.X.X -N
Anonymous login successful
Domain=[XXXXX] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]

Sharename Type Comment
--------- ---- -------
cli_rpc_pipe_open: cli_nt_create failed on pipe \srvsvc to machine X.X.X.X. Error was NT_STATUS_ACCESS_DENIED
Error returning browse list: NT_STATUS_ACCESS_DENIED
session request to X.X.X.X failed (Called name not present)
session request to 10 failed (Called name not present)
Anonymous login successful
Domain=[XXXXX] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]

想了一下,會不會是Windows domain的問題,所以查了一下smbclient的man page,找到了以下的提示:
-W|--workgroup=domain
Set the SMB domain of the username. This overrides the default domain which is the domain defined in smb.conf. If the domain specified is the same as the servers NetBIOS name, it causes the client to log on using the servers local SAM (as opposed to the Domain SAM).

恩,在執行一次看看,這次加入了--workgroup的參數:
[root@server2 ~]# smbclient //X.X.X.X/temp -U lawrence --workgroup=XXXXX
Password:
Domain=[XXXXX] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]
smb: \>

成功了!

Monday, January 28, 2008

X window重點條列

最近加強了關於X window的觀念,整理出重點如下:

- 目前的X window是由X11R6延伸發展而來
- 兩大分支: Xfree86, xorg
- X window = X Server + X Client + window manager (twm, KDE, GNOME and etcs)
- X Server: 負責將X Client的運算結果顯示於screen
- X Client: 負責處理X Server傳回的資訊,並回傳給X Server,不care X Server是用那張顯卡,那個作業系統
- Check X version: 以root身份執行 X -version

- X Server 主要設定檔, 適用於xfree86 & xorg:
/etc/X11/xorg.conf, /etc/X11/XF86Config
主要參數說明:
InputDevice -> 設定輸出入裝置: 如鍵盤 or 滑鼠
Device -> 設定顯卡為那張?驅動程式為?
Screen ->設定色度與解析度
Files -> 設定X font, 設定的方法有直接指定路徑 or 透過xfs (X font Server)
Monitor -> 設定screen的水平與垂直度頻率
Module -> 載入相關的模組
ServerLayout -> 以上所有參數都可有許多筆,至於用到那一筆則是在這邊決定

- 在runlevel 3啟動X的流程:
startx->xinit-> ~/.xinitrc -> /etc/X11/xinit/xinitrc -> ~/.xserverrc -> /etc/X11/xinit/xserverrc
- 如果是runlevel5的話,可以在/etc/inittab看到啟動display manager:
# Run xdm in runlevel 5
x:5:respawn:/etc/X11/prefdm -nodaemon

- 設定window manager的設定檔:
/etc/sysconfig/desktop
KDE -> startkde
GNOME -> gnome-session

-X v7.x的字型目錄:
/usr/share/fonts/
/usr/share/X11/fonts

-X v6.x的字型目錄:
/usr/X11R6/lib/X11/fonts/

-X預設在tty7,也就是ALT+CTRL+F7,執行的程式方法是 X :0,預設port是TCP 6000,如果是X :1,那麼就是tty8,i.e. ALT+CTRL+F8,TCP port 6001

-如果是用xfs管理字型的話,請確認執行X時,要先啟動xfs,否則將無法啟動X


Thursday, January 17, 2008

MacBook Air

Apple終於announce輕機種的NB了,重量僅1.36kg,這才是我想要的!
且觸碰板還支援多點觸碰!真是創意無限!
更詳細的spec: MacBook Air Specs
Demo影片: MackBook Air Guided