Mount remote directory linux

Mount remote directory using SSH

Now we’ll create a directory to mount the remote folder in.

I chose to create it in my home directory and call it remoteDir .

Now I ran the command to mount it (mount on home):

sshfs maythux@192.168.xx.xx:/home/maythuxServ/Mounted ~/remoteDir 

I’m a little confused. in the sshfs command, I think that the mountpoint local directory is named remoteDir , and when I’m on the ssh serever, there is a dir /home/maythuxServ/Mounted that is not mounted locally, and I can not tell, or care, whether it’s mounted elsewhere?

I skipped some of these steps under 14.04 when I used the following guide: help.ubuntu.com/community/SSHFS

Configure ssh key-based authentication

Generate key pair on the local host.

Accept all sugestions with enter key.

Copy public key to the remote host:

$ ssh-copy-id -i .ssh/id_rsa.pub user@host 

Install sshfs

Mount remote directory

$ sshfs user@host:/remote_directory /local_directory 

Don’t try to add remote fs to /etc/fstab

Or don’t try to mount shares via /etc/rc.local .

In both cases it won’t work as the network is not available when init reads /etc/fstab.

Install AutoFS

Edit /etc/auto.master

Comment out the following lines

#+/etc/auto.master.d #+/etc/auto.master 

Edit /etc/auto.sshfs

/local_directory -fstype=fuse,allow_other,IdentityFile=/local_private_key :sshfs\#user@remote_host\:/remote_directory 

Remote user name is obligatory.

Start autofs in debug mode

$ sudo service autofs stop $ sudo automount -vf 

Observe logs of the remote ssh server

$ ssh user@remote_server $ sudo tailf /var/log/secure 

Check content of the local directory

You should see contents of the remote directory

Читайте также:  Boot modes in linux

Start autofs in normal mode

Stop AutoFS running in debug mode with CTRL-C .

Start AutoFS in normal mode

$ sudo service autofs start 

Still good on Ubuntu 18.04. Used it to mount a directory from a Raspberry Pi 2 on a PC. When issuing sudo automount -vf , if you get 1 remaining in /- it is likely because you have already manually mounted the directory at step Mount remote directory . Rebooting should fix the issue.

Based on my experiments, explicitly creating the fuse group and adding your user to it is NOT required to mount ssh file system.

To summarize, here are the steps copied from this page:

$ sudo apt-get install sshfs

2.Create local mount point

3.Mount remote folder /remote/path to /home/johndoe/sshfs-path/

$ sshfs remoteuser@111.222.333.444:/remote/path /home/johndoe/sshfs-path/

$ fusermount -u /home/johndoe/sshfs-path/

sudo apt-get install sshfs

@:  fuse.sshfs delay_connect,_netdev,user,idmap=user,transform_symlinks,identityfile=/home//.ssh/id_rsa,allow_other,default_permissions,rw,nosuid,nodev,uid=1000,gid=1000,nonempty 0 0 

Although it is not answering your question exactly but I just wanted to mention that you can achieve the same goal using «sftp» as well. Just inside your file manager address bar type this command:

sftp://remoteuser@111.222.333.444/remote/path 

An easy way to run sshfs mounts at startup is also by adding it to the root (or another user’s) crontab, like this:

@reboot sshfs remoteuser@111.222.333.444:/remote/path /home/johndoe/sshfs-path/ 

And if you need to add a delay, you can use:

@reboot sleep 60 && sshfs remoteuser@111.222.333.444:/remote/path /home/johndoe/sshfs-path/ 

I would like to warn that, it seems that by default only the user which set up the mount can access the remote directory.

I set up a remote directory, and create a crontab with sudo crontab -e . Later I found out the backup file didn’t write the remote directory at all. Then I found out that I could not cd into the remote disk as root ! So eventually I create the same task with crontab -e and everything works as I expected.

Читайте также:  Zip архиватор astra linux

Источник

How to Mount Remote Directory or Filesystem in Linux

mount remote folder in linux

Sometimes you may need to mount remote directory or filesystem in Linux. In this article, we will learn how to do this using SSHFS client over SSH. You can use these steps to mount remote folders on their local system.

What is SSHFS?

SSHFS stands for Secure Shell Filesystem that allows you to mount remote folders and filesystems via local machine and access them via SFTP (Secure File Transfer Protocol). It comes with FUSE (Filesystem in Userspace) that allows anyone to securely create their filesystem without modifying kernel code.

How to Mount Remote Directory or Filesystem in Linux

Here are the steps to mount remote directory or filesystem in Linux.

1. Install SSHFS Client in Linux Systems

By default, sshfs is not present on most Linux distributions. Open terminal and run the following command to install SSHFS on your system. Here are the commands to install SSHFS on different Linux systems.

# yum install sshfs # dnf install sshfs [On Fedora 22+ releases] $ sudo apt-get install sshfs [On Debian/Ubuntu based systems]

2. Create SSHFS Mount Directory

Once SSHFS is installed, you need to create a mount point for your folder, where you will mount the remote folder. Here is the command to create mount point at /mnt/test

# mkdir /mnt/test $ sudo mkdir /mnt/test [On Debian/Ubuntu based systems]

3. Mount Remote Folder

Once you have created mount point for your folder, run the following command to mount the remote folder as root. We will mount remote folder /home/test to local folder /mnt/test. Replace x.x.x.x with the IP address of your remote folder. Replace test_user with your remote username. Replace /home/test with the location of your remote folder.

# sshfs test_user@x.x.x.x:/home/test/ /mnt/test $ sudo sshfs -o allow_other test@x.x.x.x:/home/test/ /mnt/test [On Debian/Ubuntu based systems]

If your Linux server is configured with key-based authorization, then you will need to specify path to public keys.

# sshfs -o IdentityFile=~/.ssh/id_rsa test_user@x.x.x.x:/home/test/ /mnt/test $ sudo sshfs -o allow_other,IdentityFile=~/.ssh/id_rsa test@x.x.x.x:/home/test/ /mnt/test [On Debian/Ubuntu based systems]

4. Verify Remote Filesystem is Mounted

Once you have successfully mounted the remote folder, you can access it as if it is a local directory and view its contents.

Читайте также:  Настроить переключение языка linux

Alternatively, you can check the mount point by check if it is listed when you run df command.

5. Mount Remote Filesystem Permanently

The above steps will mount remote filesystem only until the next reboot. If you want to permanently mount remote folder, then you need to open the file /etc/fstab in a text editor.

# vi /etc/fstab $ sudo vi /etc/fstab [On Debian/Ubuntu based systems]

Add the following line to the bottom of the file. Replace test_user with your remote username, x.x.x.x with remote folder’s IP address, /home/test with remote folder location and /mnt/test with the local mount point of remote folder.

sshfs#test_user@x.x.x.x:/home/test/ /mnt/test fuse.sshfs defaults 0 0

If your SSH is configured to use key-based authentication, add the following command instead of above command, specifying the key location.

sshfs#test@x.x.x.x:/home/test/ /mnt/test fuse.sshfs IdentityFile=~/.ssh/id_rsa defaults 0 0

Save and exit the file. Run the following command to mount the file.

# mount -a $ sudo mount -a [On Debian/Ubuntu based systems]

6. Unmount Filesystem

If you want to unmount the remote folder, run the following command.

In this article, we have learnt how to mount remote filesystem in Linux.

Источник

Оцените статью
Adblock
detector