- How to mount a remote directory in Linux using sshfs
- How to Mount Remote Linux Filesystem or Directory Using SSHFS Over SSH
- What Is SSHFS?
- Step 1: Install SSHFS Client in Linux Systems
- Step 2: Creating SSHFS Mount Directory
- Step 3: Mounting Remote Filesystem with SSHFS
- Step 4: Verifying Remote Filesystem is Mounted
- Step 5: Checking Mount Point with df -hT Command
- Step 6: Mounting Remote Filesystem Permanently
- Step 7: Unmounting Remote Filesystem
- If You Appreciate What We Do Here On TecMint, You Should Consider:
- Монтируем удаленную файловую систему через SSH.
- How To Mount a Remote Directory With SSHFS on a Linux
- More on SSHFS
- Installing SSHFS on a Ubuntu/Debian/Mint Linux
- Installing SSHFS on an Arch Linux
- Installing SSHFS on a RHEL (Red Hat)/CentOS Linux
- How do I mount the remote file system?
- Dealing with “Permission denied” error and recommended procedure for mounting the remote directory
- How do I unmount the remote file system?
- How can I permanently mount the remote file system by updating /etc/fstab?
- Examples
How to mount a remote directory in Linux using sshfs
Q. I have access rights to one of the remote server through SSH protocol and there is no File share services such as Samba, NFS or FTP etc which are enabled on the server. Now I want to mount data from that remote server, is it possible to mount remote folders?
A. The answer to this is yes, We can share data/mount folder on a local machine by using just SSH protocol. This can be done by using FUSE(Filesystem in USErspace) which support SSH and FTP file systems. This post is in response to conversation which I had with one our users two days back. the question he asked about ftp is “I want to transfer one latest file from my ftp server and I want to automate this task through shell script to download latest file from my FTP server, And I don’t know what is the Operating System at server end(This is ultimate sentence I hear from the user today in my office 🙂 )“. Let’s prepare our machine on how to mount a remote folder by using SSH protocol.
Step1: Installing Package
On Ubuntu/Debain
On Redhat/CentOS/Fedora
Step2: Once the package is installed we have to create a mount point and mount our server data using sshfs command, for which we require username/password. Here are my details for this task.
Now create the mount point and mount SSH account data.
Step3: The above command will mount my root directory in 10.233.10.212 server. Testing our setup
Check if you are able to see data
#cd /mnt/ssh
#ls
What about df -hs command output?
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 12G 8.4G 2.5G 78% /
/dev/sda6 80G 43G 34G 56% /var
/dev/sda5 2.0G 41M 1.8G 3% /home
/dev/sda1 99M 12M 83M 12% /boot
tmpfs 506M 0 506M 0% /dev/shm
sshfs#root@10.233.10.212:/ 1000G 0 1000G 0% /mnt/ssh
Step4: So what about mounting it permanently?. We can do it by editing fstab file in /etc folder
#vi /etc/fstab
go to last line and type below line
sshfs#root@10.233.10.212:/ /mnt/ssh fuse defaults 0 0
Save the file and exit. Now run mount -a to update the fstab file state to kernel.
Note: Its not advisable to write passwords in human readable files like /etc/fstab.
#mount -a
Let me explain what entry in fstab indicates. We are mentioning mount user root data which is located on 10.233.10.212 server on to /mnt/ssh using fuse file system with default settings.
Step5: What about unmounting this drive?
Enjoy new learning of mounting a folder using SSH protocol.
Источник
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 .
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.
Источник
Монтируем удаленную файловую систему через SSH.
Во время работы часто приходится работать с удаленными файлами, часто через ssh. Gnome позволяет подключиться и работать с данными с помощью утилиты Places->Connect to Server, но, к сожалению, таким образом могут работать не все программы… Vim, например, а так как это основной мой редактор — я искал способ сделать это. И нашел 🙂
Все, что написано дальше — касается Linux, в частности Ubuntu Linux.
Итак, способ: смонтировать удаленую систему так же, как вы монтируете локальные диски. Сделать такое возможно с поомщью утилиты sshfs.
Для начала надо ее установить вместе с несколькими зависимостями:
$sudo apt-get install sshfs
Потом нужно добавить себя в группу пользователей fuse. Сделать это надо, потому что программа устанавливвается в системные папки, в которые обычным пользователям доступ запрещен. Так, добавляем себя в группу:
$sudo adduser fuse
Потом создаем директорию для монтирования, например, на рабочем столе:
Теперь надо выйти с терминала и зайти вновь. Все, теперь мы в группе fuse. Пробуем соединиться с сервером:
Если соединение идет не по ключу то, скорее всего, у вас появится запрос на введение пароля с удаленной машины.
Если же вы сразу не получили ошибку fusermount: fuse device not found, try ‘modprobe fuse’ first — проверяйте директорию, там должны появиться файлики :). Если же вылезла ошибка — значит модуль ядра fuse не загрузился автоматом, пробуем загрузить вручную:
$sudo modprobe fuse
Пробуем установить соединение еще раз.
Чтобы отмонтировать это все дело, надо выполнить следующее:
Чтобы каждый раз не вводить такую кучу комманд — создаем(если нету) и редактируем файл
/.bash_aliases, добавляя в конец такие строчки:
alias testssh=’sshfs user@example.com:/stuff
/Desktop/test_ssh’
alias testssh_umount=’fusermount -u
Теперь вы сможете монтировать удаленную машину командой testssh, а размонтировать — testssh_umount 🙂
Cпасибо за внимание!
ЗЫ Статью сначала перевел с английского на украинский, добавил немного своего и перевел на русский для Хабра 🙂
Источник
How To Mount a Remote Directory With SSHFS on a Linux
H ow can I mount a remote directory with ssh on a Linux bases system? How do I use SSHFS to mount remote file systems over SSH on a Ubuntu or Debian/RHEL/CentOS/Arch Linux system?
SSH is a secure protocol and you can use it to mount a directory on a remote server or local laptop with the help of the SSHF service. With SSHFS you can mount remote server file system to your local development workstation/laptop powered by Linux. [donotprint]
Tutorial details | |
---|---|
Difficulty level | Intermediate |
Root privileges | Yes |
Requirements | sshfs |
Est. reading time | 10m |
[/donotprint]
More on SSHFS
sshfs is a filesystem based on the SSH file transfer protocol. It is used on a client system i.e. you need to install sshfs package on your local computer/laptop powered by CentOS/RHEL/Ubuntu/Debian/Arch Linux. No need to install anything on server (server1.cyberciti.biz). You only need an openssh server installed on server side. Our sample setup:
Fig.01: Our sample setup
Installing SSHFS on a Ubuntu/Debian/Mint Linux
Installing SSHFS on an Arch Linux
Type the following command:
Make sure you add user named vivek to fuse group:
## [ create fuse group if does not exist as per your distro ] ##
$ sudo groupadd fuse
$ sudo usermod -a -G fuse vivek
Installing SSHFS on a RHEL (Red Hat)/CentOS Linux
First, turn on EPEL repo and then type the following yum command to install FUSE-Filesystem to access remote filesystems via SSH on a CentOS/RHEL:
How do I mount the remote file system?
First, create a directory using mkdir command:
I’m going to mount file system using root user and you need to type root password when prompted:
To access and/or to see the remote file system, run:
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
Fig. 02: sshfs in action
Dealing with “Permission denied” error and recommended procedure for mounting the remote directory
If you get an error that read as cannot access server1: Permission denied, add yourself to a group called fuse:
Next, create a mount point inside your own home directory:
To mount the remote file system, enter:
Fig.03: Using sshfs without root access on local laptop/desktop
How do I unmount the remote file system?
How can I permanently mount the remote file system by updating /etc/fstab?
For persistent mounts, you must create ssh keys based login
$ ssh-keygen -t rsa
$ ssh-copy-id -i
/.ssh/id_rsa.pub vivek@server1.cyberciti.biz
Now, edit the /etc/fstab file, enter:
Examples
Add the following entry at the bottom of the file:
Another example with additional options:
Recommend option for on-demand mounting if you are using systemd:
Save and close the file. Where,
- root@192.168.1.142 : Remote server with sshd
- fuse : File system type.
- idmap=user : Only translate UID of connecting user.
- allow_other : Allow access to other users.
- reconnect : Reconnect to server.
- _netdev : The filesystem resides on a device that requires network access (used to prevent the system from attempting to mount these filesystems until the network has been enabled on the system).
- users : Allow every user to mount and unmount the filesystem.
- IdentityFile=/path/to/.ssh/keyfile – SSH key file.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Category | List of Unix and Linux commands |
---|---|
Documentation | help • mandb • man • pinfo |
Disk space analyzers | df • duf • ncdu • pydf |
File Management | cat • cp • less • mkdir • more • tree |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Linux Desktop Apps | Skype • Spotify • VLC 3 |
Modern utilities | bat • exa |
Network Utilities | NetHogs • dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop |
Searching | ag • grep • whereis • which |
Shell builtins | compgen • echo • printf |
Text processing | cut • rev |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Comments on this entry are closed.
Word of warning: SSHFS is even slower than FTP since §sshd§ has to
Источник