Fedora 26: Install WebDAV for file server


Table of Contents

1 Install WebDAV

  • This article uses default SSL/TLS certicication file for https. Please change your SSL/TLS certification file.
  • Use https or davs for SSL.
  • WEBDAV_USERNAME is username and WEBDAV_PASSWORD is password for digest authentication.

#!/bin/shset -e[ -z “${WEBDAV_USERNAME}” ] && WEBDAV_USERNAME=webdav[ -z “${WEBDAV_PASSWORD}” ] && WEBDAV_PASSWORD=webdavsudo dnf install -y httpd httpd-tools mod_sslcat <<EOF | sudo tee /etc/httpd/conf.d/webdav.confAlias /webdav /var/www/webdavDAVLockDB /var/lib/webdav/DAVLock<VirtualHost _default_:443> SSLEngine on SSLCertificateFile /etc/pki/tls/certs/localhost.crt SSLCertificateKeyFile /etc/pki/tls/private/localhost.key</VirtualHost><Location /webdav> DAV On SSLRequireSSL AuthType Digest AuthName webdav AuthUserFile /etc/httpd/.webdav Require valid-user</Location>EOFsudo mkdir /var/www/webdavsudo chown apache:apache /var/www/webdavsudo mkdir /var/lib/webdavsudo chown apache:apache /var/lib/webdavsudo firewall-cmd –add-service=https –permanentsudo firewall-cmd –reloadsudo systemctl enable httpdsudo systemctl restart httpdsudo setsebool -P httpd_unified 1# Create digest password file with expect command.sudo dnf install -y expectexpect -c “set timeout -1spawn sudo htdigest -c /etc/httpd/.webdav webdav ${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 dnf install -y davfs2

Run “mount -t davfs”.

$ sudo mount -t davfs https://localhost/webdav /mntPlease enter the username to authenticate with serverhttps://localhost/webdav or hit enter for none. Username: webdavPlease enter the password to authenticate user webdav with serverhttps://localhost/webdav or hit enter for none. Password:/sbin/mount.davfs: the server certificate does not match the server name/sbin/mount.davfs: the server certificate is not trusted issuer: SomeOrganizationalUnit, SomeOrganization, SomeCity, SomeState, — subject: SomeOrganizationalUnit, SomeOrganization, SomeCity, SomeState, — identity: fedora-25 fingerprint: 15:73:eb:cb:97:4b:d1:ae:8b:6a:ca:e8:0a:83:c2:f4:11:e1:45:74You only should accept this certificate, if you canverify the fingerprint! The server might be fakedor there might be a man-in-the-middle-attack.Accept certificate for this session? [y,N] y

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 /var/www/webdav.

$ sudo cat /var/www/webdav/hello.txthello

Android | Linux | SDL - Narrow Escape