Tuesday, August 26, 2008

ClamAV Antivirus และ Samba



Error จาก /var/log/message เมื่อมีการเปิดใช้ไฟล์จาก windows

smbd_vscan_clamav[290099]: ERROR : file /home/tawich/Policy/Poledit.exe not found,
not readable or an error occured
ERROR : daemon failed with a minor error - access to file Policy/poledit.exe denied

ความหมายคือ โปรแกรม clamd สิทธิ์ไม่ถึงที่จะตรวจสอบไฟล์นั้นได้ รู้ได้ยังไงเหรอ ลองตรวจสอบสถานะ process
ด้วยคำสั่ง ps -aux | grep clamd จะเห็นว่า daemon clamd รันด้วย user clamav อยู่ ถ้าหากเปลี่ยนสถานะ
เป็น root คงจะแก้ปัญหานี้ได้ ทีนี้ลองมาแก้ดูตามที่สันนิษฐานกันต่อ

1. แก้ไขไฟล์ /etc/clamav/clamd.conf เพื่อกำหนดให้ clamd รันเป็น root

#Run as another user
User root

2. save file แล้วรัน clamd อีกครั้งตรวจสอบสถานะว่ารันเป็น root แล้วหรือไม่ดู

เมื่อทุกอย่าง OK แล้วคราวนี้เปิดไฟล์ตามปกติใน windows และทดสอบเปิดไฟล์ที่ติดไวรัส พบว่ามีการกำจัดไวรัสให้
แล้ว

clamav samba


Resources:

ManPage clamd.conf (5) : -> http://linux.die.net/man/5/clamd.conf
Clam Antivirus: Installation -> http://www.proscrutiny.com/howtos/clamav-qmail-ldap.html

มี package rpm สำหรับ Mandriva ที่นี่

Monday, August 25, 2008

Vtfp with CentOS

วันนี้ต้อง upgrade firmware ของอุปกรณ์ thin client โดยผ่าน ftp ด้วยความกรุณาของช่าง
แนะนำให้เราสร้าง ftp server บน windows 2003 ไอ้ความที่เราไม่ค่อยถนัดนักในเรื่องของ window
จึงได้ทำบน linux ของเราดีกว่า เสร็จแล้วค่อยโทรไปหาฝ่าย support ของ thin client อีกครั้ง

VNC server with CentOS 4 ว่าด้วยการ config

สวัสดีครับพี่น้อง ผมได้อ่านและทำตามการติดตั้ง vncserver ด้วย CentOS 4.6 ของบทความนี้ และใช้งานได้
จึงเห็นสมควรอนุรักษ์ไว้ จึง copy มาทั้งดุ้นแบบนี้ เชิญท่านทัศนาได้แล้ว ณ บัดนี้


Contents

1. Installing the required packages
2. Configuring un-encrypted VNC
1. Create your VNC users
2. Set your users' VNC passwords
3. Edit the server configuration
4. Create xstartup scripts
5. Test each VNC user
1. Testing with a java enabled browser
2. Testing with a vnc client
3. Starting vncserver at boot
3. VNC encrypted through an ssh tunnel
4. Recovery from a logout
5. VNC-Sever setup with no hassles with vnc-ltsp-config
6. VNC-Server for an already logged in GUI console session

VNC is used to display an X windows session running on another computer. Unlike a remote X connection, the xserver is running on the remote computer, not on your local workstation. Your workstation ( Linux or Windows ) is only displaying a copy of the display ( real or virtual ) that is running on the remote machine.

There are several ways to configure the vnc server. This HOWTO shows you how to configure VNC using the 'vncserver' service as supplied by CentOS.

1. Installing the required packages

The server package is called 'vnc-server'. Run the command rpm -q vnc-server.

The result will be either package vnc-server is not installed or something like vnc-server-4.0-11.el4.

If the server is not installed, install it with the command: yum install vnc-server.

The client program is 'vnc'. You can use the command yum install vnc to install the client if rpm -q vnc shows that it is not already installed.

Make sure to install a window manager in order to get a normal GUI desktop. You can use the command yum groupinstall "GNOME Desktop Environment" to install the Gnome Desktop and requirements, for example. Other popular desktop environments are "KDE" and "XFCE-4.4". XFCE is more light-weight than Gnome or KDE and available from the "extras" repository.

ตรงนี้หากเราติดตั้ง CentOS และเลือก Xwindows พร้อมกับ KDE หรือ Gnome แล้วตั้งแต่แรกก็สามารถข้ามไปได้ อนึ่ง
ในลินุกซ์การติดตั้ง package เป็นขบวนแบบนี้ภายหลังยุ่งยากมาก เพราะไฟล์ที่ต้องการและขึ้นต่อกันมีเยอะเกินไป
จึงควรทำเสียให้เสร็จตั้งแต่ตอนแรกแล้ว....

2. Configuring un-encrypted VNC

We will be setting up VNC for 3 users. These will be 'larry', 'moe', and 'curly'.

You will perform the following steps to configure your VNC server:

1. Create your VNC users.
2. Set your users' VNC passwords.
3. Edit the server configuration.
4. Create xstartup scripts.
5. Test each VNC user.

2.1. Create your VNC users หรือ นัยหนึ่่งคือสร้าง user ในลินุกซ์ หากมี user อยู่แล้วให้ข้ามไปขั้นตอน
สร้าง password เลย

As root:

# useradd larry
# useradd moe
# useradd curly
# passwd larry
# passwd moe
# passwd curly

2.2. Set your users' VNC passwords

Login to each user, and run vncpasswd. This will create a .vnc directory. ให้ login
ด้วย user แต่ละคนก่อนในแต่ละคนนั้นให้สร้างพาสเวิร์ดด้วยคำสั่ง vncpasswd ซึ่งจะมีการสร้างไดเรกทอรี .vnc
ขึ้นในนั้นประกอบด้วยไฟล์ passwd ขึ้นมา

[~]$ cd .vnc
[.vnc]$ ls
passwd

2.3. Edit the server configuration
# เสร็จแล้วให้แก้ไขไฟล์ vncservers ใน /etc/sysconfig ด้วยการเพิ่มเข้าไปอีก 4 บรรทัด คงพอเดาได้หล่ะนะ
ว่าคืออะไร

Edit /etc/sysconfig/vncservers, and add the following to the end of the file.

VNCSERVERS="1:larry 2:moe 3:curly" # กำหนดว่าให้ใช้ได้ 3 คน
VNCSERVERARGS[1]="-geometry 640x480" # คนที่ 1 ได้รายละเอียดของภาพที่ 640x480
VNCSERVERARGS[2]="-geometry 640x480" # คนที่ 2 ได้รายละเอียดของภาพที่ 640x480
VNCSERVERARGS[1]="-geometry 800x600" # คนที่ 3 ได้รายละเอียดของภาพที่ 800x600

Larry will have a 640 by 480 screen, as will moe. Curly will have an 800 by 600 screen.

2.4. Create xstartup scripts # จะเป็นการสร้างไฟล์ xstartup ที่จะใช้รันเมื่อมีการ connect เข้ามา
จาก vncviewer ต่าง ๆ ไฟล์นี้จะถูกสร้างในไดเรกทอรี .vnc ของ user ทั้งสามคนที่กำหนดไว้ข้างต้น ไฟล์นี้
ให้สร้างด้วย scrip โดยรัน vncserver service จะสร้างให้โดยอัตโนมัติ ตามขั้นตอนสามบรรทัดถัดจากนี้ไป

We will create the xstartup scripts by starting and stopping the vncserver as root.

# service vncserver start
# service vncserver stop

Login to each user and edit the xstartup script. To use Larry as an example, first login as larry.

[~]$ cd .vnc
[.vnc] ls
mymachine.localnet:1.log passwd xstartup

Edit xstartup. Add the line indicated here, and uncomment the two lines as directed.
=============== อันนี้เป็นค่า default ที่สร้างจาก vncserver service เลย ===============
#!/bin/sh (-)
# Add the following line to ensure you always have an xterm available.
( while true ; do xterm ; done ) &
# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER # ให้เอา # ออก
exec /etc/X11/xinit/xinitrc # ให้เอา # ออก
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &

# ค่าสุดท้ายนี้หากต้องการ รัน gnome แก้เป็น exec gnome-session
หากต้องการรัน kde แก้เป็น startkde ของผมใช้ kde จึงเป็น startkde &

2.5. Test each VNC user ทดสอบดูว่าแต่ละคนจะใช้ vncserver ที่ port ต่างกันตามลำดับ

ก่อนจะทดสอบ ให้รัน vncserver เสียก่อน ด้วยคำสั่ง #service vncserver start
เห็น vncserver โชว์หรือเปล่าพร้อมสำหรับ 3 คนแล้ว

2.5.1. Testing with a java enabled browser

Let us assume that mymachine has an IP address of 192.168.0.10. The URL to connect to each of the users will be:

Larry is http://192.168.0.10:5801
Moe is http://192.168.0.10:5802
Curly is http://192.168.0.10:5803

Connect to http://192.168.0.10:5801. A java applet window will pop-up showing a conection to your machine at port 1. Click the [ok] button. Enter larry's VNC password, and a 640x480 window should open using larry's default window manager.

2.5.2. Testing with a vnc client

For Larry: vncviewer 192.168.0.10:1
For Moe: vncviewer 192.168.0.10:2
For Curly: vncviewer 192.168.0.10:3

To test larry using vncviewer, vncviewer 192.168.0.10:1. Enter Larry's VNC password, and a 640x480 window sholud open using Larry's default window manager.

เมื่อ vncserver รันได้แล้ว และพร้อมสำหรับการคอนเนกแล้ว ก็ให้รัน vncserver ทุกครั้งที่ boot ซะ
2.5.3. Starting vncserver at boot

To start vncserver at boot, enter the command chkconfig vncserver on.

# chkconfig --level 35 vncserver on


=========== ต่อไปของ howto นี้เป็นการ config VNC ในแบบ encrypted โดยผ่าน ssh tunnel ก็หาอ่านต่อได้จากลิงค์ต้นฉบับครับ ===========================

ต้นฉบับลอกมาจาก: http://wiki.centos.org/HowTos/VNC-Server
TightVNC

Setup VNC Server on Linux

Run VNCserver on CentOS

Short notes on how to run VNCserver under CentOS 5

1. install the app
#> sudo yum install vnc-server

2. create a password file
#> vncpasswd password

3. edit vnc config file
#> sudo vi /etc/sysconfig/vncserver
VNCSERVERS="1:yourusername"
- uncomment this if you want to force VNC connections only via SSH tunnel
#VNCSERVERARGS[1]="-geometry 800×600 -nolisten tcp -nohttpd -localhost"

4. start vncserver
#> sudo service vncserver start

Tweaks : what ever vnc start for you is in $HOME/.vnc/xstartup,uncomment the following two lines to have your default desktop
#unset SESSION_MANAGER # exec /etc/X11/xinit/xinitrc

Sorce: http://www.101tech.net/wordpress/2007/07/20/run-vncserver-on-centos/

Thursday, August 14, 2008

Samba Video tutorial

วันนี้ท่องเน็ตอยู่ ๆ ก็เจอวีดีโอช่วยสอนการใช้และการ setup Samba server ที่ดีๆเข้า จึงได้ดาวน์โหลดมาศึกษา
เนื้อหาง่ายดี ยังไม่เข้าขั้น advance เท่าไหร admin มือเก๋า ข้ามไปได้ ส่วนผู้ใช้งานมื่อใหม่อย่างเรา น่าสนใจทีเดียว

ในวิดีโอ 1 สอนให้ใช้ linux เข้าถึงแชร์ไฟล์ใน windows โดยเรียกไฟล์จาก windows ผ่าน msclient ได้โชว์
คำสั่งต่าง ๆ ให้เห็นเป็นบุญ ดังนี้

rpm -qa | grep smb
rpm -ql | grep samba

ผลของคำสั่งแสดงให้เห็นว่ามีการติดตั้ง package samba เวอร์ชั่นอะไรลงไป



คำสั่ง smbclient -L winxp -U administrator
ตามด้วยพร้อมสำหรับใส่พาสเวิร์ด

เป็นคำสั่งให้มองเห็นว่าในเครื่อง windowsXP นั้นมีแชร์อะไรเปิดอยู่บ้าง โดย ชื่อ winxp ที่อยู่หลัง -L นั้น
เป็นชื่อของคอมพิวเตอร์ windowsXP ตรวจสอบได้จากการคลิกขวา MyComputer และเลือกดูที่ชื่อคอมพิวเตอร์

smbclient //winxp/install -U administrator
password:

เป็นคำสั่งเข้าใช้งานแชร์ชื่อว่า install ในเครื่อง XP ด้วย administrator user

ตรวจสอบดูว่าเราสามารถใช้คำสั่งอะไรได้บ้างจาก msclient ด้วยเครื่องหมาย ? ที่พร้อมของ smbclient
จะปรากฏคำสั่งเรียงรายออกมาให้เลือกใช้ได้ตามความเหมาะสม



ในพร้อมของคำสั่ง msclient เหมือนคำสั่ง ftp ที่ได้เข้าไปยัง ftp server ได้แล้ว เหมือนหนึ่งว่าได้เข้าไปนั่ง
ที่คอมพิวเตอร์เครื่องนั้น ๆ แล้ว จึงสามารถจัดการไฟล์ด้วยการ copy มาไว้ที่เครื่องเราหรือจะโยนไฟล์ที่เครื่องเราไป
ที่เครื่องของ xp ก็ได้ คำสั่งต่าง ๆ ที่เราได้รู้จาก ? เอามาใช้ประโยชน์ เช่น

get filename คำสั่ง get ตามด้วยชื่อไฟล์ เป็นการ copy ไฟล์ที่ระบุมายัง linux
mget * เหมือนคำสั่ง get เพียงแต่ copy ครั้งละหลาย ๆไฟล์
ls ตรวจสอบว่าทีไดเรกปัจจุบันที่เรา login เข้ามาแล้วมีไฟล์อะไรบ้าง หากเราจะดูว่าแล้วที่ linux ของเราหละ
ขณะนี้มีไฟล์อะไรบ้างก็ใช้คำสั่ง ! ls
cd directory คำสั่ง cd ตามด้วย ไดเรกทอรีเป็นการเข้าไปยังไดเรกทอรีนั้น ๆ การตรวจสอบว่าขณะนี้เราอยู่ที่
ไดเรกทอรีอะไรให้ใช้คำสั่ง pwd
put และ mput เป็นคำสั่งโยนไฟล์จากเครื่อง linux ไปยังไดเรกทอรีปลายทางใน windows
ออกจากคำสั่ง msclient ด้วย quit

ใน windows เราไดเคย map drive ของเครื่องอื่น ๆ เข้ามาเป็น drive ตัวหนึ่งในเครื่องเพื่อจะได้ใช้งานได้โดยสะดวก
ใน linux ก็สามารถ map drive ลักษณะนั้นได้ เรียกว่าการ mount ซึ่งการ mount ในลีนุกซ์จะแตกต่างจากวินโดสว์
ที่ต้องสร้างไดเรกทอรีขึ้นมารองรับเสียก่อน และเข้าถึงแชร์นั้นโดยผ่านไดเรกทอรีที่สร้างนั้น ในตัวอย่างของวีดีโอนี้ map แชร์ชื่อว่า install ในวินโดวส์เข้ามาเป็นไดเรกทอรีในลีนุกซ์ และเข้าใช้งาน แชร์ install ผ่านไดเรกทอรี นั้น ดังนี้

สร้างไดเรกทอรีขึ้นมารองรับ mkdir /media/samba
map แชร์ด้วยคำสั่ง

smbmount //winxp/install /media/samba -o username=administrator

การยกเลิก drive ที่ map เข้ามาแล้ว ด้วยคำสั่ง smbumount /media/samba

จบวีดีช่วยสอนในไฟล์ที่ 1 เท่านี้

Samba Linux Server


Samba sets up network shares for chosen Unix directories (including all contained
subdirectories). These appear to Microsoft Windows users as normal Windows folders
accessible via the network. Unix users can either mount the shares directly as part of their file structure or, alternatively, can use a utility, smbclient (libsmb) installed with Samba to read the shares with a similar interface to a standard command line FTP program. Each directory can have different access privileges overlaid on top of the normal Unix file protections. For example: home directories would have read/write access for all known users, allowing each to access their own files. However they would still not have access to the files of others unless that permission would normally exist. Note that the netlogon
share, typically distributed as a read only share from /etc/samba/netlogon, is the logon

directory for user logon scripts.

Configuration is achieved by editing a single file (typically installed as /etc/smb.conf or /etc/samba/smb.conf). samba can also provide user logon scripts and group policy
implementation through poledit.

CODE

http://rapidshare.com/files/132632180/samba1.avi
http://rapidshare.com/files/132686954/samba2.avi
http://rapidshare.com/files/132632793/samba3.avi
http://rapidshare.com/files/132633169/samba4.avi
http://rapidshare.com/files/132633301/samba5.avi
http://rapidshare.com/files/132634112/samba6.avi
http://rapidshare.com/files/132751641/samba7_cupsprinting.avi

Wednesday, August 13, 2008

Samba with IPtables

หลังจากที่ set เครื่อง PDC ด้วย samba ขึ้นมาแล้ว หากรัน service iptables ด้วยจะทำให้เครื่องอื่น ๆเข้ามาใช้บริการไม่ได้เพราะถูกป้องกันด้วย firewall iptables ไปด้วย ไอ้ครั้นจะยกเลิก service iptables ไป PDC server ของเราก็จะไม่ปลอดภัย และดูเป็นธรรมดาๆ เสียเหลือเกิน (อายพวกมือเก๋า ๆ) อย่ากระนั้นเลยมาลองมั่วเปิด service iptables ร่วมกับ samba ดูสักตั้งหนึ่งประไร.....

ได้ยินมาว่าเจ้า samba ให้บริการผ่าน port 137,138,139 และ 445 มีคนแนะนำให้เปิดดูในไฟล์ /etc/services
ก็จะพบความจริงที่แสดงในบรรทัดดังนี้

netbios-ns 137/tcp # NetBIOS Name Service
netbios-ns 137/udp
netbios-dgm 138/tcp # NetBIOS Datagram Service
netbios-dgm 138/udp
netbios-ssn 139/tcp # NetBIOS Session Service
netbios-ssn 139/udp
microsoft-ds 445/tcp # Microsoft Directory Service
microsoft-ds 445/udp



เห็นกับตาอาจเป็นเพียงทฤษฏี มาลองดูของจริง ๆ ว่า samba มันเปิดพอร์ตไหนไว้บริการแน่ที่เครื่อง PDC ก่อนอื่นให้ stop
samba ก่อน แล้วตรวจสอบ พอร์ตที่เปิดบริการ จากนั้น start samba และตรวจสอบเทียบเคียงกันอีกชั้นหนึ่ง ดังนี้

# service smb stop
# netstat -ln > netstat-ln-smb.before
# service smb start
# netstat -ln > netstat-ln-smb.after
# diff netstat-ln-smb.*


edit /etc/sysconfig/iptables

*filter
:INPUT ACCEPT [56005:161967936]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [55983:161988082]
-A INPUT -p udp -m udp --dport 138 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 139 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 445 -j ACCEPT
-A INPUT -p udp -m udp --dport 137 -j ACCEPT
COMMIT





แหล่งอ้างอิง http://troy.jdmz.net/samba/fw/

Twitter Delicious Facebook Digg Stumbleupon Favorites More