使用sshfs挂载远程文件系统

1|0什么是sshfs


ssfhs是一个客户端,可以让我们通过SFTP(SSH文件传输协议)挂载远程的文件系统,从而实现本机和远程的文件系统的交互

2|0安装sshfs


yum -y install epel-release yum -y install sshfs

3|0有密码挂载远程文件系统


[root@localhost opt]# sshfs root@192.168.0.126:/opt share/ #将远程的/opt目录挂载在本机的share目录下,注意本机的share要是空目录 root@192.168.0.126's password: #这种情况下要输入密码

4|0无密码挂载远程文件系统


1.生成rsa公钥

[root@localhost opt]# ssh-keygen -t rsa #一路回车生成id_rsa.pub公钥 Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. #公钥路径 The key fingerprint is: SHA256:rQhwm//R5d70BBiyZ/fm8Z2y++4aa9AQhjkKnK07sKY root@localhost.localdomain The key's randomart image is: +---[RSA 2048]----+ | . o o | | + . + o | | . . o . + o | | + + . . + o | | * . S o B o | | o = . o * o o | | o + o . o...+| | E . . . =o==| | . o=X==| +----[SHA256]-----+

2.将公钥复制到服务器上,期间会输入密码一次

[root@localhost opt]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.0.126 usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@192.168.0.126's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'root@192.168.0.126'" and check to make sure that only the key(s) you wanted were added.

3.然后再挂载,就不会输入密码

[root@localhost share]# sshfs root@192.168.0.126:/opt/pyexecnetcache/APP_AutoTest/allure_reports ../share/

5|0查看挂载点


[root@localhost share]# df -hT Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 899M 0 899M 0% /dev tmpfs tmpfs 910M 24K 910M 1% /dev/shm tmpfs tmpfs 910M 9.5M 901M 2% /run tmpfs tmpfs 910M 0 910M 0% /sys/fs/cgroup /dev/mapper/centos-root xfs 50G 12G 39G 23% / /dev/sda1 xfs 1014M 169M 846M 17% /boot /dev/mapper/centos-home xfs 27G 33M 27G 1% /home tmpfs tmpfs 182M 0 182M 0% /run/user/0 root@192.168.0.126:/opt/pyexecnetcache/APP_AutoTest/allure_reports fuse.sshfs 50G 12G 39G 23% /opt/share

6|0卸载挂载点


[root@localhost opt]# umount share/

7|0参考文章


《sshfs远程挂载》
《使用 SSHFS挂载远程的Linux文件系统或目录》
《使用SSHFS文件系统通过SSH远程挂在目录》


__EOF__

本文作者cnhkzyy
本文链接https://www.cnblogs.com/my_captain/p/12779253.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   cnhkzyy  阅读(1084)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示