Is that an alright title? Trying to keep it short. Basically, I want to map files on my server (or any remote computer locally. Specifically, to a folder in my /home.
Here’s the tutorial on how to create your public/private key that I followed: https://help.ubuntu.com/community/SSH/OpenSSH/Keys
Once that’s done, you’ll want to create a folder for your mapped files. In my case, I chose to create /home/www/
to contain directories that match the name of the connection in question; for example, if I want to map a connection to example.com
, I’d create /home/www/example.com/
. And, indeed, I will use that in my example commands below.
So, after creating the directory for your mapping, you’ll also need to copy your ssh key to the remote connection. That’s done using the ssh-copy-id
command. You’ll need to have your username and password handy. The command to run is ssh-copy-id [email protected]
. When it connects, you’ll be prompted to approve of the connection, then the password. If all works, then from terminal, you can ssh [email protected]
and connect without being prompted for your password.
One final prerequisite: If you don’t have sshfs
installed, run sudo apt-get install sshfs
to install it.
So now we’re ready to run the command to connect:
sshfs [email protected]:/home/user/ ~/www/example.com/
To break that down:
-
sshfs
- is the command -
[email protected]
is the user at the domain to which to connect -
:
- colon to add the remote folder to map -
/home/user/
- the remote folder to mount as the local folder (it JUST occurred to me that using~/
might work) -
~/www/example.com/
- whatever local folder you created
Assuming that command succeeds, you should now be able to open ~/www/example.com and see your remote files in Caja or whatever file manager you use.
This connection will last until you reboot.
Now we can step things up a notch. I’ve edited my .bash_aliases
file with a function to make it easier to connect, as follows:
s()
{
if [ "$1" == example.com ]; then
sshfs [email protected]:/home/user/ ~/www/example.com/
elif [ "$1" == example2.com ]; then
sshfs [email protected]:/home/user/ ~/www/example2.com/
else
echo "Site not found in list."
fi
}
Duplicate and update the “elif” line as you add more sites.
That means I can run s example.com
from terminal to connect that site.
Now, I’ve seen places talk about adding things to fstab
to map these connections at startup, but that makes me a little nervous, personally. I haven’t gotten it to work, and frankly, I don’t want to keep all of my sites open permanently, as convenient as it would, admittedly, be.
If you have suggestions/corrections/opinions/etc, please let me know. I will be glad to edit this with better ideas and credit you.