How to use the command sshfs (with examples)

How to use the command sshfs (with examples)

SSHFS is a filesystem client based on SSH. It allows users to securely mount remote directories over SSH. This command provides a convenient way to access files on a remote system as if they were located on the local system.

Use case 1: Mount remote directory

Code:

sshfs username@remote_host:remote_directory mountpoint

Motivation:

Mounting a remote directory using SSHFS allows you to access files stored on a remote system as if they were on your local machine. This can be useful when you need to work with files located on a remote server and want to perform operations on them using local tools.

Explanation:

  • username: The username you use to log in to the remote server.
  • remote_host: The hostname or IP address of the remote server.
  • remote_directory: The directory path on the remote server that you want to mount.
  • mountpoint: The local directory where you want to mount the remote directory.

Example output:

Once the command is executed successfully, the remote directory specified will be mounted on the local machine at the specified mount point. You can then interact with the remote files using local commands or file managers.

Use case 2: Unmount remote directory

Code:

umount mountpoint

Motivation:

Unmounting a remote directory using the umount command allows you to unmount the SSHFS mountpoint and disconnect from the remote system. This can be useful when you no longer need access to the remote files.

Explanation:

  • mountpoint: The local directory where the remote directory is currently mounted.

Example output:

Executing this command will unmount the remote directory from the local machine. Once unmounted, the remote files will no longer be accessible via the mountpoint directory.

Use case 3: Mount remote directory from server with specific port

Code:

sshfs username@remote_host:remote_directory -p 2222

Motivation:

If the remote SSH server is listening on a non-standard port, this command allows you to specify the port number to establish the SSH connection. This is useful when the SSH server is configured to listen on a different port for security or organizational purposes.

Explanation:

  • username: The username you use to log in to the remote server.
  • remote_host: The hostname or IP address of the remote server.
  • remote_directory: The directory path on the remote server that you want to mount.
  • -p 2222: Specifies the port number to use for the SSH connection. Replace 2222 with the actual port number you want to use.

Example output:

After executing this command, the remote directory will be mounted on the local machine as specified. The SSH connection will be established using the specified port number.

Use case 4: Use compression

Code:

sshfs username@remote_host:remote_directory -C

Motivation:

Enabling compression during the SSHFS mount can improve the performance of file transfers between the local and remote systems. This can be beneficial when working with large files or slow network connections.

Explanation:

  • username: The username you use to log in to the remote server.
  • remote_host: The hostname or IP address of the remote server.
  • remote_directory: The directory path on the remote server that you want to mount.
  • -C: Enables compression during the SSHFS mount.

Example output:

When compression is enabled, the file transfer between the local and remote systems will be compressed, resulting in faster transfer times, especially for large files or over slow network connections.

Code:

sshfs -o follow_symlinks username@remote_host:remote_directory mountpoint

Motivation:

When working with remote directories mounted via SSHFS, you might encounter symbolic links that point to other files or directories. Enabling the follow_symlinks option allows you to access the files or directories that the symbolic links point to.

Explanation:

  • -o follow_symlinks: Enables following symbolic links during the SSHFS mount.
  • username: The username you use to log in to the remote server.
  • remote_host: The hostname or IP address of the remote server.
  • remote_directory: The directory path on the remote server that you want to mount.
  • mountpoint: The local directory where you want to mount the remote directory.

Example output:

By enabling the follow_symlinks option, any symbolic links encountered within the remote directory will be followed, allowing you to access and work with the files or directories they point to as if they were local.

Conclusion:

The sshfs command provides a convenient way to mount remote directories over SSH, allowing you to access and work with files on remote systems as if they were on your local machine. Whether you need to access remote files, disconnect from remote systems, specify custom ports, enable compression, or follow symbolic links, sshfs offers a range of useful options to enhance your remote file access experience.

Related Posts

How to use the command "xml-unescape" (with examples)

How to use the command "xml-unescape" (with examples)

In this article, we will explore the xml unescape command, which is part of the XMLStarlet toolkit.

Read More
How to use the command 'sprio' (with examples)

How to use the command 'sprio' (with examples)

The ‘sprio’ command is a Slurm utility that allows users to view the factors determining the scheduling priority of jobs in a Slurm job scheduler.

Read More
How to use the command "siege" (with examples)

How to use the command "siege" (with examples)

Siege is an HTTP loadtesting and benchmarking tool that allows users to test the performance of web servers by simulating multiple concurrent connections.

Read More