Linux下建立SSHFS共享

        我們使用windows共享習慣了,總希望在Linux上執行相同,或類似的操作。可喜的是Linux內核,提供ssh服務。所以,我們可以方便的藉助於sshfs工具實現遠程服務器的訪問。本文中,使用簡單的方法,實現了此過程。整個操作過程記錄文檔,可以參考資源:

http://download.csdn.net/detail/attagain/6847317

http://download.csdn.net/detail/attagain/7802929


1、 應用說明
 服務端:指提供共享目錄,用來爲客戶端提供訪問服務
 客戶端:訪問服務器端共享目錄的終端
2、 客戶端環境準備
客戶端IP:192.168.30.206
1) 客戶端sshfs-fuse工具安裝
官網URL:http://sourceforge.net/projects/fuse/files/sshfs-fuse/
 安裝fuse的方法:
[TSP@tsp-rls-webservice01 ~]$ tar xvf fuse-2.9.3.tar.gz
[TSP@tsp-rls-webservice01 ~]$ cd  fuse-2.9.3
[TSP@tsp-rls-webservice01 fuse-2.9.3]$ ./configure
[TSP@tsp-rls-webservice01 fuse-2.9.3]$ make
[TSP@tsp-rls-webservice01 fuse-2.9.3]$ sudo make install
 安裝sshfs-fuse的安裝方法:
[TSP@tsp-rls-webservice01 ~]$ tar xvf sshfs-fuse-2.5.tar.gz
[TSP@tsp-rls-webservice01 ~]$ cd sshfs-fuse-2.5
[TSP@tsp-rls-webservice01 sshfs-fuse-2.5]$ ./configure
[TSP@tsp-rls-webservice01 sshfs-fuse-2.5]$ make
[TSP@tsp-rls-webservice01 sshfs-fuse-2.5]$ sudo make install

3、 配置ssh自動登陸
1) 在客戶端使用普通用戶生成密鑰對
  客戶端IP:192.168.30.206
 執行命令:ssh-keygen -d
 執行結果如下:
[TSP@tsp-rls-webservice01 ~]$ ssh-keygen -d
Generating public/private dsa key pair.
Enter file in which to save the key (/home/TSP/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/TSP/.ssh/id_dsa.
Your public key has been saved in /home/TSP/.ssh/id_dsa.pub.
The key fingerprint is:
61:23:a4:22:8c:af:37:d9:9d:c8:c5:6e:e6:54:eb:a5 TSP@tsp-rls-webservice01
The key's randomart image is:
+--[ DSA 1024]----+
|      .          |
|o    o           |
|o.. . . +        |
| o . . o o       |
|  .   o S        |
| . + = o .       |
|. + + B . .      |
| . . = . o       |
|      . E        |
+-----------------+
 查看生成的密鑰對文件,執行命令:ll /home/TSP/.ssh
[TSP@tsp-rls-webservice01 ~]$ ll /home/TSP/.ssh
總用量 8
-rw-------. 1 TSP TSP 668 8月  22 10:14 id_dsa
-rw-r--r--. 1 TSP TSP 614 8月  22 10:14 id_dsa.pub
2) 通過客戶端,將公鑰上傳至服務端
客戶端IP:192.168.30.206
 執行命令:ssh-copy-id -i ~/.ssh/id_dsa.pub 192.168.30.202
 執行結果如下:
[TSP@tsp-rls-webservice01 ~]$ ssh-copy-id -i ~/.ssh/id_dsa.pub 192.168.30.202
The authenticity of host '192.168.30.202 (192.168.30.202)' can't be established.
RSA key fingerprint is 69:f8:f9:5a:3a:c7:7e:f2:ad:f3:85:79:43:41:99:3d.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.30.202' (RSA) to the list of known hosts.
[email protected]'s password:
Now try logging into the machine, with "ssh '192.168.30.202'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.
 注意:中間過程,需要輸入服務端的用戶密碼
 根據上述提示,在客戶端使用ssh命令登陸服務端:
[TSP@tsp-rls-webservice01 ~]$ ssh 192.168.30.202
Last login: Fri Aug 22 09:31:06 2014 from 192.168.30.65
[TSP@tsp-rls-webservice ~]$ pwd
/home/TSP
[TSP@tsp-rls-webservice ~]$ ll .ssh/authorized_keys
-rw-------. 1 TSP TSP 614 8月  22 10:18 .ssh/authorized_keys
3) 確認服務端的公鑰信息
  服務端IP:192.168.30.202
 使用服務端TSP用戶登錄,查看服務端.ssh目錄下公鑰信息,執行命令:
ll ~/.ssh/authorized_keys
 執行結果如下:
[TSP@tsp-rls-webservice ~]$ ll ~/.ssh/authorized_keys
-rw-------. 1 TSP TSP 614 8月  22 10:18 /home/TSP/.ssh/authorized_keys
4) 客戶端建立sshfs共享
  客戶端IP:192.168.30.202
 執行命令:sshfs [email protected]:/tsp /tsp -o allow_other,nonempty
 options重點關注下:
 -C 壓縮,或者-o compression=yes
 -o reconnect 自動重連
 -o transform_symlinks 表示轉換絕對鏈接符號爲相對鏈接符號
 -o follow_symlinks 沿用服務器上的鏈接符號
 -o cache=yes
 -o allow_other 這個參數最重要,必須寫,否則任何文件都是Permission Deny
 如果想卸載當前sshfs掛載,使用如下命令:
[TSP@tsp-rls-webservice01 /]$ fusermount -u /tsp
5) 出現allow_other參數不正常的解決方法
錯誤信息如下:
[TSP@tsp-rls-webservice01 tsp]$ sshfs [email protected]:/tsp /tsp -o allow_other,nonempty
fusermount: option allow_other only allowed if 'user_allow_other' is set in /etc/fuse.conf
解決方法,安裝提示,在/etc/fuse.conf中添加user_allow_other
[TSP@tsp-rls-webservice01 tsp]$ sudo vi /etc/fuse.conf
添加如下信息,並保存:
user_allow_other

 


 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章