How to Mount a Remote Folder using SSH on Ubuntu(Ubuntu 使用ssh挂载远程目录)

如果网络条件允许,建议看原文。原文地址:http://www.howtogeek.com/howto/ubuntu/how-to-mount-a-remote-folder-using-ssh-on-ubuntu/

Connecting to a server across the internet is much more secure using SSH. There is a way that you can mount a folder on a remove server using the SSHFS service.

There are quite a few steps that you’ll have to follow, so get ready and open a terminal window.

First we’ll install the module:

sudo apt-get install sshfs

Now we will use the modprobe command to load it

sudo modprobe fuse

We’ll need to set up some permissions in order to access the utilities. Replace <username> with your username.

sudo adduser <username> fuse

sudo chown root:fuse /dev/fuse

sudo chmod +x /dev/fusermount

Since we’ve added ourselves to a user group, we need to logout and back in at this point before we continue.

Now we’ll create a directory to mount the remote folder in. I chose to create it in my home directory and call it remoteserv.

mkdir ~/remoteserv

Now we have the command to actually mount it. You’ll be prompted to save the server key and for your remote password.

sshfs <username>@<ipaddress>:/remotepath ~/remoteserv

Now you should be able to cd into the directory and start using it as if it was local.

geek@ubuntuServ:~/remoteserv$ ls -l
total 16
drwxr-xr-x 1 951247 155725 4096 2006-12-13 13:30 howtogeek.com
drwxr-sr-x 1 root root 4096 2006-09-11 06:45 logs
drwx—— 1 951247 155725 4096 2006-08-11 16:09 Maildir
drwxrwxr-x 1 951247 155725 4096 2006-10-29 02:34 scripts

<think>我们正在讨论Windows通过SSH挂载Ubuntu目录。根据之前的上下文,我们已经提到了SSHFS-Win方案。现在需要详细说明在Windows上的操作步骤。 注意:用户要求使用中文回答,并在最后提出3-5个相关问题,且第一行必须是“§§相关问题§§”,然后列举问题。 方案:使用SSHFS-Win在Windows上挂载Ubuntu目录 步骤: 1. 安装必要软件: - 下载并安装WinFsp(Windows File System Proxy):https://github.com/winfsp/winfsp/releases - 下载并安装SSHFS-Win:https://github.com/winfsp/sshfs-win/releases 2. 挂载远程目录: 方法1:通过“此电脑”右键菜单挂载 - 打开“此电脑” - 在空白处右键 -> 选择“映射网络驱动器” - 在“文件夹”栏输入:\\sshfs\username@ubuntu_ip[!port] (例如:\\sshfs\user@192.168.1.100) - 注意:如果SSH端口不是22,则需要指定端口,格式为:\\sshfs.r\username@ubuntu_ip!port - 点击“完成”,输入SSH密码(如果设置了密钥,需要确保密钥已加载到Pageant或配置为无密码) 方法2:使用命令挂载(管理员权限运行) - 打开命令提示符(CMD)或PowerShell - 输入: net use Z: \\sshfs\username@ubuntu_ip\path\to\folder (或者使用带端口的格式:net use Z: \\sshfs.r\username@ubuntu_ip!port\path\to\folder) - 输入密码 3. 卸载目录: - 在文件资源管理器中右键点击挂载的驱动器 -> 断开连接 - 或使用命令:`net use Z: /delete` 4. 常见问题处理: - 连接失败:检查UbuntuSSH服务是否运行(`sudo systemctl status ssh`),防火墙是否开放端口(默认22)。 - 权限问题:确保Ubuntu上的目标目录SSH用户有读/写权限。 - 密钥认证:建议使用密钥登录,避免每次输入密码。将公钥添加到Ubuntu的`~/.ssh/authorized_keys`,私钥使用Pageant加载或放入SSHFS-Win默认位置(如`C:\Users\用户名\.ssh`)。 注意:SSHFS-Win在Windows资源管理器中可能显示为网络驱动器。 优势:利用SSH加密传输,无需额外配置,安全便捷。 §§相关问题§§ 1. 如何在Windows上配置SSH密钥以用于SSHFS免密挂载? 2. SSHFS挂载后访问速度慢,有哪些优化方法? 3. 如何解决Windows挂载Ubuntu目录时出现的“权限被拒绝”错误? 4. 除了SSHFS,Windows还有哪些工具可以挂载Linux远程目录? 5. 如何通过批处理脚本实现Windows开机自动挂载SSHFS目录?</think>在Windows系统上通过SSH挂载Ubuntu目录,推荐使用**SSHFS-Win**工具实现。以下是详细步骤: ### 安装准备 1. **安装必备组件**: - 下载安装 [WinFsp](https://github.com/winfsp/winfsp/releases)(Windows文件系统代理) - 下载安装 [SSHFS-Win](https://github.com/winfsp/sshfs-win/releases)SSH文件系统实现) > 注意:安装时勾选"Add to PATH" 2. **Ubuntu端配置**: ```bash sudo apt update && sudo apt install openssh-server -y sudo systemctl enable ssh sudo ufw allow 22 # 开放SSH端口 ``` ### 挂载操作(两种方法) **方法1:资源管理器挂载** 1. 打开文件资源管理器 2. 地址栏输入: ```path \\sshfs\[用户名]@[Ubuntu_IP]\[目录路径] ``` 示例:`\\sshfs\ubuntu_user@192.168.1.100\home/share` **方法2:命令挂载(管理员权限)** ```cmd net use Z: \\sshfs\ubuntu_user@192.168.1.100\home/share /persistent:yes ``` > 提示输入SSH密码后完成挂载,驱动器将显示为网络位置 ### 密钥认证配置(免密挂载) 1. **生成密钥对**(Windows端): ```cmd ssh-keygen -t rsa # 默认保存到 %USERPROFILE%\.ssh\id_rsa ``` 2. **复制公钥到Ubuntu**: ```cmd type %USERPROFILE%\.ssh\id_rsa.pub | ssh ubuntu_user@192.168.1.100 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys" ``` 3. **挂载时自动使用密钥**: ```cmd net use Z: \\sshfs.r\ubuntu_user@192.168.1.100!22\home/share /persistent:yes ``` ### 卸载目录 - 资源管理器:右键驱动器 → 断开连接 - 命令行:`net use Z: /delete` ### 常见问题解决 - **连接失败**:检查Ubuntu SSH服务状态 `sudo systemctl status ssh` - **权限错误**:确保Ubuntu目录权限 `sudo chmod 755 /path` - **端口变更**:非22端口需使用 `\\sshfs.r\user@ip!port\path` 格式
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值