ArchLinux 2017.10.01: ファイルサーバのWebDAVをインストールする


Table of Contents

1 WebDAVをインストールする

  • SSLを利用するのでhttpsやdavsで接続してください。
  • Digest認証を使用します。ユーザ名はWEBDAV_USERNAMEの値で、パスワードはWEBDAV_PASSWORDの値です。
  • WEBDAV_SERVER_FQDNはお使いのサーバーの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 WebDAVへアクセスする

davfsのマウントを可能にするdavfs2パッケージをインストールします。

$ sudo pacman -Sy –noconfirm 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:<snip>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

Android | Linux | SDL - Narrow Escape