SSHFS挂载远程目录

SSHFS配置

SSHFS基于SSH协议 ,所以首先你本地以及远程主机上要安装有实现SSH协议的openssh或SSH Communications 软件

本地Linux发行版内要安装有fuse模块,因为sshfs需要fuse模块的支持。

Fuse安装包(在Linux系统安装包中)

fuse-2.7.4-8.el5

fuse-devel-2.7.4-8.el5

fuse-libs-2.7.4-8.el5

下载地址:http://sourceforge.net/projects/fuse/files/sshfs-fuse/2.5/

sshfs-fuse-2.5.tar.gz

 

 

检查安装openssh

[root@ora10g ~]# rpm -qa | grep openssh

openssh-4.3p2-41.el5

openssh-server-4.3p2-41.el5

openssh-askpass-4.3p2-41.el5

openssh-clients-4.3p2-41.el5

[root@ora10g ~]#

 

 

安装fuse

[root@node2 ~]# cd sshfs

[root@node2 sshfs]# ls

fuse-2.7.4-8.el5.x86_64.rpm        fuse-libs-2.7.4-8.el5.x86_64.rpm

fuse-2.9.4.tar.gz                  sshfs-fuse-2.5.tar.gz

fuse-devel-2.7.4-8.el5.x86_64.rpm

[root@node2 sshfs]# rpm -ivh *.rpm

[root@node2 sshfs]# rpm -qa | grep fuse

fuse-2.7.4-8.el5

fuse-devel-2.7.4-8.el5

fuse-libs-2.7.4-8.el5

[root@node2 sshfs]#

 

 

检查fuse是否被载入,

检查系统有没有fuse模块,如果系统没有输出则没有这个模块

[root@node2 sshfs]# lsmod | grep fuse

[root@node2 sshfs]# dmesg | grep fuse

 

 

使用modprobe加载fuse模块

[root@node2 sshfs]# modprobe fuse

[root@node2 sshfs]# dmesg | grep fuse

fuse init (API version 7.10)

[root@node2 sshfs]# lsmod | grep fuse

fuse                   83057  0

[root@node2 sshfs]#

 

 

解压并安装sshfs

[root@node2 ~]# tar zxvf sshfs-fuse-2.5

[root@node2 ~]# cd sshfs-fuse-2.5

[root@node2 sshfs-fuse-2.5]# ls

aclocal.m4  config.h       depcomp      missing        sshfs-sshfs.o

AUTHORS     config.h.in    FAQ.txt      NEWS           sshnodelay.c

cache.c     config.log     INSTALL      README         sshnodelay.so

cache.h     config.status  install-sh   sshfs          stamp-h1

ChangeLog   configure      Makefile     sshfs.1

compat      configure.ac   Makefile.am  sshfs.c

compile     COPYING        Makefile.in  sshfs-cache.o

[root@node2 sshfs-fuse-2.5]# ./configure && make && make install

[root@node2 sshfs-fuse-2.5]# which sshfs

/usr/local/bin/sshfs

 

 

挂载

sshfs –o allow_other root@192.168.80.102:/devdb2_arch /devdb2_arch

 

sshfs [remote_user]@[remote_server]:[remote_directory] [mountpoint] [options]

options选项:

-C 压缩,或者-o compression=yes
-o reconnect 自动重连
-o transform_symlinks 表示转换绝对链接符号为相对链接符号

-o follow_symlinks 沿用服务器上的链接符号

-o cache=yes
-o allow_other

把远程102节点上的/devdb2_arch目录挂载到本机的/devdb2_arch目录(本机IP192.168.80.101

-o allow_other选项是指挂载后允许系统上的其它用户访问该目录/devdb2_arch(更多选项请使用:man sshfs

allow_other选项很重要,必须添加,否则任何文件都是Permission Deny

 

 

开机自启动

/etc/fstab中添加挂载项

sshfs#root@192.168.80.102:/devdb2_arch   /devdb2_arch  fuse defaults,auto,allow_other       0 0

 

sshfs#[remote_user]@[remote_server]:[remote_directory] [mountpoint] fuse allow_other 0 0

 

挂载后使用df命令查看挂载目录

 

配置用户的SSH对等性,实现自启动自动挂载

以下是RACoracle用户的SSH对等性配置,root用户的配置参考orace用户即可

[root@node1 ~]# su - oracle

[oracle@node1 ~]$ pwd

/u01/app/oracle

[oracle@node1 ~]$ ls -la

total 40

drwxr-xr-x 5 oracle oinstall 4096 Apr  7 23:52 .

drwxr-xr-x 3 oracle oinstall 4096 Apr  7 22:55 ..

drwxr-xr-x 2 oracle oinstall 4096 Apr  7 23:15 admin

-rw------- 1 oracle oinstall  570 Apr  7 23:59 .bash_history

-rw-r--r-- 1 oracle oinstall   33 Apr  7 23:01 .bash_logout

-rw-r--r-- 1 oracle oinstall  481 Apr  7 23:12 .bash_profile

-rw-r--r-- 1 oracle oinstall  124 Apr  7 23:01 .bashrc

drwxr-xr-x 3 oracle oinstall 4096 Apr  7 23:17 oradata

drwxr-xr-x 3 oracle oinstall 4096 Apr  7 23:15 product

-rw------- 1 oracle oinstall  866 Apr  7 23:52 .viminfo

[oracle@node1 ~]$ mkdir .ssh

[oracle@node1 ~]$ chmod 700 .ssh/

[oracle@node1 ~]$ cd .ssh/

[oracle@node1 .ssh]$ ls

[oracle@node1 .ssh]$ ls - la

ls: -: No such file or directory

ls: la: No such file or directory

[oracle@node1 .ssh]$ ls -la

total 8

drwx------ 2 oracle oinstall 4096 Apr  8 00:02 .

drwxr-xr-x 6 oracle oinstall 4096 Apr  8 00:02 ..

[oracle@node1 .ssh]$ which ssh

/usr/bin/ssh

[oracle@node1 .ssh]$ which ssh-keygen

/usr/bin/ssh-keygen

[oracle@node1 .ssh]$ ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/u01/app/oracle/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /u01/app/oracle/.ssh/id_rsa.

Your public key has been saved in /u01/app/oracle/.ssh/id_rsa.pub.

The key fingerprint is:

0a:1b:ca:46:ba:81:6a:92:67:d1:2c:ce:f6:1a:19:e9 oracle@node1

[oracle@node1 .ssh]$ ssh-keygen -t dsa

Generating public/private dsa key pair.

Enter file in which to save the key (/u01/app/oracle/.ssh/id_dsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /u01/app/oracle/.ssh/id_dsa.

Your public key has been saved in /u01/app/oracle/.ssh/id_dsa.pub.

The key fingerprint is:

bc:f2:eb:83:a4:57:80:7e:1c:42:34:2b:7a:f9:6b:c9 oracle@node1

[oracle@node1 .ssh]$ ls -la

total 24

drwx------ 2 oracle oinstall 4096 Apr  8 00:05 .

drwxr-xr-x 6 oracle oinstall 4096 Apr  8 00:02 ..

-rw------- 1 oracle oinstall  672 Apr  8 00:05 id_dsa

-rw-r--r-- 1 oracle oinstall  602 Apr  8 00:05 id_dsa.pub

-rw------- 1 oracle oinstall 1675 Apr  8 00:05 id_rsa

-rw-r--r-- 1 oracle oinstall  394 Apr  8 00:05 id_rsa.pub

[oracle@node1 .ssh]$ cat *.pub > authorized_keys

[oracle@node1 .ssh]$ ll

total 20

-rw-r--r-- 1 oracle oinstall  996 Apr  8 00:06 authorized_keys

-rw------- 1 oracle oinstall  672 Apr  8 00:05 id_dsa

-rw-r--r-- 1 oracle oinstall  602 Apr  8 00:05 id_dsa.pub

-rw------- 1 oracle oinstall 1675 Apr  8 00:05 id_rsa

-rw-r--r-- 1 oracle oinstall  394 Apr  8 00:05 id_rsa.pub

 

 

[oracle@node1 .ssh]$ ssh node2 cat ~/.ssh/*.pub >> authorized_keys

The authenticity of host 'node2 (192.168.136.102)' can't be established.

RSA key fingerprint is 2f:6f:94:34:06:a6:89:ee:fb:98:f1:44:8c:7c:40:5d.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'node2,192.168.136.102' (RSA) to the list of known hosts.

oracle@node2's password:

[oracle@node1 .ssh]$ ls

authorized_keys  id_dsa  id_dsa.pub  id_rsa  id_rsa.pub  known_hosts

[oracle@node1 .ssh]$ ll

total 24

-rw-r--r-- 1 oracle oinstall 1992 Apr  8 00:10 authorized_keys

-rw------- 1 oracle oinstall  672 Apr  8 00:05 id_dsa

-rw-r--r-- 1 oracle oinstall  602 Apr  8 00:05 id_dsa.pub

-rw------- 1 oracle oinstall 1675 Apr  8 00:05 id_rsa

-rw-r--r-- 1 oracle oinstall  394 Apr  8 00:05 id_rsa.pub

-rw-r--r-- 1 oracle oinstall  403 Apr  8 00:10 known_hosts

 

[oracle@node1 .ssh]$ scp authorized_keys node2:~/.ssh/

oracle@node2's password:

authorized_keys                               100% 1992     2.0KB/s   00:00   

[oracle@node1 .ssh]$ ssh node1 date

Wed Apr  8 00:14:29 CST 2015

[oracle@node1 .ssh]$ ssh node2 date

Wed Apr  8 00:14:32 CST 2015

[oracle@node1 .ssh]$ ssh node1-priv date

Wed Apr  8 00:14:36 CST 2015

[oracle@node1 .ssh]$ ssh node2-priv date

Wed Apr  8 00:14:47 CST 2015

 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26537027/viewspace-1825074/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/26537027/viewspace-1825074/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值