在 Linux 中装载 SharePoint Online (Office 365)

pro*_*ous 15 linux webdav sharepoint ubuntu office365

我们已开始使用 Office 365 订阅中包含的 SharePoint Online。我们的 Windows 用户可以安装软件,自动将共享文档从 SharePoint 同步到他们的 Windows 计算机。如何让我的 Linux (Ubuntu) 用户也能这样做?

我认为 WebDav 会工作,但我的尝试总是失败,主要是“HTTP 错误:禁止”。具体来说,我尝试通过 Nautilus 文件浏览添加服务器并失败:

Server: mycompany.sharepoint.com
Port: 443
Tppe: Secure WebDav (HTTPS)
Folder: /
User name: first.last@mycompany.com
Password: ********
Run Code Online (Sandbox Code Playgroud)

HTTP 错误:禁止

我尝试将用户名更改为:

 mycompany\first.last
Run Code Online (Sandbox Code Playgroud)

我尝试将文件夹更改为:

 /Shared%20Documents
Run Code Online (Sandbox Code Playgroud)

以及基于网络搜索的各种其他路径无济于事。

这应该工作吗?有更好的解决方案吗?

Vin*_*ris 9

这适用于目前最新版本的 rclone 1.50:

https://rclone.org/downloads/

OneDrive for Business 基本上是共享点,它通过 rclone 设置工作,如下所述:

https://rclone.org/onedrive/(检查限制!)

所以基本上你在终端中运行:

rclone config
Run Code Online (Sandbox Code Playgroud)

然后输入 n,然后输入名称并选择选项 22(这可能会更改,但此处指的是 onedrive 选项)。然后按 Enter 两次(不需要客户端 ID 和密钥),然后按 n 表示无需高级配置。然后输入 y 进行自动配置(您的浏览器应该打开,如果您已登录,这很方便,它将重定向并在浏览器中显示成功消息。

返回终端并为 onedrive 选择 1。这应该会显示一个驱动器,选择 0。下一条消息,选择 y 进行确认,下一个 y 也是如此。

现在您已经完成了配置设置,因此您可以将共享挂载为:

rclone --vfs-cache-mode writes mount onedrive: ~/OneDrive
Run Code Online (Sandbox Code Playgroud)

其中 onedrive 是您创建的共享的名称,~/OneDrive 是您的主目录中安装该共享的文件夹。

如果安装出现问题,您可以使用以下命令卸载:

fusermount -uz ~/OneDrive/
Run Code Online (Sandbox Code Playgroud)

您可能已经注意到共享文件夹不存在。目前商业版本的 rclone 不支持它。要解决这个问题,您可以使用 WebDAV 配置来安装它。更多相关内容可以在这里找到:

https://rclone.org/webdav/

对于供应商选择共享点,因此您的配置如下所示:

[onedriveShared]
type = webdav
url = https://domain.sharepoint.com/personal/firstname_lastname_domain_com/Documents
vendor = sharepoint
user = firstname.lastname@domain.com
pass = encryptes_pass
Run Code Online (Sandbox Code Playgroud)

这里的问题是您需要为每个共享添加此内容。不幸的是,微软认为没有必要支持 Linux,所以我的建议是远离他们的产品并使用开箱即用的产品。

更新:提到的要点是这样的,我还没有测试它,但为了方便和完整性将其添加到这里,它应该处理共享:

# User service for Rclone mounting
#
# Place in ~/.config/systemd/user/
# File must include the '@' (ex rclone@.service)
# As your normal user, run 
#   systemctl --user daemon-reload
# You can now start/enable each remote by using rclone@<remote>
#   systemctl --user enable --now rclone@dropbox

[Unit]
Description=rclone: Remote FUSE filesystem for cloud storage config %i
Documentation=man:rclone(1)
After=network-online.target
Wants=network-online.target 

[Service]
Type=notify
ExecStartPre=-/usr/bin/mkdir -p %h/mnt/%i
ExecStart= \
  /usr/bin/rclone mount \
    --config=%h/.config/rclone/rclone.conf \
    --vfs-cache-mode writes \
    --vfs-cache-max-size 100M \
    --log-level INFO \
    --log-file /tmp/rclone-%i.log \
    --umask 022 \
    --allow-other \
    %i: %h/mnt/%i
ExecStop=/bin/fusermount -u %h/mnt/%i

[Install]
WantedBy=default.target
Run Code Online (Sandbox Code Playgroud)


小智 7

通过 WebDAV 连接到 Office365 Sharepoint(或“OneDrive for Business”)需要现有的身份验证 cookie。您无法在 WebDAV 客户端中使用用户名和密码登录。在 Windows 上,您可以通过将 Sharepoint 站点添加到 Internet Explorer 的 Intranet 站点列表中,然后使用 Internet Explorer 登录并勾选“保持登录状态”来实现此目的,这样您就可以在 Windows 资源管理器中映射网络驱动器。

我发现在 Linux 上执行此操作的唯一方法是使用 Konqueror,因为它包含 Web 浏览器和支持 WebDAV 的文件浏览器。您可以在 Konqueror 浏览器中登录 Sharepoint 站点,然后 Konqueror 文件浏览器可以使用该 cookie 向 WebDAV 进行身份验证。


小智 7

确实有可能,但我还没有一个顺利的解决方案。我正在使用 davfs2 安装 SharePoint 驱动器。为此,您必须使用浏览器进行身份验证(只需访问您的 SharePoint 网站)。然后,您必须提取名为“rtFa”和“FedAuth”的 Cookie。它们必须粘贴在文件 /etc/davfs2/davfs2.conf 的末尾,如下所示:

add_header Cookie rtFa=<your cookie here>;FedAuth=<your other cookie here>;
Run Code Online (Sandbox Code Playgroud)

还要添加以下行:

use_locks 0
Run Code Online (Sandbox Code Playgroud)

为了装载共享,我使用共享的 SharePoint-Webinterface-URL 的 URL,末尾没有 default.aspx。我还将它们输入到 /etc/fstab 中,这样我就可以轻松挂载它们:

https://myinstitution.sharepoint.com/sites/path/to/my/share/      /path/to/my/mountpoint   davfs   user,rw,noauto  0       0
Run Code Online (Sandbox Code Playgroud)

为了将 cookie 保存到 davfs2.conf 文件中,我使用带有 cookies.txt 扩展的 Chrome,这样我只需单击两次即可将它们保存到 cookies.txt 文件中。然后我编写了一个小的 Ruby 脚本来解析该文件并将该行添加到 davfs2.conf 文件中。我目前有一个从 /etc/davfs2/davfs2.conf 到我的主目录上的文件的符号链接,但更简洁的方法是每个用户一个配置文件(davfs2 允许 afaik)。它远非理想,但目前已经可以完成工作了。

#!/usr/bin/ruby

davfsFile = "/path/to/the/file/davfs2.conf"  # Replace this
cookiesFile = "/path/to/the/file/cookies.txt"  # Replace this
cookies = File.read(cookiesFile).split("\n").map{|c| c.split("\t")}
`rm #{cookiesFile}`

cookies.select!{|c| c[5]=="rtFa" || c[5]=="FedAuth"}
cookieline = "add_header Cookie #{cookies[0][5]}=#{cookies[0][6]};#{cookies[1][5]}=#{cookies[1][6]};"

davfsconf = File.read(davfsFile).split("\n")
davfsconf[-1]=cookieline
File.write(davfsFile, davfsconf.join("\n"))
Run Code Online (Sandbox Code Playgroud)

文件传输快速且可用,目录访问几乎慢得无法使用,像 ls */bla 这样的东西在包含 30 个条目的目录中需要 40 秒...我正在调查原因,当我了解更多信息时,我会在这里发布...