Linux mount directory from another server

How to Mount Remote Linux Filesystem or Directory Using SSHFS Over SSH

The main purpose of writing this article is to provide a step-by-step guide on how to mount remote Linux file system using SSHFS client over SSH.

This article is useful for those users and system administrators who want to mount remote file system on their local systems for whatever purposes. We have practically tested by installing SSHFS client on one of our Linux system and successfully mounted remote file systems.

Before we go further installation let’s understand about SSHFS and how it works.

Sshfs Mount Remote Linux Filesystem or Directory

What Is SSHFS?

SSHFS stands for (Secure SHell FileSystem) client that enable us to mount remote filesystem and interact with remote directories and files on a local machine using SSH File Transfer Protocol (SFTP).

SFTP is a secure file transfer protocol that provides file access, file transfer and file management features over Secure Shell protocol. Because SSH uses encryption while transferring files over the network from one computer to another computer and SSHFS comes with built-in FUSE (Filesystem in Userspace) kernel module that allows any non-privileged users to create their file system without modifying kernel code.

In this article, we will show you how to install and use SSHFS client on any Linux distribution to mount remote Linux filesystem or directory on a local Linux machine.

Step 1: Install SSHFS Client in Linux Systems

By default sshfs packages does not exists on all major Linux distributions, you need to enable epel repository under your Linux systems to install sshfs with the help of Yum command with their dependencies.

Step 2: Creating SSHFS Mount Directory

Once the sshfs package installed, you need to create a mount point directory where you will mount your remote file system. For example, we have created mount directory under /mnt/tecmint .

Step 3: Mounting Remote Filesystem with SSHFS

Once you have created your mount point directory, now run the following command as a root user to mount remote file system under /mnt/tecmint . In your case the mount directory would be anything.

The following command will mount remote directory called /home/tecmint under /mnt/tecmint in local system. (Don’t forget replace x.x.x.x with your IP Address and mount point).

If your Linux server is configured with SSH key based authorization, then you will need to specify the path to your public keys as shown in the following command.

Step 4: Verifying Remote Filesystem is Mounted

If you have run the above command successfully without any errors, you will see the list of remote files and directories mounted under /mnt/tecmint .

Читайте также:  Ocz vertex windows driver

Step 5: Checking Mount Point with df -hT Command

If you run df -hT command you will see the remote file system mount point.

Sample Output

Step 6: Mounting Remote Filesystem Permanently

To mount remote filesystem permanently, you need to edit the file called /etc/fstab . To do, open the file with your favorite editor.

Go to the bottom of the file and add the following line to it and save the file and exit. The below entry mount remote server file system with default settings.

Make sure you’ve SSH Passwordless Login in place between servers to auto mount filesystem during system reboots..

If your server is configured with SSH key based authorization, then add this line:

Next, you need to update the fstab file to reflect the changes.

Step 7: Unmounting Remote Filesystem

To unmount remote filesystem, jun issue the following command it will unmount the remote file system.

That’s all for now, if you’re facing any difficulties or need any help in mounting remote file system, please contact us via comments and if you feel this article is much useful then share it with your friends.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

How to Mount a Linux directory from a different PC to your local Linux PC?

Is there a way to mount a Linux directory from a different PC to your local Linux PC? How?

5 Answers 5

sshfs is very nice, and easy to use

Yes, it’s called NFS. You might also want to check out sshfs which is pretty nice.

You need to be a bit more specific. You can use NFS.

Depending on what distro you’re using, you simply edit the /etc/exports file on the remote machine to export the directories you want, then start your NFS daemon.

Then on the local PC, you mount it using the following command:

Use the man utility for more information:

man exports (Examples of configuring directories for export are on the bottom of this manual page.)

NFS is handy since it’s built-in and easy to configure, but the 2 common implementations (NFSv2 and NFSv3) don’t translate usernames between the systems; user IDs are used instead. This requires you to use a central auth system such as LDAP so tha tcommon user IDs can be maintained.

sshfs requires you to connect as a single user and so accesses are always done (and consequently, can only be done) as that user.

cifs in a *nix-to-*nix connection (via Samba) both translates usernames and follows standard *nix permissions. As well, it is more flexible in that it allows you to perform ownership/permission transformation on creation of a new file or directory. It is, however, much more complex to configure.

Источник

Best way to mount remote folder

I have two RasberryPi running debian wheezy and I would like to mount a folder from computer A on computer B.

What is the best (as in most efficient) way to do this?

I can do it via SMB, but that is for windows, I think there must be a better way to share across linux.

4 Answers 4

SSHFS is wonderful. It can mount remote directories in a local directory with FUSE. The commands below use # to indicate that a command was executed as root , while $ indicates execution as a regular user. Because FUSE software is required, first make sure that it is available and running.

Читайте также:  Сброс планшета asus windows

One of the lsmod and grep commands, below, can reveal if the software is loaded and ready for use. A result from either command indicates that fuse is available.

If there is no result from either command, try to load the kernel module without a reboot using modprobe and check again.

If loading the module fails, install the software with apt-get .

Check again after installation.

FUSE must be installed and running before continuing.

Check the permissions of /dev/fuse . The permissions should provide your regular user account with read and write access. Skip this part if you have determined that your regular user account already has read and write permission on /dev/fuse .

The output might be something like one of the following.

In 2013, my Debian created /dev/fuse with 0600 permissions, owner root , group owner fuse . I needed to let the fuse group use the device and to add my regular user account to the group, as shown below.

If the new group membership was required, log out and in again to become a member of the group.

Next, install ssh on both sides as follows.

This answer was written for Debian, but on Ubuntu 18.x at least, openssh-client , fuse , and a few other packages are a part of the Ubuntu sshfs package. The sshfs software is required on the client side, but it can be installed on both sides if desired. One of the package dependencies is fuse , but the installer skips over software that has already been installed.

With fuse and ssh available, and with permission to use the device, /dev/fuse , create a mount point for the remote file system; and, mount that remote filesystem locally as follows.

To mount a directory other than home, specify it after the colon.

To unmount, use fusermount .

If you have a Windows machine, it too can use SSHFS with win-sshfs. This software will «map a drive» with SSHFS, so that you can have a Windows drive letter that contains the remote directory.

Источник

Mount remote directory using SSH

How to mount a remote directory using SSH to be available same as if it is a local directory?

7 Answers 7

First install the module:

Load it to kernel:

Setting permissions (Ubuntu versions remoteDir .

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

Now it should be mounted:

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:

Install sshfs

Mount remote 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

Edit /etc/auto.sshfs

Remote user name is obligatory.

Start autofs in debug mode

Observe logs of the remote ssh server

Check content of the local directory

You should see contents of the remote directory

Start autofs in normal mode

Stop AutoFS running in debug mode with CTRL-C .

Start AutoFS in normal mode

Enjoy

(Tested on Ubuntu 14.04)

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

Читайте также:  Все для apple mac os

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:

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

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

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.

Not the answer you’re looking for? Browse other questions tagged mount ssh sshfs or ask your own question.

Linked

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.10.8.40416

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

Как в Linux монтировать шару CIFS

Что такое Linux и CIFS простыми словами.

Работа с общими папками Windows происходит с использованием протокола CIFS (SMB). Все примеры в данном руководстве выполняются на Linux Ubuntu и CentOS.

Подготовка

Установка пакетов

Для монтирования общей папки необходимо установить набор утилит для работы с CIFS.

yum install cifs-utils

apt-get install cifs-utils

Сетевые порты

Если мы будем монтировать сетевую папку, сервер которой находится за брандмауэром, необходимо открыть следующие порты:

Синтаксис

* вместо mount.cifs можно написать mount -t cifs.

mount.cifs //192.168.1.1/public /mnt

* простой пример монтирования папки public на сервере 192.168.1.1 в локальный каталог /mnt.

Ручное монтирование

Теперь монтирование можно выполнить следующей командой:

mount.cifs //192.168.1.10/share /mnt -o user=dmosk

* в данном примере будет примонтирован каталог share на сервере 192.168.1.10 в локальную папку /mnt под учетной записью dmosk.

То же самое, с использованием домена:

mount.cifs //192.168.1.10/share /mnt -o user=dmosk,domain=dmosk.local

Автоматическое монтирование CIFS через fstab

Для начала создаем файл, в котором будем хранить данные авторизации при подключении к общей папке:

И добавляем в него данные следующего вида:

username=dmosk
password=dPassw0rd
domain=dmosk.local

* в этом примере создана пара логин/пароль — dmosk/dPassw0rd; domain указывать не обязательно, если аутентификация выполняется без него.

Теперь открываем конфигурационный файл fstab:

и добавляем в него следующее:

//192.168.1.10/share /mnt cifs user,rw,credentials=/root/.smbclient 0 0

* в данном примере выполняется монтирование общей папки share на сервере с IP-адресом 192.168.1.10 в каталог /mnt. Параметры для подключения — user: позволяет выполнить монтирование любому пользователю, rw: с правом на чтение и запись, credentials: файл, который мы создали на предыдущем шаге.

Чтобы проверить правильность настроек, вводим следующую команду:

Примеры использования опций

Версии SMB

Если на стороне Windows используется старая или слишком новая версия протокола SMB, при попытке монтирования мы можем получить ошибку mount error(112): Host is down. Чтобы это исправить, указываем версию:

mount.cifs //192.168.1.10/share /mnt/ -o vers=1.0

* монтирование по протоколу SMB1.0

Монтирование от гостевой учетной записи

Если сервер принимает запросы без логина и пароля, то клиент подключается, как гость:

mount.cifs //192.168.1.10/share /mnt -o guest

//192.168.1.10/share /mnt cifs guest 0 0

Права на примонтированные каталоги

При монтировании папки мы можем указать определенные права:

mount.cifs //192.168.1.10/share /mnt -o file_mode=0777,dir_mode=0777

Для указания владельца, который будет назначен для примонтированного каталога, используем:

mount.cifs //192.168.1.10/share /mnt -o uid=33,gid=33

* чтобы посмотреть идентификаторы пользователя, вводим id -u и id -g .

Источник

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