在 Ubuntu 上使用 sshfs 映射远程 ssh 文件系统为本地磁盘

install sshfs

sudo apt-get install sshfs
sudo modprobe fuse
sudo adduser apuser fuse
sudo chown root:fuse /dev/fuse

Now, assuming that you have an SSH server running on a remote machine, simply run the SSHFS command to mount the remote directory. In this example, the remote directory is /home/wenyang/ on remote host 10.0.128.67. The local mount point is `/home/apuser/67/`.

sshfs -o idmap=user [email protected]:/home/wenyang/ /home/apuser/67/
or

sshfs [email protected]:/home/wenyang/work /home/apuser/67

To unmount

fusermount -u ~/67

To add it to your /etc/fstab

sshfs#[email protected]:/home/wenyang/ /home/apuser/67 fuse defaults,idmap=user 0 0

Note that you have to change $USER to your login name when editing fstab, but it is not necessary when typing commands (the shell does it for you in that case). One thing to be aware of is that your UID (User ID, the unique number of your user on a system) is not necessarily the same on the two hosts. When you ls -l, the user name associated with each file is printed in the third column. However, in the filesystem, only UIDs are stored, and ls simply looks up the UID and finds the user name associated with it. In Unix, UIDs are what matter, not the user names. So if you're 1000 on the local host and 1003 on the remote host, the sshfs mounted directory would show a different user name for your files. This is not a problem, though, because the ssh server on the remote machine is what is actually reading and writing files. So even though it shows up in ls -l as a different UID, any changes will be done through the ssh server on the remote host, which will use the correct UID for the remote machine. Problems may arise if you attempt to use a program that looks at UIDs of files (e.g. ls prints the wrong user name). The `idmap=user` option ensures that files owned by the remote user are owned by the local user. If you don't use `idmap=user`, files in the mounted directory might appear to be owned by someone else, because your computer and the remote computer have different ideas about the numeric user ID associated with each user name. `idmap=user` will not translate UIDs for other users.



你可能感兴趣的:(在 Ubuntu 上使用 sshfs 映射远程 ssh 文件系统为本地磁盘)