Syslog-ng-SSH log
การสร้าง SSH Logging ด้วย Syslog-ng
เราจะเห็นได้ว่าใน SUSE Linux Enterprise Server มีการเก็บ log file SSH ลงบน /var/log/messages ซึ่งทำให้อยากต้องการตรวจสอบ แนวทางแก็ไขก็คือสร้างที่เก็บ SSH log file นี่ใหม่ครับ.
1. สร้าง SSH log directory
# mkdir /var/log/sshd
2. สร้างไฟล์สำหรับเก็บ log
# touch /var/log/sshd/sshderr.log
# touch /var/log/sshd/sshd.log
3. แก้ไขไฟล์ syslog-ng.conf.in
# vim /etc/syslog-ng/syslog-ng.conf.in
พิมพ์เพิ่มในบรรทัดสุดท้ายครับ
# SSH Filters
filter f_sshderr { match('^sshd\[[0-9]+\]: error:'); };
filter f_sshd { match('^sshd\[[0-9]+\]:'); };
# SSH Logging
destination sshderr { file("/var/log/sshd/sshderr.log"); };
log { source(src); filter(f_sshderr); destination(sshderr); flags(final); };
destination sshd { file("/var/log/sshd/sshd.log"); };
log { source(src); filter(f_sshd); destination(sshd); flags(final); };
:wq!
รายละเอียด
| Entry | Description |
| # SSH Filters | This line is a comment and only there for human readability/reminder. |
| filter f_sshderr { match('^sshd\[[0-9]+\]: error:'); }; | This line sets a filter statement which will weed out the following strings "sshd: error:". Between the brackets any digits can exist there. |
| filter f_sshd { match('^sshd\[[0-9]+\]:'); }; | This line sets a filter statement which will weed out the following strings "sshd:". Between the brackets any digits can exist there. |
| # SSH Logging | This line is a comment and only there for human readability/reminder. |
| destination sshderr { file("/var/log/sshd/sshderr.log"); }; | This line a destination for SSH errors i.e. /var/log/sshd/sshderr.log. |
| log { source(src); filter(f_sshderr); destination(sshderr); flags(final); }; | This line combines the filter and the destination for logging. |
| destination sshd { file("/var/log/sshd/sshd.log"); }; | This line a destination for all other SSH activities i.e. /var/log/sshd/sshd.log. |
| log { source(src); filter(f_sshd); destination(sshd); flags(final); }; | This line combines the filter and the destination for logging. |
4. สั่ง Generating syslog-ng
# SuSEconfig
5. Restart syslog-ng daemon
# rcsyslog restart หรือ service syslog restart
6. ตรวจสอบ log SSH
ทดสอบโดยการที่คุณลอง ssh มาที่เครื่องที่คุณได้ config ไว้หลังจากนั้นให้ใช้คำสั่ง tail -f ในการตรวจสอบ
เช่น tail -f /var/log/sshd/sshderr.log
7. สร้าง logrotate
# vim /etc/logrotate.d/sshd
/var/log/sshd.log /var/log/sshderr.log {
compress
dateext
maxage 365
rotate 99
size=+400k
notifempty
missingok
copytruncate
create 640 root root
sharedscripts
postrotate
/etc/init.d/syslog reload
endscript
}
Ref : http://www.novell.com/communities/

SUSE Linux Enterprise Cool Solutions
|







