Ubuntu 22.04 SSHFS: Difference between revisions
Created page with "==Introduction== SSHFS (Secure SHell FileSystem) is a file system that allows you to mount a remote file system over a secure SSH connection. This allows you to access files and directories on a remote server as if they were local files on your own machine. This guide will walk you through the process of installing SSHFS on Ubuntu and using it to mount a remote file system. ==Install SSHFS== <code>sudo apt-get install sshfs</code> ==Create a mount point== You will n..." |
(No difference)
|
Latest revision as of 19:48, 11 May 2023
Introduction
SSHFS (Secure SHell FileSystem) is a file system that allows you to mount a remote file system over a secure SSH connection. This allows you to access files and directories on a remote server as if they were local files on your own machine. This guide will walk you through the process of installing SSHFS on Ubuntu and using it to mount a remote file system.
Install SSHFS
sudo apt-get install sshfs
Create a mount point
You will need to create a directory on your local machine that will be used as the mount point for the remote file system. You can create a directory in your home directory using the following command:
mkdir ~/remote_mount
Mount the remote file system
To mount the remote file system, you will need to use the sshfs command in the following format:
sshfs <username>@<remote_server>:<remote_directory> <local_mount_point>
Replace <username> with your username on the remote server, <remote_server> with the IP address or hostname of the remote server, <remote_directory> with the directory you want to mount on the remote server, and <local_mount_point> with the local mount point you created in the previous step.
For example, if you want to mount the directory /home/user/files on the remote server with the IP address 192.168.1.100 using your username user and the local mount point ~/remote_mount, you would run the following command:
sshfs user@192.168.1.100:/home/user/files ~/remote_mount
You will be prompted for the password for the remote server.
Access the remote files
Once you have mounted the remote file system, you can access the files and directories on the remote server as if they were local files on your own machine. You can use your file manager to browse the files, or you can use the terminal to navigate to the mount point and use standard command-line tools to work with the files.
IdentityFile - aka ssh-key
To use the IdentityFile option with SSHFS, you can add it to the command when you mount the remote file system.
The IdentityFile option allows you to specify the path to the private key file that you want to use for authentication. This can be useful if you have multiple SSH keys, or if you want to use a specific key for a particular connection.
Here's an example of how you can use the IdentityFile option with SSHFS:
sshfs -o IdentityFile=/path/to/private/key <username>@<remote_server>:<remote_directory> <local_mount_point>
Replace /path/to/private/key with the path to the private key file that you want to use, <username> with your username on the remote server, <remote_server> with the IP address or hostname of the remote server, <remote_directory> with the directory you want to mount on the remote server, and <local_mount_point> with the local mount point you created in the previous step.
For example, if you have a private key file called mykey.pem in your home directory, and you want to use it to mount the directory /home/user/files on the remote server with the IP address 192.168.1.100 using your username user and the local mount point ~/remote_mount, you would run the following command:
sshfs -o IdentityFile=$HOME/mykey.pem user@192.168.1.100:/home/user/files ~/remote_mount
This will mount the remote file system using the specified private key file for authentication.
Options to customize sshfs behavior
- allow_other: This option allows other users to access the mounted file system. By default, only the user who mounted the file system can access it. You can use this option by adding -o allow_other to the sshfs command.
- default_permissions: This option enables the use of default file permissions when accessing the mounted file system. By default, all files and directories on the mounted file system are owned by the user who mounted it, and are not accessible by other users. You can use this option by adding -o default_permissions to the sshfs command.
- reconnect: This option enables automatic reconnection to the remote server if the connection is lost. You can use this option by adding -o reconnect to the sshfs command.
- cache: This option enables caching of file attributes and directory entries, which can improve performance. You can use this option by adding -o cache=yes to the sshfs command.
- transform_symlinks: This option allows you to specify whether symbolic links should be resolved on the local or remote machine. You can use this option by adding -o transform_symlinks to the sshfs command.
- ssh_command: This option allows you to specify a custom SSH command to use for the connection. You can use this option by adding -o ssh_command="<command>" to the sshfs command, where <command> is the custom SSH command you want to use.
Here's an example of how you can use some of these options with SSHFS:
sshfs -o allow_other,default_permissions,reconnect,cache=yes,transform_symlinks,ssh_command="ssh -p 2222" <username>@<remote_server>:<remote_directory> <local_mount_point>
This command will mount the remote file system with the specified options, including allowing other users to access it, using default permissions, enabling automatic reconnection, caching file attributes and directory entries, transforming symbolic links, and using a custom SSH command to connect to the remote server on port 2222.
Unmount the remote file system
When you are finished working with the remote files, you can unmount the remote file system using the following command:
fusermount -u <local_mount_point>
Replace <local_mount_point> with the local mount point you used to mount the remote file system.
For example, to unmount the remote file system mounted at ~/remote_mount, you would run the following command:
fusermount -u ~/remote_mount