右鍵已鎖定
logo

安裝FreeBSD 9.1-RELEASE (下)

安裝好之後當然要來作一些基本設定啦,不然整台機器也太陌生了
1.設定sshd
安裝好當然要先讓他可以遠端ssh,不然每次都要本機console太麻煩了,雖然安裝過程中有enable sshd開機時啟動,但是光是啟動sshd還是無法ssh你的BSD的,因為BSD的安全性考量,不能讓root做遠端ssh登入,所以我們要修改一下

# vi /etc/ssh/sshd_config

找到這句,把它mark拿掉就可以了

PermitRootLogin yes

這樣就可以登入了,但是為了方便之後做key,順便把這些設定mark拿掉

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys


2.更新ports tree
為了方便之後安裝軟體,建議先把ports tree更新到最新,相信還是有很多人在用 csup 或是更老派的 cvsup ,新版的BSD可以使用更為簡單的portsnap,portsnap 是為了取代之前 cvsup/csup 的更新方法而誕生的,因為 cvsup/csup 要多開一個 tcp port 5999 而 portsnap 是走web的 tcp port 80,所以防火牆可以少開一個 tcp port 比較安全一點,以前也是要先安裝才能使用而現在改成內建在系統裡面。

先修改portsnap的server位置到台灣,更新會比較快

# vi /etc/portsnap.conf
SERVERNAME=portsnap.tw.FreeBSD.org

首先執行 portsnap fetch 抓 server 上的 portsnap
如果是第一次使用的話再執行 portsnap extract 建立 snap 在主機上
因為我們剛裝好,所以一定是第一次執行

# portsnap fetch extract
….(略)…..
/usr/ports/x11/yalias/
/usr/ports/x11/yeahconsole/
/usr/ports/x11/yelp/
/usr/ports/x11/zenity/
Building new INDEX files... done.

以後要更新的話就只需要一行就可以了

# portsnap fetch upate
Looking up portsnap.tw.FreeBSD.org mirrors... none found.
Fetching snapshot tag from portsnap.tw.FreeBSD.org... done.
Latest snapshot on server matches what we already have.
No updates needed.
Ports tree is already up to date. 

(BSD 9.1版是2012/12月才release所以檔案都還蠻新的,裝8.2版可能更新就很多)
執行完 Portsnap 更新後查看一下系統中的 Ports Tree 是否確實更新

#less /usr/ports/UPDATING
20121030:
 AFFECTS: users of www/squid31
  AUTHOR: [email protected]
 

在安裝軟體時,系統會幫你找尋相關的必要軟體,這是make幫你做的事情,所以如果不指定server給他,他會從網路幫你搜尋,通常都很慢…所以我們需要設定一下make.conf

# cp /etc/defaults/make.conf /etc/ (沒有也沒關係,直接自己創) 
# vi /etc/make.conf
# Port master sites.
#
# If you want your port fetches to go somewhere else than the default
# (specified below) in case the distfile/patchfile was not found,
# uncomment this and change it to a location nearest you.  (Don't
# remove the "/${DIST_SUBDIR}/" part.)
#

MASTER_SITE_BACKUP?=    \
     ftp://ftp.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
     ftp://ftp5.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
     ftp://ftp10.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
     ftp://ftp2.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
     ftp://ftp3.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
     ftp://ftp4.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
     ftp://ftp7.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
     ftp://ftp8.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
     ftp://ftp9.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
     ftp://ftp11.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
     ftp://ftp12.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
     ftp://ftp.freebsd.org/pub/FreeBSD/ports/distfiles/${DIST_SUBDIR}/

# If you want your port fetches to check the above site first (before
# the MASTER_SITES specified in the port Makefiles), uncomment the
# line below.  You can also change the right side to point to wherever
# you want.

MASTER_SITE_OVERRIDE?= ${MASTER_SITE_BACKUP}

上述站台的排列原則是,哪一台的網路連線與您的網路環境最佳者,排在第一個。抓檔案時,如果第一台抓不到,會依序向第二台詢問有沒有。如果都問完了,還是沒有,就會到國外的原始站台去抓。不過,這種情形應該很少見到。

3.安裝vim-lite,與設定vimrc (不要裝成vim了,會很久)

# cd /usr/ports/editors/vim-lite/
# make install clean
# vi .vimrc
set encoding=utf-8
set fileencodings=utf-8,cp950

syntax on        " 語法上色顯示 "
set nocompatible " VIM 不使用和 VI 相容的模式 "
set shiftwidth=2 " 設定縮排寬度 = 4 "
set tabstop=4    " tab 的字元數 "
set softtabstop=4
set backspace=2  " 在 insert 也可用 backspace"
set ic           " 設定搜尋忽略大小寫 "
set ru           " 第幾行第幾個字 "
set hlsearch     " 設定高亮度顯示搜尋結果 "
set incsearch    " 在關鍵字還沒完全輸入完畢前就顯示結果 "
set smartindent  " 設定 smartindent "
set confirm      " 操作過程有衝突時,以明確的文字來詢問 "
set history=100  " 保留 100 個使用過的指令 "
set laststatus=2

4.使用習慣設定
A.更改按鍵
BSD預設不能使用 HOME、END..等鍵,真的很難用(超難用),先改一下

# vi /etc/profile
export INPUTRC=/usr/local/etc/inputrc
# vi /usr/local/etc/inputrc
set meta-flag on
set input-meta on
set convert-meta off
set output-meta on
"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": beginning-of-history
"\e[6~": end-of-history
"\e[3~": delete-char
"\e[2~": quoted-insert
"\e[5C": forward-word
"\e[5D": backward-word

登出再登入就生效了

B.更改登入環境BASH
BSD預設為CSH,linux為bash,因為習慣bash所以BSD也要改一下
先看看BSD有沒有安裝bash

# bash
bash: Command not found.

Well….沒有,很正常,安裝吧

# cd /usr/ports/shells/bash
# make install clean

#which bash
/usr/local/bin/bash
# chsh -s /usr/local/bin/bash root
chsh: user information updated

BSD只吃 .bash_profile,不像linux可以吃 .bashrc,不過因為使用習慣,所以我們可以這樣做

#vi .bash_profile
source ~/.bashrc

再來.bashrc愛怎麼改都可以,反正登入時 .bash_profile都會去撈.bashrc

#vi .bashrc
alias ls='ls -G'
alias ll='ls -alhG'
alias rm='rm -i'
alias vi='vim'
alias tailf='tail –f'
# source .bashrc

安裝sudo,蠻多機會用到的,而且linux會幫你裝好,bsd竟然沒有!

# cd /usr/ports/security/sudo 
# make install clean
3,241 次瀏覽