KaguyaのVPSで放置してても、システムを常に最新にしてくれる cron-apt を設定する。
しかし、cron-apt ってメールシステム必須なので、postfixが付随してインストールされてしまうので、不本意ながらメールシステムも設定する。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | noizumi@irc:~$ sudo apt install cron-apt パッケージリストを読み込んでいます... 完了 依存関係ツリーを作成しています 状態情報を読み取っています... 完了 以下の追加パッケージがインストールされます: liblockfile-bin liblockfile1 postfix 提案パッケージ: procmail postfix-mysql postfix-pgsql postfix-ldap postfix-pcre postfix-lmdb postfix-sqlite sasl2-bin | dovecot-common resolvconf postfix-cdb mail-reader postfix-doc 以下のパッケージが新たにインストールされます: cron-apt liblockfile-bin liblockfile1 postfix アップグレード: 0 個、新規インストール: 4 個、削除: 0 個、保留: 1 個。 1,239 kB のアーカイブを取得する必要があります。 この操作後に追加で 4,755 kB のディスク容量が消費されます。 続行しますか? [Y/n] | 
・postfixの設定編集
よく考えたら、リレーホストにTLS接続する為に、SSLのサイトの正式名称でないとエラーになるはずなので、わしのプロバイダのサーバーの正式名称である sv96.xserver.jp にしないといけない。
そして、プロバイダのメールアカウントの認証を通す為に末尾に設定を追加。
| 1 | root@irc:/etc/postfix# vi /etc/postfix/main.cf | 
| 1 2 3 4 5 6 7 8 9 10 | … relayhost = [sv96.xserver.jp]:587 … smtpd_sasl_auth_enable = yes smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/smtp_sasl_password smtp_sasl_security_options = noanonymous smtp_sasl_mechanism_filter = plain smtp_use_tls = yes smtp_tls_CAfile = /etc/postfix/cert/gd_bundle-g2-g1.crt | 
・中間証明書取得
TLS接続に中間証明書が無いとエラーになる事があるので、goddadyから頂いて /etc/postfix/cert ディレクトリに設置する。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 | root@irc:/etc/postfix# mkdir cert root@irc:/etc/postfix# cd cert root@irc:/etc/postfix/cert# wget https://certs.godaddy.com/repository/gd_bundle-g2-g1.crt --2021-10-17 12:51:37-- https://certs.godaddy.com/repository/gd_bundle-g2-g1.crt Resolving certs.godaddy.com (certs.godaddy.com)... 173.201.249.4 Connecting to certs.godaddy.com (certs.godaddy.com)|173.201.249.4|:443... connected. HTTP request sent, awaiting response... 200 Length: 4795 (4.7K) [application/octet-stream] Saving to: ‘gd_bundle-g2-g1.crt’ gd_bundle-g2-g1.crt 100%[===================>] 4.68K --.-KB/s in 0s 2021-10-17 12:51:38 (303 MB/s) - ‘gd_bundle-g2-g1.crt’ saved [4795/4795] | 
・パスワード認証ファイルの用意
| 1 | root@irc:/etc/postfix# vi smtp_sasl_password | 
| 1 | [sv96.xserver.jp]:587 アカウント名:パスワード | 
| 1 | root@irc:/etc/postfix# postmap smtp_sasl_password | 
・postfixの再起動
| 1 | root@irc:/etc/postfix# systemctl restart postfix | 
・テストメール送信
| 1 2 3 4 5 6 7 | root@irc:/etc/postfix# cat << _EOD_|sendmail -t > From: 差出人メールアドレス > To: 宛先メールアドレス > Subject: test > > This is test mail. > _EOD_ | 
・cron-apt設定
| 1 | root@irc:/etc/cron-apt# vi config | 
| 1 2 3 | … MAILTO="わしのメールアドレス" OPTIONS="-o quiet=1" | 
| 1 | root@irc:/etc/cron-apt# vi action.d/3-download | 
| 1 2 | autoclean -y dist-upgrade -y -o APT::Get::Show-Upgraded=true | 
テスト実行
| 1 | root@irc:/etc/cron-apt# /usr/sbin/cron-apt | 
ログの確認
| 1 | root@irc:/etc/cron-apt# less /var/log/cron-apt/log | 
これで VPS放置してても勝手にアップデートされる。



