AlpineLinux 3.8: Install webdav for WebDAV server


Table of Contents

1 Install webdav

  • This article uses default SSL/TLS certicication file for https. Please change your SSL/TLS certification file.
  • For closing http, use firewall with awall.
  • Use https or davs for SSL.
  • WEBDAV_USERNAME is username and WEBDAV_PASSWORD is password for digest authentication.

#!/bin/sh -e[ -z “${WEBDAV_USERNAME}” ] && WEBDAV_USERNAME=admin[ -z “${WEBDAV_PASSWORD}” ] && WEBDAV_PASSWORD=webdav# Install webdav.sudo apk add apache2-webdav apache2-utils apache2-sslsudo rc-update add apache2sudo rc-service apache2 start# Create directory for webdav.sudo mkdir -p /var/lib/davsudo mkdir -p /usr/uploadssudo chown apache:apache /var/lib/davsudo chown apache:apache /usr/uploads# Create digest password file with expect command.sudo apk add expectexpect -c “set timeout -1spawn sudo htdigest -c /usr/user.passwd DAV-upload ${WEBDAV_USERNAME}expect “New password: “send “${WEBDAV_PASSWORD}n”expect “Re-type new password: “send “${WEBDAV_PASSWORD}n”expect eof”

2 Access to webdav

Install davfs2 package for mounting davfs.

$ sudo sed -e ‘s;^#http(.*)/v3.8/community;http1/v3.8/community;g’ -i /etc/apk/repositories$ sudo apk update$ sudo apk add davfs2

Get SSL certificate from server.

$ WEBDAV_SERVER_FQDN=webdav-server.hiroom2.com$ openssl s_client -showcerts -connect “${WEBDAV_SERVER_FQDN}”:443 < /dev/null 2> /dev/null | openssl x509 -outform PEM | sudo tee /etc/davfs2/certs/”${WEBDAV_SERVER_FQDN}”.pem

Run “mount -t davfs”.

$ sudo mount -t davfs https://${WEBDAV_SERVER_FQDN}/uploads /mntPlease enter the username to authenticate with serverhttps://webdav-server.hiroom2.com/uploads or hit enter for none.admin Username: Please enter the password to authenticate user admin with serverhttps://webdav-server.hiroom2.com/uploads or hit enter for none. Password:

Write file via webdav.

$ echo hello | sudo tee /mnt/hello.txt

For updating written file immediately, unmount /mnt.

$ sudo umount /mnt

Written file can be read in /usr/uploads.

$ sudo cat /usr/uploads/hello.txthello

Android | Linux | SDL - Narrow Escape