前言

最近想将网盘里面的资源使用 WebDav 挂载到电脑上
我使用的是 Debian GNU/Linux 并搭载 KDE Plasma桌面环境

使用davfs

安装davfs2

首先,需要安装davfs2来提供WebDav挂载支持

$ sudo apt install -y davfs2 #Debian

安装完成后就可以挂载WebDav了

挂载WebDav

手动挂载

新建一个文件夹用来作为挂载点(mountpoint)

$ pwd
/home/charity
$ mkdir OPList

现在就可以使用mount命令来进行挂载了

语法:
mount -t davfs <http(s)://your.domain.com> <mountpoint>

$ sudo mount -t davfs https://your.domain.com/dav OPList
Please enter the username to authenticate with server
https://your.domain.com/dav or hit enter for none.
  Username: #WebDav账户
Please enter the password to authenticate user ChariTY with server
https://your.domain.com/dav or hit enter for none.
  Password: #WebDav密码

如果WebDav未指定账户/密码,按回车跳过即可

不出意外的话,此时应该可以看到WebDav里面的文件

$ pwd
/home/charity/OPList
$ ls -aF
./  123WebDav/  lanzou/  Local/  lost+found/  OneDrive/

自动挂载

配置davfs2.conf

有些时候,手动挂载不太方便,需要开机后自动挂载

我们需要修改一下davfs2的配置
使用任意文本编辑器来编辑位于/etc/davfs2/davfs2.conf的配置文件

$ sudo nano /etc/davfs2/davfs2.conf

#use_locks 0去掉注释改为use_locks 1并保存

再次定位到/etc/davfs2/secrets

$ sudo nano /etc/davfs2/secrets

在末尾添加http(s)://<服务器域名/IP> <WebDav账户> <WebDav密码>
保存并退出
这样在挂载的时候将不会询问账户和密码

这种方式将以明文保存密码,请确保secrets文件权限为660(-rw-rw----),以防被盗取

可以测试一下

$ pwd
/home/charity
$ sudo mount -t davfs https://101.132.75.252:83/dav OPList
$ ls -aF OPList 
./  123WebDav/  lanzou/  Local/  lost+found/  OneDrive/

此时不再询问账号与密码

配置fstab

以上操作成功后,就可以编辑/etc/fstab文件来实现开机自动挂载了

$ sudo nano /etc/fstab

在末尾添加<http(s)://your.domain.com> <mountpoint> davfs defaults,_netdev 0 0
_netdev选项会推迟挂载直到设备连接到网络

保存并退出

验证

确保WebDav挂载点已卸载

$ pwd
/home/charity
$ sudo umount OPList
/sbin/umount.davfs: waiting for mount.davfs (pid 295352) to terminate gracefully .. OK

重载systemd daemon

$ sudo systemctl daemon-reload

使用systemctl start path-to-your-mountpoint.mount启动单元

$ sudo systemctl start home-charity-OPList.mount

根据systemd的命名规则
mount单元的名称必须根据其封装的文件系统挂载点路径命名
如这里的挂载点是/home/charity/OPList
那么单元名称则为home-charity-OPList.mount

使用systemctl status path-to-your-mountpoint.mount查看挂载单元状态

$ sudo systemctl status home-charity-OPList.mount
● home-charity-OPList.mount - /home/charity/OPList
     Loaded: loaded (/etc/fstab; generated)
     Active: active (mounted) since Thu 2025-11-06 00:58:15 CST; 6s ago
      Where: /home/charity/OPList
       What: https://your.domain.com/dav
       Docs: man:fstab(5)
             man:systemd-fstab-generator(8)
      Tasks: 1 (limit: 9030)
     Memory: 2.5M
        CPU: 66ms
     CGroup: /system.slice/home-charity-OPList.mount
             └─525520 /sbin/mount.davfs https://your.domain.com/dav /home/charity/OPList -o rw _netdev

11月 06 00:58:14 debian systemd[1]: Mounting home-charity-OPList.mount - /home/charity/OPList...
11月 06 00:58:14 debian mount.davfs[525409]: davfs2 1.6.1
11月 06 00:58:15 debian systemd[1]: Mounted home-charity-OPList.mount - /home/charity/OPList.

确保为active状态且下方日志无异常

最后,查看挂载点目录是否正常加载

$ pwd
/home/charity
$ ls -aF OPList                                           
./  123WebDav/  lanzou/  Local/  lost+found/  OneDrive/

使用Dolphin

KDE Dolphin是一款功能强大、高度可定制且注重效率的图形化文件管理器。它作为 KDE Plasma 桌面环境的默认组件

安装

如果使用的是KDE Plasma桌面环境,请跳过安装步骤
使用APT:

$ sudo apt install dolphin

使用Dolphin添加网络存储

安装成功后可以在开始页面打开,或在终端输入dolphin来打开
在左侧侧边栏选择网络
图片.png
点击地址栏旁边的添加网络文件夹
图片.png
选择Webdav(Web文件夹)
分别填入名称、服务器(域名)、端口、文件夹
图片.png
填入完成后,点击保存并连接
如果WebDav需要身份认证则会弹出认证窗口,否则不弹
f.gif
成功添加后即可对WebDav进行操作