【问题标题】:Mounting SSHFS for local folder on Mac OS X to edit files on Ubuntu AWS instance在 Mac OS X 上为本地文件夹挂载 SSHFS 以在 Ubuntu AWS 实例上编辑文件
【发布时间】:2017-06-07 14:13:25
【问题描述】:

我希望能够使用一个不错的 IDE 在本地编辑文件并拥有这些文件 在我的本地机器 (~/Code/myproject) 上立即推送到云中的 Ubuntu 机器 (/home/ubuntu/myproject)。

我为我的 Mac OS X 笔记本电脑(本地)安装了 FUSE and SSHFS

我在 EC2 上有一个 Ubuntu 16.04 AWS 实例:

ubuntu@ip-xxxxxx:~$ uname -a
Linux ip-xxxxxx 4.4.0-1017-aws #26-Ubuntu SMP Fri Apr 28 19:48:19 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
ubuntu@ip-xxxxxxx:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.2 LTS
Release:    16.04
Codename:   xenial

我使用.pem 文件通过-i 标志(尚未设置authorized_keys)通过SSH 进入该框。

这就是我在本地机器上所做的:

$ mount  # check for mounted
/dev/disk1 on / (hfs, local, journaled)
devfs on /dev (devfs, local, nobrowse)
map -hosts on /net (autofs, nosuid, automounted, nobrowse)
map auto_home on /home (autofs, automounted, nobrowse)

$ sudo sshfs -o allow_other,defer_permissions,IdentityFile=~/.ssh/aws.pem,loglevel=debug \
    ubuntu@ec2-xxxxxxxx.compute-1.amazonaws.com:/home/ubuntu/myproject \
    /Users/me/Code/myproject

它提示我输入本地机器密码,然后我看到以下内容:

Password:
remote host has disconnected

显然,有些东西已经安装了:

$ mount
/dev/disk1 on / (hfs, local, journaled)
devfs on /dev (devfs, local, nobrowse)
map -hosts on /net (autofs, nosuid, automounted, nobrowse)
map auto_home on /home (autofs, automounted, nobrowse)
ubuntu@ec2-xxxxxxx.compute-1.amazonaws.com:/home/ubuntu/myproject on /Users/me/Code/myproject (osxfuse, synchronous)

如果我再次尝试与上面相同的 sshfs 命令(没有 unmoun-ting),我会得到一个不同的错误:

mount_osxfuse: mount point /Users/me/Code/myproject is itself on a OSXFUSE volume

我可以卸载并使用sudo diskutil umount force /Users/me/Code/myproject/ 重试,但我再次尝试时得到相同的原始错误。

我认为这可能是我的远程服务器的 SFTP 有问题,所以我在远程框上找到了所有 sftp-server 位置:

$ sudo find / | grep sftp-server
...
/usr/lib/sftp-server
/usr/lib/openssh/sftp-server

然后我在 /etc/ssh/sshd_config 文件中尝试了这两种方法:

#Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp /usr/lib/sftp-server

但重启后的配置似乎都不起作用。

我可以使用以下命令进行 SFTP 访问:

$ sftp -i ~/.ssh/aws.pem ubuntu@ec2-xxx.compute-1.amazonaws.com
Connected to ec2-xxx.compute-1.amazonaws.com.
sftp>

编辑:运行debug3 日志级别给出了相对相同的结果:

$ sudo sshfs -o allow_other,defer_permissions,IdentityFile=~/.ssh/aws.pem,loglevel=debug3 ubuntu@ec2-xxxx.compute-1.amazonaws.com:/home/ubuntu/myproject /Users/me/Code/myproject
sudo: cannot get working directory
The authenticity of host 'ec2-xxx.compute-1.amazonaws.com (xx.xx.xx.xx)' can't be established.
ECDSA key fingerprint is SHA256:xxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no)? yes
remote host has disconnected

关于解决什么/问题可能出在哪里的任何想法?

【问题讨论】:

  • 你能连接到那台服务器上的sftp 吗?
  • 是的,我可以。所以sftp服务器正在运行
  • 试试loglevel=debug3 并发布输出。
  • @Jakuje 已更新。我得到相同的输出。仍然是 remote host has disconnected 的错误消息。

标签: macos ubuntu ssh fuse sshfs


【解决方案1】:

您在sudo 下运行sshfs,这与以您的用户身份运行sftp 不同,因为root 找不到您的身份验证密钥:

IdentityFile=~/.ssh/aws.pem

为您的用户 (/home/your-user/.ssh/aws.pem) 展开到您的主目录,但为 sudo 用户 (/root/.ssh/aws.pem) 展开到 root 主目录,该文件显然不是。

使用 PEM 文件的完整路径,例如

IdentityFile=/home/your-user/.ssh/aws.pem`

【讨论】:

  • 顺便说一句,sudo diskutil umount force /Users/me/Code/myproject 是最好的卸载方式吗?
  • 根据github.com/libfuse/sshfs umount mountpoint 应该可以完成这项工作(当然,如果您使用sudo 安装,则使用sudo)。
猜你喜欢
  • 2010-10-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-07
  • 2014-08-21
  • 1970-01-01
  • 1970-01-01
  • 2013-11-10
相关资源
最近更新 更多