2009年9月18日 星期五

ssh over autofs

SSHFS (Secure SHell FileSystem) is a file system for Linux (and other operating systems with a FUSE implementation, such as Mac OS X or FreeBSD) capable of operating on files on a remote computer using just a secure shell login on the remote computer. On the local computer where the SSHFS is mounted, the implementation makes use of the FUSE (Filesystem in Userspace) kernel module. The practical effect of this is that the end user can seamlessly interact with remote files being securely served over SSH just as if they were local files on his/her computer. On the remote computer the SFTP subsystem of SSH is used.
先引用一下Man page省我一點口舌,SSHFS就是透過ssh連線把對方的檔案拉過來當自己檔案系統的一部分,好處是ssh連線是加密的,而且可以用金鑰認證省去每次打密碼的麻煩。
DESCRIPTION
autofs control the operation of the automount(8) daemons running on the Linux system. Usually autofs is invoked at system boot time with the start parameter and at shutdown time with the stop parameter. The autofs script can also manually be invoked by the system administrator to shutdown, restart or reload the automounters.
再引用autofs的描述,就是一種技術,當你需要檔案系統某部份的時候,系統就會自動根據路徑去自動掛檔案系統(種類很多),讓你根本不用動用系統底層去處理掛載與卸載的問題,專注於你要做的事情之上。
兩者結合在一起,就可以達到安全存取遠端少量且重要的檔案的需求,瞬間拉進來就好像長在本地一樣。

第一步,用金鑰加速連線遠端主機(名$RmoteHost)省去認證
提示:設定$RemoteHost:/etc/ssh/sshd_config
PubkeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys
將你的金鑰中公鑰放進去信任名單
scp ~/.ssh/id_rsa.pub $RemoteHost:\.ssh/authorized_keys
如果沒有金鑰,你問題好大,麻煩去找鎖匠(man ssh-keygen)打一副再回來重練。

然後遠端設定就完成了(什麼?就這樣?),是的,對方只有設定完accept ssh public-key 就大致完成了,什麼連線要多久中斷之類還可以微調,不過不重要。本機機器設定以UBUNTU 9.04 為示範(本機$LocalHost,因為本人從BSD帶來的壞習慣,都是直接用root不用sudo)。
首先安裝套件sshfs autofs
apt-get install sshfs autofs
autofs有autofs4、autofs5新舊版之分,可以試試看新版,應該不會導致系統爆炸。sshfs是依賴於系統核心fuse模組,因為UBUNTU 9.04是直接把它編在核心裡,不再放在外掛模組,所以也不用多加理會,把自己加進可以使用fuse的群組

adduser $USER fuse
接下來只要設定autofs完成,就可以享受這成果了。

編輯/etc/autofs.master,加入sshfs設定
/mnt/ssh /etc/auto.sshfs uid=1001,gid=1001,--timeout=300,--ghost
/mnt/ssh就是autofs掛載起始點 設定掛進來給uid 1001 與 gid 1001的人用,不知道是誰就趕快翻翻/etc/passwd。設定過300秒就斷線。
然後繼續編寫/etc/auto.sshfs

# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# Details may be found in the autofs(5) manpage
skb -fstype=fuse,rw,nodev,nonempty,noatime,allow_other,max_read=65536 :sshfs\#$RemotUser@$RemoteHost\:
範例看得很清楚,此時只要你要求/mnt/ssh/skb下面檔案,就會自動通到
$RemotUser@$RemoteHost,基本上就是他的家目錄,也就是你一開始拷鑰匙過去的人家,這時候天涯若比鄰,你家就是我家!!
對了,記得叫autofs開機自動跑
/etc/init.d/autofs start

參考資料:Totally Seamless SSHFS under Linux using Fuse and Autofs

2009年9月17日 星期四

純粹碎碎念

可惡的BIND9,裝在FreeBSD的時候就很聰明,會自動去Chroot相對路徑找資料,怎麼在linux就一定要絕對路徑指明檔案,害我DNS停擺好幾天,掉了好多頭髮還想不出原因(不是因為我懶或笨)。可惡!!這樣還敢說你有chroot,我、才、不、信!以後bind還是給FreeBSD跑。

VMware安裝 @ Ubuntu

近欠很多篇筆記喔 哈

首發就來這個在ubuntu 9.04上安裝VMware  Server 的筆記。

為什麼這時候棄Virtual Box不用?很簡單,64 位元。首先去VMware 下載,Server 2免費的,不過要註冊,不用錢。

下載的時候,因為公司控管頻寬只能衝到450k,所以我決定在家裡遙控下載,可以衝到700k。本來是用lynx來下載,一樣可以https連線,登入存cookies,不過下載後搬到/var/tmp/lynx/$sessionxxx的鬼,靠~所以反正是實驗,就給她硬上Xorg與 firefox 3.5,然後遠端執行Firefox下載。

安裝的方法,rpm的方法不紀錄。VMware-server-$Version.tar.gz就是剛剛下載的tarball,就把它解開

tar xzvf VMVMware-server-*.x86_64.tar.gz

會得到vmware-server-distrib這目錄,執行裡面的vmware-install.pl就會開始文字介面的安裝VMware。因為這是現場編譯很多模組,因此有很多基本功夫要先打底,不然等一下被考倒重考很尷尬,我不甲意這種感覺。

apt-get install build-essential vmware-package

其中因為會用到核心的C headers,所以要抓來核心補完計畫。方法事先檢查現在用的核心是啥版本

uname –a

然後安裝你的對應版本

aptitude install linux-headers-2.6.$version

把它作個符號連結,偽裝成/usr/src/linux。

全部跑過以後,包含你腦袋清楚的設定完Bridge, NAT,Hostonly的網路組態後,我是用網路連線進去組態。直接打開瀏覽器,輸入http://$VMhost:8222就可直通到主控台,更神奇的是加裝外掛後,瀏覽器就可以直接開啟虛擬機器的主畫面,可以開始安裝。

2009年9月4日 星期五

[OpenBox] 隨著X啟動程式

話說拿著那個退役筆電當第二個監控螢幕,把它用最精簡的X裝法完成。但是我想讓它自己開機就會進入pcmanx 監控。以下就是簡述

因為監控程式moni是用4gl的程式,所以一定要使用pcmanx才能繪出畫面,所以第一步驟簡化就是前面用過得getty –l 自動登入技巧。

第二步驟,在.bash_profile寫入一個

if  [ $TERM==linux ] ; then

startx

fi

這樣當tty登入,就會接著啟動x視窗。

自動啟動xinit後,本來查到的文件叫我直接寫~/.xsession或~/.xinitrc,不過我發現那太鳥了,因為她是在WindowManager前執行,所以就是醜醜的x加上你要開的程式…

OpenBox說,寫Autostart。執行程式的寫法是

( sleep 1 && Name_of_Program )&

最後,因為Ray會貼心的幫我關機省電,But這台老筆電沒有電源管理,所以按下開關,就真的斷電關機了。因此,我在root的cron table加入關機指令(ㄜ 如果你永遠可以準時下班 ),從此,這台筆電就真的「家電化」,按電源開!時間到關!Yes!!