Table of Contents
1 WebDAVをインストールする
- この記事ではhttpsの為にデフォルトのSSL/TLS証明書を使っています。別にSSL/TLS証明書を用意している場合はそちらをお使いください。
- SSLを利用するのでhttpsやdavsで接続してください。
- Digest認証を使用します。ユーザ名はWEBDAV_USERNAMEの値で、パスワードはWEBDAV_PASSWORDの値です。
#!/bin/shset -e[ -z “${WEBDAV_USERNAME}” ] && WEBDAV_USERNAME=webdav[ -z “${WEBDAV_PASSWORD}” ] && WEBDAV_PASSWORD=webdavsudo apt install -y apache2cat <<EOF | sudo tee /etc/apache2/sites-available/webdav.confAlias /webdav /var/www/webdav<VirtualHost _default_:443> SSLEngine on SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key</VirtualHost><Location /webdav> DAV On SSLRequireSSL AuthType Digest AuthName webdav AuthUserFile /etc/apache2/.webdav Require valid-user</Location>EOFsudo mkdir /var/www/webdavsudo chown www-data:www-data /var/www/webdavfor mod in dav dav_fs dav_lock ssl auth_digest; do sudo a2enmod ${mod}donesudo a2ensite webdavsudo systemctl restart apache2yes ${WEBDAV_PASSWORD} | sudo htdigest -c /etc/apache2/.webdav webdav ${WEBDAV_USERNAME}
2 WebDAVへアクセスする
davfsのマウントを可能にするdavfs2パッケージをインストールします。
$ sudo apt install -y davfs2
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: mint subject: mint identity: mint fingerprint: c3:d2:03:34:6f:3d:3e:17:3b:f9:c6:20:96:71:e2:23:10:25:81:7cYou 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
/mnt/hello.txtを書き込みます。
$ echo hello | sudo tee /mnt/hello.txt
即座にファイルを反映させる為にアンマウントします。
$ sudo umount /mnt
WebDAVのディレクトリにファイルが反映されています。
$ sudo cat /var/www/webdav/hello.txthello