Use SSHFS to mount remote directories locally (as with Windows mount disks) under Ubuntu

Source: Internet
Author: User

Access to other Ubuntu machines in the LAN, jumping between different machines, is a hassle, if you can map the remote directory to the local will undoubtedly be used greatly, just like the network map disk under Windows. In the world of Linux there will undoubtedly be this mechanism and the way, recently in the process of using the SSHFS this tool to achieve the remote directory mapping to local functions.

SSHFS can gain all the encrypted communication benefits via SSH in a locally installed file system. Using SSHFS can map remote directory directly to the local, without modifying the remote machine settings, only require the SSH connection permissions (SSH is not, what can you do?)

Website address: http://fuse.sourceforge.net/sshfs.html

one, SSHFS for Ubuntu

Let's start with a brief introduction to SSHF.

About SSH introduction and installation use can refer to: SSH introduction and working mechanism as well as the Ubuntu environment in the installation and use of SSH in these two articles.

SSH is a powerful and secure tool, we can use it in addition to remote management of the host, but also through it to establish SSH tunnel for proxy, remote transfer files and so on. And here I want to introduce another feature, that is, the combination of SSHFS this tool can map the remote host file system to the local host, through SSH to the remote file system to mount to the computer, so that we can not use the SCP tool can be used to directly copy and delete the remote host files, It's as easy as working on a local disk.

SSH is a trusted way to connect two independent computers for remote control tasks.

The best thing about SSHFS is that you can get all the encrypted communication benefits through SSH in a locally installed file system. SSHFS is a FUSE-based SSH file system client program that can be used to mount remote file systems through the SSH protocol without any changes to the remote host configuration, which is very convenient and secure.

Second, install SSHFS on Ubuntu

The Ubuntu source already contains the SSHFS, as well as the required fuse packs, which can be installed directly:

[HTML]View PlainCopy
    1. sudo apt-get install SSHFS



The user group fuse is created automatically when installing, and users who want to use SSHFS need to add to this user group first (remember to log in again after completion), otherwise they will not have permission to execute Fusermount:

Fuse:failed to exec Fusermount:permission denied

Third, Mount remote file System/directory

The general format for mounting is:

[HTML]View PlainCopy
    1. sudo sshfs {{user id}}@{{server Hostname}}:{{desiredremote share}} {{desired local mount point}}-o idmap=user-o Allow_other -ouid={{local User ID}}-o gid={{local Group ID}}



Among the key options:

-O Transform_symlinks represents the conversion of absolute link symbols to relative link symbols

-O follow_symlinks Follow the link symbols on the server

-C compression, or-O Compression=yes

-O Reconnect automatic re-connection

-O Cache=yes

-O Allow_other

The mount format looks more dizzy, here combined with my use gives a concise and intuitive format:

[HTML]View PlainCopy
    1. Sshfs-o transform_symlinks-ofollow_symlinks [email protected]: [Dir]mountpoint



Examples are as follows:

[HTML]View PlainCopy
    1. Sshfs–o cache=yes,allow_other [email protected]:/home/user/code home/user/code



Description

1, the connection may require administrator rights, in the Mount command before Sudo can.

2, more parameters please man SSHFS, if you encounter other problems, please refer to the official FAQ.

3, if you want to not enter the password, you can use the SSH key authentication method.

4. After executing the command, Ubuntu will automatically display the mounted SSHFS file system disk on the desktop, and now you can manipulate the mapped disk as if it were a local disk.

Iv. Unloading

Fusemount–u/home/user/code

v. SSHFS Options [HTML]View PlainCopy
  1. General Options:
  2. -O opt,[opt ...] Mount Options
  3. -H--help Print help
  4. -V--version print version
  5. SSHFS options:
  6. -p port equivalent to '-O port=Port '
  7. -c equivalent to ' -o compression=yes ' #启用压缩, recommended with
  8. -F ssh_configfile Specifies alternative ssh configuration file #使用非默认的ssh配置文件
  9. -1 equivalent to '-O ssh_protocol=1 ' #不要用啊
  10. -O Reconnect reconnect to server #自动重连
  11. -O delay_connect delay connection to server
  12. -O Sshfs_sync Synchronous writes
  13. -O no_readahead Synchronous reads (no speculative readahead) #提前预读
  14. -O sshfs_debug Print Some debugging information
  15. -o cache=BOOL enable caching {Yes,no} (default:yes) #能缓存目录结构之类的信息
  16. -o cache_timeout=N sets timeout for caches in seconds (default:20)
  17. -O cache_x_timeout=N sets timeout for {stat,dir,link} cache
  18. -O workaround=list Colon separated list of workarounds
  19. None Workarounds Enabled
  20. All workarounds Enabled
  21. [No]rename fix renaming to existing file (Default:off)
  22. [No]nodelaysrv set Nodelay TCP flag in sshd (Default:off)
  23. [No]truncate fix truncate for old servers (Default:off)
  24. [no]buflimit Fix buffer FillUp bug in Server (Default:on)
  25. -o idmap=TYPE user/group ID mapping, possible types is: #文件权限uid/gid mapping Relationship
  26. None translation of the ID space (default)
  27. User only translate UID of connecting user
  28. -O ssh_command=cmd execute cmd instead of ' ssh '
  29. -o ssh_protocol=N SSH protocol to use (Default:2) #肯定要2的
  30. -o sftp_server=SERV path to SFTP server or subsystem (DEFAULT:SFTP)
  31. -O directport=port directly connect to port bypassing SSH
  32. -O transform_symlinks transform absolute symlinks to relative
  33. -O follow_symlinks follow symlinks on the server
  34. -O no_check_root don ' t check for existence of ' dir ' on server
  35. -O password_stdin read password from stdin (only for Pam_mount)
  36. -o sshopt=VAL ssh options (see Mans Ssh_config)
  37. Module options:
  38. [SubDir]
  39. -o subdir=DIR prepend This directory to all paths (mandatory)
  40. -O [no]rellinks transform absolute symlinks to relative
  41. [Iconv]
  42. #字符集转换, for my kind of UTF8, the default is already the best
  43. -o from_code=CHARSET Original encoding of file names (default:utf-8)
  44. -o to_code=CHARSET New encoding of the file names (default:utf-8)
Vi. Summary: In the Ubuntu environment, direct access to other computer files on the network due to permissions problems, there will be a lot of problems; Recently, especially highlighted is the remote computer and local file comparison, folder comparison, can not use tools, extremely inconvenient. Using SSHSF to attach a folder on a remote computer to a local location, you can easily access remote files and compare remote files/folders to local files/folders using the Diff tool. such as using Beyond CompareYou cannot compare remote files, folders, and local. This problem is resolved after mounting the remote folder. http://blog.csdn.net/netwalk/article/details/12952719

Use SSHFS to mount remote directories locally (as with Windows mount disks) under Ubuntu

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.