首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 其他相关 >

Ubuntu停使用sshfs挂载远程目录到本地

2013-10-24 
Ubuntu下使用sshfs挂载远程目录到本地Ubuntu下使用sshfs挂载远程目录到本地访问局域网中其他Ubuntu机器,在

Ubuntu下使用sshfs挂载远程目录到本地

Ubuntu下使用sshfs挂载远程目录到本地


访问局域网中其他Ubuntu机器,在不同机器间跳来跳去,很是麻烦,如果能够把远程目录映射到本地无疑会大大方面使用,就像Windows下的网络映射盘一样。在Linux的世界无疑也会有这种机制和方式,最近在使用的过程中选择了sshfs这个工具来达到把远程目录映射到本地的功能。

SSHFS可在本地安装的文件系统中,通过SSH获得所有加密的通信优势。使用sshfs可以把远程目录直接映射到本地,无需修改远程机器的设置,仅要求有ssh连接的权限(ssh都没有的话,还能干啥?)

官网地址: http://fuse.sourceforge.net/sshfs.html

一、SSHFS for Ubuntu

首先简单介绍一下SSHF。

关于SSH的介绍和安装使用可参考:SSH简介及工作机制以及Ubuntu环境下SSH的安装及使用这两篇文章。

SSH 是一个强大且安全的工具,我们除了可以用它来远程管理主机外,还可以通过它建立 SSH tunnel作 Proxy用,远程传输文件等等。而这里我想要介绍另外一个功能,那就是结合 sshfs 这个工具可以把远程主机的文件系统映射到本地主机上,透过 SSH 把远程文件系统挂载到本机上,这样我们可以不必使用 scp 工具就可以做到直接复制及删除远程主机的文件了,就像操作本地磁盘一样方便。

SSH是连接两台独立计算机,进行远程控制任务的受信任的方式。

SSHFS最炫的地方在于可在本地安装的文件系统中,通过SSH获得所有加密的通信优势。sshfs 是基于 FUSE 构建的 SSH 文件系统客户端程序,通过它远程主机的配置无需作任何改变,就可以透过 SSH 协议来挂载远程文件系统了,非常方便及安全。

 

二、Ubuntu 上安装sshfs

Ubuntu源中已经包含了sshfs,以及所需的fuse包,直接安装即可:

general options:    -o opt,[opt...]        mount options    -h   --help            print help    -V   --version         print versionSSHFS options:    -p PORT                equivalent to '-o port=PORT'    -C                     equivalent to '-o compression=yes' #启用压缩,建议配上    -F ssh_configfile      specifies alternative ssh configuration file #使用非默认的ssh配置文件    -1                     equivalent to '-o ssh_protocol=1' #不要用啊    -o reconnect           reconnect to server               #自动重连    -o delay_connect       delay connection to server    -o sshfs_sync          synchronous writes    -o no_readahead        synchronous reads (no speculative readahead) #提前预读    -o sshfs_debug         print some debugging information    -o cache=BOOL          enable caching {yes,no} (default: yes) #能缓存目录结构之类的信息    -o cache_timeout=N     sets timeout for caches in seconds (default: 20)    -o cache_X_timeout=N   sets timeout for {stat,dir,link} cache    -o workaround=LIST     colon separated list of workarounds             none             no workarounds enabled             all              all workarounds enabled             [no]rename       fix renaming to existing file (default: off)             [no]nodelaysrv   set nodelay tcp flag in sshd (default: off)             [no]truncate     fix truncate for old servers (default: off)             [no]buflimit     fix buffer fillup bug in server (default: on)    -o idmap=TYPE          user/group ID mapping, possible types are:  #文件权限uid/gid映射关系             none             no translation of the ID space (default)             user             only translate UID of connecting user    -o ssh_command=CMD     execute CMD instead of 'ssh'    -o ssh_protocol=N      ssh protocol to use (default: 2) #肯定要2的    -o sftp_server=SERV    path to sftp server or subsystem (default: sftp)    -o directport=PORT     directly connect to PORT bypassing ssh    -o transform_symlinks  transform absolute symlinks to relative    -o follow_symlinks     follow symlinks on the server    -o no_check_root       don't check for existence of 'dir' on server    -o password_stdin      read password from stdin (only for pam_mount)    -o SSHOPT=VAL          ssh options (see man ssh_config)Module options:[subdir]    -o subdir=DIR       prepend this directory to all paths (mandatory)    -o [no]rellinks     transform absolute symlinks to relative[iconv]    #字符集转换,对我这种UTF8控,默认已经是最好的    -o from_code=CHARSET   original encoding of file names (default: UTF-8)    -o to_code=CHARSET      new encoding of the file names (default: UTF-8)

六、总结:在Ubuntu环境下,直接访问网络上其他电脑的文件时由于权限问题,会出现很多问题;最近特别突出的是远程电脑和本地的文件比较,文件夹比较的时候,不能使用工具,极度不方便。使用sshsf将远程电脑上的文件夹挂载到本地以后,不但可以很方便的访问远程文件而且也能使用比较工具将远程文件/文件夹和本地文件/文件夹进行比较。
比如使用beyond Compare时不能将远程文件、文件夹和本地的进行比较。挂载远程文件夹之后,此问题迎刃而解。

热点排行