Mount Up! How to Mount Remote Server Folders in Ubuntu
Hey there, Ubuntu adventurers! ๐
Ever felt the need to instantly access files from a remote server on your Ubuntu system as if they were right on your local machine? It's like teleporting files, but without the sci-fi stuff. Today, we're going to turn this dream into reality. We're gonna ride into the wild west of Linux and tame ourselves a remote server folder - saddle-free! So, buckle up, we're about to Mount Up!
Install SSHFS - Your trusty mount ๐
SSHFS (SSH File System) is a neat little tool that lets us mount a remote filesystem and interact with it as if it's local. Pretty nifty, right?
Here's the magic spell to conjure it into your system:
sudo apt-get install sshfs
Create a Local Directory ๐
Now that we have our trusty mount (SSHFS), we need a stable to keep it. This is where our remote files will be chilling out once we're connected.
Let's say we call our stable "remote-folder". To create it, simply type:
mkdir ~/remote-folder
The Mounting โฐ๏ธ
It's time! Let's take our horse for a ride. Use the following command, substituting "username", "remote-server-ip", and "remote-folder-path" with your actual details:
sshfs username@remote-server-ip:/remote-folder-path ~/remote-folder
And voila! If everything goes well, you should now have the remote server's folder mounted onto your local Ubuntu system. It's like the remote folder has magically teleported onto your local machine!
Unmounting when Done ๐๏ธ๐
Once you're done rummaging through the files and folders, you might want to unmount the remote server folder. To do this, run:
fusermount -u ~/remote-folder
And that's all, folks! You've successfully mounted a remote server folder on your Ubuntu system. It's like you've just ridden a wild stallion through the unchartered lands of remote file systems. Now, go on, access those files and tame that data!
Just remember, with great power comes great responsibility. So, use this power wisely, and always remember to dismount (unmount) when you're done! ๐ค
How do I keep my mountings intact even after a server reboot?
Just like the mythical Phoenix that arises from its ashes, we'd love for our mount points to spring back to life after a system restart, wouldn't we?
Well, I have good news for you! We're gonna use a tool called "fstab" for this. Think of it as a resurrection spell for our mountings. A word of caution, though, this tool is pretty powerful, so we need to use it wisely.
Update /etc/fstab ๐
The /etc/fstab file is like the system's personal diary of disk space. It keeps track of all our filesystems and how they should be automatically mounted. This is where we'll tell our system to remember our SSHFS mount point.
To start off, we'll open the fstab file with a text editor. We'll use nano here, but feel free to use your favorite one:
sudo vi /etc/fstab
Scroll down to the bottom of this file. Here, we'll add a new line for our mount point. It should look something like this:
sshfs#username@remote-server-ip:/remote-folder-path /local-folder-path fuse defaults 0 0
Of course, you'll replace the placeholders with your actual details.
Install and Set Up the AutoSSH ๐๏ธ
AutoSSH is our knight in shining armor that will maintain and re-establish SSH connections if they drop. Let's get it installed:
sudo apt-get install autossh
Once installed, we need to create a RSA key pair to enable passwordless login:
ssh-keygen -t rsa
You can press enter to accept the defaults. It'll create a new RSA key pair with no passphrase.
Now, let's copy our public key to the remote server:
ssh-copy-id username@remote-server-ip
Replace username and remote-server-ip with your details. It'll ask for your password, and after entering it, your public key will be copied to the remote server.
Test the Setup ๐งช
Alright, it's time to test if everything's working:
sudo mount -a
This command will attempt to mount all the filesystems mentioned in /etc/fstab.
If everything's been set up correctly, your SSHFS mount should survive through reboots just like a majestic Phoenix!๐ฅ๐ฆ
Remember, with great power comes even greater responsibility! The fstab file is a crucial part of your system. Handle it with care, and always make sure to test your new setup before relying on it!
Happy trails, adventurer! Until the next tech quest. ๐ค ๐