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

Tuesday, December 25, 2007

DNS: forward Zone

這算是一個蠻特別的需求,只有針對特定的domain時,才會將DNS query轉送到特定的DNS Server,不過似乎挺多單位常有這樣的需求,所以還是趕緊給它記下來吧:
zone "test.com"
{
type forward;
forwarders { 192.168.0.254; 192.168.0.253; };
};

就是這麼簡單囉,凡是看到test.com的DNS查詢時便forward到192.168.0.254與192.168.0.253這兩台DNS Server。

Fix NFS ports

NFS Server有一個特性,那就是除了portmapper與nfs分別是使用固定的port number外(portmapper:111,nfs:2049),其它的port都是隨機產生的,如下所示:
[root@server3 ~]# rpcinfo -p
program vers proto port
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100011 1 udp 745 rquotad
100011 2 udp 745 rquotad
100011 1 tcp 748 rquotad
100011 2 tcp 748 rquotad
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100021 1 udp 1028 nlockmgr
100021 3 udp 1028 nlockmgr
100021 4 udp 1028 nlockmgr
100021 1 tcp 3767 nlockmgr
100021 3 tcp 3767 nlockmgr
100021 4 tcp 3767 nlockmgr
100005 1 udp 760 mountd
100005 1 tcp 763 mountd
100005 2 udp 760 mountd
100005 2 tcp 763 mountd
100005 3 udp 760 mountd
100005 3 tcp 763 mountd
100024 1 udp 832 status
100024 1 tcp 835 status
[root@server3 ~]# service nfs restart; service nfslock restart
Shutting down NFS mountd: [ OK ]
Shutting down NFS daemon: [ OK ]
Shutting down NFS quotas: [ OK ]
Shutting down NFS services: [ OK ]
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS daemon: [ OK ]
Starting NFS mountd: [ OK ]
Stopping NFS locking: [ OK ]
Stopping NFS statd: [ OK ]
Starting NFS statd: [ OK ]
[root@server3 ~]# rpcinfo -p
program vers proto port
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100011 1 udp 904 rquotad
100011 2 udp 904 rquotad
100011 1 tcp 907 rquotad
100011 2 tcp 907 rquotad
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100021 1 udp 1028 nlockmgr
100021 3 udp 1028 nlockmgr
100021 4 udp 1028 nlockmgr
100021 1 tcp 2229 nlockmgr
100021 3 tcp 2229 nlockmgr
100021 4 tcp 2229 nlockmgr
100005 1 udp 919 mountd
100005 1 tcp 922 mountd
100005 2 udp 919 mountd
100005 2 tcp 922 mountd
100005 3 udp 919 mountd
100005 3 tcp 922 mountd
100024 1 udp 971 status
100024 1 tcp 974 status

如果要利用iptables加以控管實在是有些困難之處,所以我們可以做的是將這些daemon指定使用固定的port number,以下的步驟將告訴你怎麼做到這一點:

Linux distro: CentOS 5.0

1. 修改/etc/sysconfig/nfs檔案中的參數如下:
RQUOTAD_PORT=9000
LOCKD_TCPPORT=9001
LOCKD_UDPPORT=9001
MOUNTD_PORT=9002
STATD_PORT=9003

2. 重啟nfs與nfslock daemon,並驗證:
[root@server3 ~]# service nfs restart; service nfslock restart
Shutting down NFS mountd: [ OK ]
Shutting down NFS daemon: [ OK ]
Shutting down NFS quotas: [ OK ]
Shutting down NFS services: [ OK ]
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS daemon: [ OK ]
Starting NFS mountd: [ OK ]
Stopping NFS locking: [ OK ]
Stopping NFS statd: [ OK ]
Starting NFS statd: [ OK ]
[root@server3 ~]# rpcinfo -p
program vers proto port
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100011 1 udp 9000 rquotad
100011 2 udp 9000 rquotad
100011 1 tcp 9000 rquotad
100011 2 tcp 9000 rquotad
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100021 1 udp 9001 nlockmgr
100021 3 udp 9001 nlockmgr
100021 4 udp 9001 nlockmgr
100021 1 tcp 9001 nlockmgr
100021 3 tcp 9001 nlockmgr
100021 4 tcp 9001 nlockmgr
100005 1 udp 9002 mountd
100005 1 tcp 9002 mountd
100005 2 udp 9002 mountd
100005 2 tcp 9002 mountd
100005 3 udp 9002 mountd
100005 3 tcp 9002 mountd
100024 1 udp 9003 status
100024 1 tcp 9003 status

如此便完成了固定NFS Server的port number。

Thursday, December 13, 2007

Linux command: screen 應用小技巧

上一篇介紹了screen的基本用法,這一篇呢,就來分享一下screen更進階的一種實用方法。
假使您所要維護的Linux機器有好幾台,每一天都要logon進去關心一下,或是操作一番,每次都要ssh過去的確是有點麻煩,搞不好一天中還要ssh進去好幾次,不太smart。

所以用screen來偷懶吧!用screen所產生的console就算你退出了screen,還是可以保留當時的使用狀況,所以我只需要把screen叫出來用就好了。好處就是快速且又保留當時操作的情境。

假想今天的Server有2台,您每天都要進去關心一下,那麼您可以寫一個script如下:

#!/bin/bash
screen -d -m -S SRV1 -t root@srv1 ssh root@192.168.0.254
screen -d -m -S SRV2 -t root@srv2 ssh root@192.168.0.253

講解一下參數:
-d -m -> 不要去attach這個screen
-S -> 設定screen name,用screen -ls時可以查看,到時可以用screen -r叫回來,有點像這個樣子:
#screen -ls
There are screens on:
555.svr1 (Detached)
560.svr2 (Detached)
# screen -r 555
-> 這樣就會回到Server1
-t -> 設定screen的title,在screen中按下CTRL+a,w時,好方便查詢。

這樣一來呢,當我想到Server1時就執行screen -ls查一下並用screen -r 555切到Server1,夠方便吧!當然你可以讓這隻script在開機時便執行,並搭配SSH免密碼登入。

Thursday, December 06, 2007

Linux command: screen

screen是可遠端登入Linux建立多重終端機的一個非常好用的指令,比如你習慣用putty透過SSH登入到遠端的Linux機器,同時想開啟多個終端機時,怎麼辦呢?這時screen就派上用場了,另一個好處是在screen下所執行的命令,即使你登出了還是會繼續執行,不需另外透過nohup,以下整理一下screen常用到的一些功能。

1. 執行screen: #screen

2. screen熱鍵:
2.1 新增screen: CTRL+a,c
2.2 切換至下個screen: CTRL+a,n
2.3 切換至前一個screen: CTRL+a,a
2.4 查看目前有幾個screen: CTRL+a,w
2.5 離開screen: CTRL+a,d
2.6 刪除screen: #exit or CTRL+a,k

3. 查看目前screen status: #screen -ls
4. 回到screen: #screen -r

Wednesday, November 21, 2007

FUSE+SSHFS

在Linux中要去mount遠端的Server某個分享資料夾,大部份是透過NFS或是Samba的方法來實做,在此帽客提供另一種方法來做,那便是利用SSH來mount。

OS: CentOS5 kernel version: 2.6.18-8.1.14.el5

透過sshfs便可以達到這樣的需求,但由於使用sshfs之前,必需安裝FUSE module,所以請先至rpm.pbone.net抓取以下的RPM並安裝:
fuse-2.7.0-1.el5.rf.i386.rpm
fuse-devel-2.7.0-3_7.el5.i386.rpm
fuse-kmdl-2.6.18-8.1.14.el5-2.7.0-3_7.el5.i686.rpm
fuse-libs-2.7.0-3_7.el5.i386.rpm

在抓取fuse-sshfs-1.8-1.el5.rf.i386.rpm安裝完後將機器重新開機或是執行modprove fuse

由於sshfs在mount遠端時都會要求輸入密碼,如同使用ssh一樣,所以我利用了免密碼就可登入到對方主機來做。(在此server2代表client要mount server1的root家目錄)

server2: 產生金鑰並scp到server1
[root@server2 ~]# ssh-keygen -t dsa
Generating public/private dsa key pair.

Enter file in which to save the key (/root/.ssh/id_dsa): Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
97:49:77:78:b0:82:13:59:fa:0b:70:ad:cd:7d:31:f1 root@server2.example.com
[root@server2 ~]# scp .ssh/id_dsa.pub root@10.4.1.33:~/server2.key.pub
Password:
id_dsa.pub
100% 614 0.6KB/s 00:00
server1: 將server2的金鑰copy到~/.ssh/authorized_keys
server1:~/.ssh # touch authorized_keys
server1:~/.ssh # cat ../server2.key.pub > authorized_keys

server2: 使用sshfs mount server1的root家目錄至/mnt/server1
[root@server2 ~]# sshfs root@10.4.1.33:/root /mnt/server1/
[root@server2 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda5 13G 3.6G 8.8G 29% /
/dev/hda1 99M 14M 80M 15% /boot
tmpfs 506M 0 506M 0% /dev/shm
/dev/hda2 4.8G 138M 4.4G 4% /home
sshfs#root@10.4.1.33:/root
1000G 0 1000G 0% /mnt/server1

完成。

Monday, November 19, 2007

[Vsftp] Allow anonymous rewrite files

今天發現到在RHEL/SLES的vsftp中,即使我開放讓anonymous有上傳與建立目錄的權限,但當要上傳並覆蓋原本的檔案時會發生權限不足的問題,原來還要多加一個設定anon_other_write_enable=YES
在此總結允許anonymous所有權限的參數:

anonymous_enable=YES
anon_other_write_enable=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES
write_enable=YES