Skip to content
Blog How To Mount a Remote hard drive on an Ubuntu server

How To Mount a Remote hard drive on an Ubuntu server

If you want to mount a remote hard drive on an AWS Ubuntu instance, you can use the SSHFS (SSH File System) utility. SSHFS allows you to mount a remote file system over SSH, making it accessible as if it were a local drive. Here’s how you can do it:

1. Install SSHFS on your AWS Ubuntu instance. Open a terminal and run the following command:

sudo apt update
sudo apt install sshfs

2. Create a directory where you want to mount the remote hard drive. For example, you can create a directory named “remote” in the root (`/`) directory by running the command:

sudo mkdir /remote

3. Mount the remote hard drive using SSHFS. Run the following command, replacing `username` with your remote server’s username, `remote_host` with the IP address or hostname of the remote server, and `/path/to/remote/drive` with the actual path to the remote hard drive:

sudo sshfs -o allow_other username@remote_host:/path/to/remote/drive /remote

If you have an SSH key configured for passwordless authentication, you can use the `-i` option followed by the path to the private key file.

For example:

sudo sshfs -o allow_other -i /path/to/private_key username@remote_host:/path/to/remote/drive /remote

4. Provide your remote server’s password or SSH key passphrase when prompted.

5. Verify that the remote hard drive is mounted. You can use the `df -h` command to see a list of mounted file systems and their usage information. Look for the entry that corresponds to your remote hard drive mounted at the specified directory (`/remote` in this example).

6. Access the remote hard drive. You can now access the files on the remote hard drive through the `/remote` directory on your AWS Ubuntu instance.

7. To ensure a persistent and stable SSHFS connection, you can set options for keeping the connection alive and automatically reconnecting in case of disconnects. Here’s how you can achieve that:

sudo sshfs -o allow_other -o ServerAliveInterval=60 -o ServerAliveCountMax=5 -o reconnect username@remote_host:/path/to/remote/drive /remote

This option specifies the number of seconds between keep-alive messages that will be sent to the remote server. In this example, a keep-alive message will be sent every 60 seconds.

This option specifies the maximum number of keep-alive messages that can be sent without receiving a response from the remote server. If the remote server does not respond within the given count, the SSHFS connection will be closed.

This option tells SSHFS to automatically reconnect if the connection is lost.

To unmount the remote hard drive when you’re finished, you can use the following command:

sudo umount /remote

Remember to replace `/remote` with the actual mount point directory you used.

With SSHFS, you can mount a remote hard drive securely and easily access its contents on your AWS Ubuntu instance.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.