顯示具有 FreeBSD 標籤的文章。 顯示所有文章
顯示具有 FreeBSD 標籤的文章。 顯示所有文章

2013年5月28日 星期二

如何在 Linux 底下找到想找的東西? - OpenFoundry

如何在 Linux 底下找到想找的東西? - OpenFoundry
好物,有不收藏的道理嗎?

搜尋最大或最新的檔案

在多個資料夾內搜尋

排除指定目錄

搜尋特定類型的檔案

搜尋重複檔案

搜尋檔案內的文字

搜尋文字區塊

管理使用者及檔案

2013年2月1日 星期五

常用 vi 密技之一

每次遇到檔案需要大量註解就得google一次很麻煩,所以把爬文發現筆記到這兒
文章:vim大量註解

1. vim加上多行註解的步驟:

(1) 將游標移到要開始註解的那一列。
(2) 按下ESC、然後按下Ctrl + V ,切換成區塊選取的模式(就是反白啦)。
(3) 將游標向下移到要加上註解的最後一列,此時你可以發現這幾列都被反白了。
(4) 按下大寫I,游標跑回步驟(2)的那一列了,這時就可以直接輸入要用的註解了,假設輸入'//'。
(5) 按下ESC,大功告成。
(6) 千萬不要忘記步驟(5)。

2. vim 取消多行註解的步驟:

(1) 方法和加上多行註解一樣,先將游標移到開始註解的那一列。
(2) 按下ESC、然後按下Ctrl + V ,切換成區塊選取的模式。
(3) 將游標向下移到要加上註解的最後一列,再按左、右的方向鍵,將要delete掉的註解都反白。
(4) 按下delete,大功告成。

其實vim中,Ctrl + V的區塊模式還有很多有趣的功能可以摸索。
其他進階功能,可以參考Vim的官方網站。
http://www.vim.org

筆記網站:http://result945.pixnet.net/blog/post/28300565-vim大量註解

2011年9月19日 星期一

Linux distribution

很常因緣際會需協助系統做設定或檢測,這時候是哪個版本的資訊就很重要囉!!
lsb_release,可列出cat /etc/issue與lsb_release去確認Linux distribution的結果

LSB Version:    :core-3.1-amd64:core-3.1-ia32:core-3.1-noarch:graphics-3.1-amd....Distributor ID: CentOSDescription:    CentOS release 5.4 (Final)Release:        5.4Codename:       Final

uname -a, for FreeBSD就可以看到相關資訊
FreeBSD xxx.xxx.xxx 6.3-STABLE FreeBSD 6.3-STABLE #0: Thu Feb  5 11:06:35 CST 200x     xxx:/usr/obj/usr/src/sys/GENERIC  i386

2011年3月17日 星期四

UNIX 文字工具: pipe

UNIX 文字工具: pipe

UNIX 除了可以將資料流導入或導出純文字檔案之外, 還可以將它導向另一個工具軟體,或是濾器。 這個機制稱為導管 (pipe)。導管符號是 | (通常在鍵盤的 Shift+\ 位置)。 | 的功能就是將它左邊的 stdout 資料變成右邊的 stdin。 所以,只要一個工具軟體的輸出是 stdout, 一個工具軟體的輸入是 stdin,就可以用導管將它們銜接在一起, 變成一個新的工作流程 (pipeline)。
例如
cat -n list.txt | less
就是將加上列號的 list.txt 檔案,放進 less 閱讀工具中。再如
tail -12 list.txt | cat -n
就是將 list.txt 的後 12列,加上列號,印在螢幕上。
只要合乎規定,UNIX 並不限定一個流程中可以使用幾次導管。例如您可以說
tail -22 list.txt | cat -n | less

如果您想要看到一個文字檔案從第 n 列到第 m 列的內容, 可以說
head -m FILE | tail -K
其中 K = m - n + 1。
舉個特例。如果想看到  list.txt 的第 5 列,就說
head -5 forty.txt | tail -1

參考http://libai.math.ncu.edu.tw/bcc16/6/textutil/index.html

2010年3月10日 星期三

Shell 環境

FreeBSD 內附的 Shell 有 sh、csh、tcsh,sh 名為 Bourne Shell,它是 UNIX 系統中最悠久的 shell,所有的 UNIX 系統都會內附這個 shell,我們在寫 shell scripts 時為了可移植性,大多使用 sh。在 FreeBSD 中 csh 和 tcsh 是一樣的東西,csh 名稱的由來是因為它的 scripts 語法和 C 語言很像。至於要使用哪一種 shell 全憑個人偏好,您也可以自行從 ports 中安裝 Linux 用的 bash 或 ksh。

例如,我們要將預設的文書編輯器改成 ee,
在 tcsh 中可以使用:
# setenv EDITOR ee
如果您使用的是 Bourne Shell:
# export EDITOR="ee"
 
在 /etc 下的 csh.cshrc 
是通用的設定,但如果使用者自己的設定和通用設定一樣時,會以使用者的設定為主。 
如果您希望日後每個新增的使用者的設定都是這樣,則必須修改 /usr/share/skel/dot.cshrc 檔案
 
/etc/csh.cshrc 和 /etc/csh.login的差別在於如果是使用者登入,二個檔案都會被執行,如果是 scripts 則只會去讀取 csh.cshrc。 
http://twbsd.org/cht/book/index.php?ch=03 
 
相關資料:第十一章、認識與學習 BASH  

2010年3月9日 星期二

安裝php5 on FreeBSD8

In the past there were several ports for PHP such as /www/mod-php5, /lang/php5-cli, and /lang/php5. Since the release of PHP 5.1.14 there is now only /lang/php5 This port now allows you to choose if you want to install the CLI, CGI, and Apache module.

# cd /usr/ports/lang/php5
# make config
# make install


Once php has installed you will need to install the extra modules for things such as MySQL. These modules are all located in the ports. Some of the most common modules are
/usr/ports/databases/php5-mysql - MySQL Database
/usr/ports/www/php5-session - Sessions
/usr/ports/graphics/php5-gd - Graphics Library

Adding the PHP 5 module to Apache

Apache needs the following lines in the httpd.conf file to use php. These lines should already be added by the port but if you have problems you should double check your httpd.conf file. Note that Apache 2.x does not need the AddModule line.
# Apache 1.3.x
LoadModule php5_module        libexec/apache/libphp5.so
AddModule mod_php5.c
# Apache 2.x
LoadModule php5_module        libexec/apache/libphp5.so
If you installed using the port and had apache installed already it should do this automatically for you.
Next find your DirectoryIndex section in your httpd.conf file. Apache is set up for PHP 4, but not PHP 5 currently so you will need to modify it and change the 4s to 5s like this.

You can change the order as you wish. Or if you just wanted to skip it you could simply add the following line to the httpd.conf file since you know you are going to have php 5.
DirectoryIndex index.php index.html index.htm
Now apache just needs to know what it should parse the PHP files with. These two lines should be added to the httpd.conf file, and can be put at the bottom if needed.
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
If want to use PHP code inside of .htm files you can just add on those extensions.
AddType application/x-httpd-php .php .htm .html

Configuring PHP

Settings for PHP are stored in /usr/local/etc/php.ini You will need to create this file by copying it from /usr/local/etc/php.ini-dist
# cp /usr/local/etc/php.ini-dist /usr/local/etc/php.ini In this file you can set the memory limit for programs. Turn on global variables if you must, set the max file upload size, and everything else you need.

From:http://www.freebsdmadeeasy.com/tutorials/web-server/install-php-5-for-web-hosting.php

2009年9月10日 星期四

LDAP安裝筆記

#安裝openldap23 & 24
cvsup -g -L 2 /root/ports-supfile
#ports-all
ports-net
ports-devel
ports-security

error log:
openldap-sasl-server cannot install: unknown LIBTOOL version: 22
根據失敗的訊息發現部分相依程式版本不對,再根據該程式的目錄去做 cvsup
基本上 make reinstall應該就可以順利安裝

===> An older version of net/openldap23-server is already installed (openldap-server-2.3.43)
You may wish to ``make deinstall'' and install this port again
by ``make reinstall'' to upgrade it properly.
If you really wish to overwrite the old port of net/openldap23-server
without deleting it first, set the variable "FORCE_PKG_REGISTER"
in your environment or the "make install" command line.
#make install FORCE_PKG_REGISTER="yes"

error log:(我決定裝現在最新版本OpenLDAP24)
OpenLDAP versions mismatch: openldap23-client is installed
最後把23版重新再裝一次然後再deinstall
openldap23-server #make reinstall
openldap23-server #make deinstall
openldap24-server #make install
最後終於成功可以裝24版

2009年6月30日 星期二

強迫密碼變更時間

FreeBSD 使用 shadow password 的方式來保護密碼檔,只有 root 才可以讀取編碼後的密碼檔 /etc/master.passwd。但是這並不是系統用來驗証的檔案,為了加快速度,FreeBSD 將該檔做成資料庫 /etc/spwd.db 及 /etc/pwd.db, 因此在修改完 master.passwd 後,必須使用指令 pwd_mkdb 來將 master.passwd 做成資料庫檔案。不過一般而言,我會使用 vipw 這個指令來修改 master.passwd,vipw 會先將 master.passwd 以預設的文書編輯軟體打開,修改完存檔後,它會視需要自動更新資料庫。

#pwd_mkdb master.passwd
  • master.passwd 這個檔案內容中,每個使用者都是獨立的一行,每個欄位使用冒號分開,它的格式是:
    name:password:UID:GID:class:change:expire:fullname:home:shell
  • change:強迫使用者變更密碼的時間,以從1970年到所要變更日期所經過的秒數來表示。你可以使用 date +%s 來求出從1970年到現在時間所經過的秒數,每天為86400秒,以現在時間的秒數加上86400*天數即為你要設定的時間。你可以使用指令下列指令來取得30天後的秒數,再將其填入即可。若設為0則表示不使用此功能:
# expr `date +%s` + 86400 \* 30

2009年5月25日 星期一

用 FreeBSD 來存取 MS Windows 的網芳資料

mount_smbfs -I 192.168.1.2 -N '//NetBISO/shareDirectory' /mnt/abc
這裡的參數 I 表示指定 IP 位址,參數 N 表示不須密碼驗證。如果您所要掛入的分享資料夾需要密碼認證,則不要加參數 N。我們在掛入別台電腦的資料夾時,如果沒有指定使用者名稱,內定會以目前所使用的帳號。

如果我們要使用別的使用者名稱,可以使用下列方式:# mount_smbfs -I 192.168.0.2 '//username@電腦名稱/shareDirectory' /mnt

要掛入的分享目錄:shareDirectory
掛入系統中哪一個目錄:/mnt/abc

This example assumes that a CIFS share has been mounted on the /mnt mount point. The following command line unmounts the share from the mount point.
# umount /mnt

2009年4月28日 星期二

Radius帳號設定

我使用最簡單的方式將使用者帳號密碼設定於 users 檔中,新增了一個使用者帳號為密碼為 user / pass:
  1. 設定 radiusd.conf:因為使用者帳號存在檔案中,因此要確認 authorize 檔中的 file 這個屬性不能被 mark 起來(將#符號取消)
  2. 由於是在本機端認證,因此不需要修改 proxy.conf
  3. 在users中加入下列幾行:
user User-Password == "pass"
Reply-Message = "Hello World!"

設定完成之後,要如何確定設定是否正確呢?可以利用 radtest 這個指令,其格式為 radtest [帳號] [密碼] [認證位址:認證埠] [NAS port] [secret key]:
[root@localhost ~]# radtest user pass localhost 0 testing123
Sending Access-Request of id 75 to 127.0.0.1 port 1812
User-Name = "user"
User-Password = "pass"
NAS-IP-Address = 255.255.255.255
NAS-Port = 0
rad_recv: Access-Accept packet from host 127.0.0.1:1812, id=75, length=57
Reply-Message = "Hello World!"

本篇轉錄自經濟部工業局

2009年4月14日 星期二

Apache 裡 index of 的亂碼問題

想開放一個資料夾,讓老師能透過 samba 上傳教學資料,且在上傳後直接在網頁上就可瀏覽,
若網頁為 big5,中文字在瀏覽器中會變成亂碼,必須要加入以下這行才能解決:

IndexOptions Charset=big5

完整的設定如下,在 httpd.conf 加入中加入


IndexOptions Charset=big5
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all


#另外測試用不同瀏覽器發現存檔的時候有差異
  • FireFox存檔時中文正常
  • IE存檔時仍是亂碼

2009年4月12日 星期日

2009年4月11日 星期六

multi IP應用 on FreeBSD

環境狀況
  1. 只有一台主機及一張網卡
  2. Public IP:公開的網站
  3. 一個 Private IP:內部網站

應用範圍
  1. Setup 2 or More IP address on One NIC
    • ifconfig -alias
      ifconfig_lnc0_alias0="192.168.1.5 netmask 255.255.255.255"(/etc/rc.conf)
    • Finally, Restart FreeBSD network service using network restart script:
      # /etc/rc.d/netif restart && /etc/rc.d/routing restart

  2. Apache - VirtualHost 架設虛擬網站

2009年4月8日 星期三

登入...就馬上寄信給特定的帳號

登入...就馬上寄信給特定的帳號...
想攔截也都來不及...這樣才知道對方什麼時後來的...以及從那裡來...相信這些資訊對被Hack的一方很有用..因為厲害的Hack會把所有可查的記錄檔全部清掉...讓你無從查起...試試看這個...很好用的..

(1)編輯 /etc/profile 在最後一行加入底下語法:
NOW=`date +%Y%m%d:%H%M%S`
LAST=`last $USER -5`
echo "[$NOW]: From $HOSTNAME : this user $USER login..." > /tmp/userlogin.log
echo "$LAST" >> /tmp/userlogin.log
mail -s "Attention !! User Login~~" user1@test.com,user2@test.com < /tmp/userlogin.logrm -f /tmp/userlogin.log

# Nice from http://dz.adj.idv.tw/redirect.php?tid=27&goto=lastpost&sid=jKGOzj

file system full分析

http://www.freebsddiary.org/file-system-full.php

2009年3月24日 星期二

aliases.db out of date

On Thu, Apr 17, 2003 at 03:17:19PM -0500, Redmond Militante wrote:
> hi
>
> i cvsup'd a few days ago to 4.8 from 4.7
> ever since, i've been receiving the following message repeatedly in root's email security reports
> Apr 17 15:00:01 xhostname sm-mta[58360]: alias database /etc/mail/aliases.db out of date
>
> how did this happen?

You updated /etc/mail/aliases, probably by running mergemaster, but
you didn't regenerate the aliases.db file from the aliases file -- and
it's aliases.db being older than aliases which sendmail is complaining
about.

Fix is simple. Just run:

# newaliases

Cheers,

Matthew

--
Dr Matthew J Seaman MA, D.Phil. 26 The Paddocks
Savill Way

maillog 分析

分析

透過 Unix-like 常見的指令或是強大的 perl 來作進行 log 檔的分析。底下有幾個簡單的例子。

查詢伺服器收了幾封信件?
$ grep "from=" /var/log/maillog | wc -l

查詢記錄檔中的某些日期的郵件數量,例如 Oct 11
$ grep "Oct 11" /var/log/maillog | grep "from="| wc -l

查詢某使用者的某封信件狀況
$ grep "xxx@mail.net" /var/log/maillog
Oct 11 00:08:31 shona sendmail[28590]: [ID 801593 mail.info] j2VG8UoI028560: to=, delay=00:00:01, xdelay=00:00:00, mailer=relay, pri=121310, relay=[10.115.1.15] [10.115.1.15], dsn=2.0.0, stat=Sent (j2VG8RjQ013936 Message accepted for delivery
接著利用 Message-ID 做搜尋
$ grep "j2VG8UoI028560" /var/log/mail
Oct 11 00:08:30 shona sendmail[28560]: [ID 801593 mail.info] j2VG8UoI028560: from=, size=1310, class=0, nrcpts=1, msgid=<20051011160826.3451.qmail@mail.fakeurl.net>, proto=SMTP, daemon=MTA, relay=mail.fakeurl.net [192.168.20.15]
Oct 11 00:08:31 shona sendmail[28590]: [ID 801593 mail.info] j2VG8UoI028560: to=, delay=00:00:01, xdelay=00:00:00, mailer=relay, pri=121310, relay=[10.115.1.15] [10.115.1.15], dsn=2.0.0, stat=Sent (j2VG8RjQ013936 Message accepted for delivery)
可得知該封信件寄出成功r

如果想要得到較完整豐富的分析,可以寫個 perl 程式來作處理,網路上也許多免費軟體或收費商業軟體可使用。

免費軟體
SMA - Sendmail log analyzer (written in C, for Sendmail)
sendmail_stat (written in C, for Sendmail)
pflogsumm (written in perl, for Postfix)
eximstats (for exim)

商業軟體
Sawmill ( supports 600 different log formats)

本篇參考http://enews.cc.ncu.edu.tw/enews/post_view2.php?unit=1&sn=155

2009年2月18日 星期三

sed

Want to use sed(1) to edit a file in place? Well, to replace every 'e' with an 'o', in a file name 'foo', you can do:

sed -i.bak s/e/o/g foo

And you'll get a backup of the original in a file name 'foo.bak', but if you want no backup:

sed -i '' s/e/o/g foo

2009年2月17日 星期二

unix密碼檔格式

master.passwd@FreeBSD
帳號:密碼:UID:GID:Login Class:Change:Expire:Full Name:家目錄:Login SHELL

  • Login Class:幾乎沒在用了,通常是空的
  • Change:強迫使用者改密碼的時間週期, 0 表示不設定
  • Expire:使用者帳號的使用期限, 0 表示不設定


passwd@Linux
帳號:密碼:UID:GID:Full Name:家目錄:Login SHELL
FreeBSD比Linux多了三個欄位

因為Linux的密碼是存在shadow


在 FreeBSD 中和使用者帳號資訊相關的有下面幾個檔案

  • /etc/master.passwd
  • /etc/passwd
  • /etc/passwd.XXXXXX
  • /etc/pwd.db
  • /etc/spwd.db
  • /etc/group
  • /etc/login.conf
  • /etc/auth.conf

/etc/master.passwd 和 /etc/passwd 是我們一般所謂的密碼檔,這兩個檔案都是以純文字的方式儲存,當我們以文書編輯軟體開啟檔案時可以直接看到記錄的內容,不過,FreeBSD 為了提昇讀取使用者資訊的效能,真正使用的是轉換為 db 格式的資料庫檔 /etc/pwd.db 和 /etc/spwd.db 。

熱門文章