Table of Contents
1 Install WebDAV
- Use https or davs for SSL.
- WEBDAV_USERNAME is username and WEBDAV_PASSWORD is password for digest authentication.
- Change WEBDAV_SERVER_FQDN to your server’s FQDN.
#!/bin/shset -e[ -z “${WEBDAV_USERNAME}” ] && WEBDAV_USERNAME=webdav[ -z “${WEBDAV_PASSWORD}” ] && WEBDAV_PASSWORD=webdav[ -z “${WEBDAV_SERVER_FQDN}” ] && WEBDAV_SERVER_FQDN=webdav-server.hiroom2.comsudo pacman -Sy –noconfirm apachesudo systemctl enable httpd# ssl configuration.# Country Name (2 letter code) [AU]:# State or Province Name (full name) [Some-State]:# Locality Name (eg, city) []:# Organization Name (eg, company) [Internet Widgits Pty Ltd]:# Organizational Unit Name (eg, section) []:# Common Name (e.g. server FQDN or YOUR name) []:# Email Address []:cat <<EOF | sudo openssl req -new -x509 -nodes -newkey rsa:4096 -days 1095 -keyout /etc/httpd/conf/server.key -out /etc/httpd/conf/server.crtAUSome-Statecitycompanysection${WEBDAV_SERVER_FQDN}EOFsudo sed -i /etc/httpd/conf/httpd.conf -e ‘s/^#LoadModule ssl_module/LoadModule ssl_module/g’ -e ‘s/^#LoadModule socache_shmcb_module/LoadModule socache_shmcb_module/g’cat <<EOF | sudo tee -a /etc/httpd/conf/httpd.confInclude conf/extra/httpd-ssl.confEOF# digest configuration.sudo sed -i /etc/httpd/conf/httpd.conf -e ‘s/#LoadModule auth_digest_module/LoadModule auth_digest_module/g’# dav configuration.sudo sed -i /etc/httpd/conf/httpd.conf -e ‘s/^#LoadModule dav_module/LoadModule dav_module/g’ -e ‘s/^#LoadModule dav_fs_module/LoadModule dav_fs_module/g’ -e ‘s/^#LoadModule dav_lock_module/LoadModule dav_lock_module/g’cat <<EOF | sudo tee -a /etc/httpd/conf/httpd.confInclude conf/extra/webdav.confEOFcat <<EOF | sudo tee /etc/httpd/conf/extra/webdav.confAlias /webdav /srv/http/webdavDavLockDB “/srv/http/lock/DavLock”<Location /webdav> DAV On SSLRequireSSL AuthType Digest AuthName webdav AuthUserFile /etc/httpd/.webdav Require valid-user</Location>EOFsudo mkdir /srv/http/locksudo mkdir /srv/http/webdavsudo chown http:http /srv/http/locksudo chown http:http /srv/http/webdavsudo systemctl restart httpd# Create digest password file with expect command.sudo pacman -Sy –noconfirm 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 pacman -Sy –noconfirm 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:<snip>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