SSH is a powerful and secure tool. In addition to using it to remotely manage hosts, we can also use it to establish an SSH tunnel as a proxy, remotely transfer files, and so on. And here I want to introduce another function, which is to combine the sshfs tool to map the file system of the remote host to the local host, and mount the remote file system to the local host through SSH, so that we don’t need to use the scp tool You can copy and delete files on the remote host directly, just as convenient as operating a local disk.
The most dazzling part of SSHFS is that it can be installed locally in the file system, through SSH to obtain all the advantages of encrypted communication. sshfs is an SSH file system client program based on FUSE. With it, the remote host configuration can be mounted via the SSH protocol without any changes, which is very convenient and safe.
Github address: https://github.com/libfuse/sshfs
1. Install EPEL extension source
[ root@tokyo /]# rpm -Uvh http://ftp.iij.ad.jp/pub/linux/centos/7/extras/x86_64/Packages/epel-release-7-9.noarch.rpm
2. Clean up YUM cache
[ root@tokyo /]# yum clean all
3. Use YUM to install SSHFS
[ root@tokyo /]# yum install fuse-sshfs
Four, mount remote directory
[ root@tokyo /]# sshfs -o port=2200 [email protected]:/data/tmp /tmp
[email protected]'s password:
[ root@tokyo /]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 993M 0 993M 0%/dev
tmpfs 1000M 0 1000M 0%/dev/shm
tmpfs 1000M 8.5M 991M 1%/run
tmpfs 1000M 0 1000M 0%/sys/fs/cgroup
/dev/sda1 30G 6.2G 22G 23% /
tmpfs 200M 0 200M 0%/run/user/0
[email protected]:/data/tmp 30G 5.6G 23G 20%/tmp
Five, uninstall the remote directory
The unloading method is the same as the mount method, which uses umount. (The information I found is useful to fusermount -u mount_point
)
[ root@tokyo /]# umount /tmp
general options:-o opt,[opt...] mount options
- h --help print help
- V --version print version
SSHFS options:-p PORT equivalent to '-o port=PORT' #Specify the ssh connection port
- C equivalent to '-o compression=yes' #Enable compression,It is recommended to match
- F ssh_configfile specifies alternative ssh configuration file #Use a non-default ssh configuration file
- 1 equivalent to '-o ssh_protocol=1' #Not recommended
- o reconnect reconnect to server #Auto reconnect
- o delay_connect delay connection to server
- o sshfs_sync synchronous writes
- o no_readahead synchronous reads(no speculative readahead) #Read ahead
- o sshfs_debug print some debugging information
- o cache=BOOL enable caching {yes,no}(default: yes) #Can cache information such as directory structure
- o cache_timeout=N sets timeout for caches inseconds(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 insshd(default: off)[no]truncate fix truncate for old servers(default: off)[no]buflimit fix buffer fillup bug inserver(default: on)-o idmap=TYPE user/group ID mapping, possible types are: #File permission uid/gid mapping
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) #Definitely 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 fromstdin(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]
# Character set conversion,UTF8 control for me,The default is already the best
- o from_code=CHARSET original encoding of file names(default: UTF-8)-o to_code=CHARSET newencodingof the file names(default: UTF-8)
Recommended Posts