Sources:
- https://www.zealfortechnology.com/2018/08/configure-unattended-upgrades-on-raspberry-pi.html
- https://www.seancarney.ca/2021/02/06/secure-your-raspberry-pi-by-enabling-automatic-software-updates/
To install the software, use the command below:
sudo apt-get install unattended-upgrades
# Following are additional software required
# we only need mailutils or bsd-mailx, choose 1
sudo apt-get install mailutils
sudo apt-get install bsd-mailx
sudo apt-get install update-notifier-common Next, we need to edit the configuration files:
sudo nano /etc/apt/apt.conf.d/50unattended-upgradesThe configuration should be similar as below:
Unattended-Upgrade::Origins-Pattern {
// Codename based matching:
// This will follow the migration of a release through different
// archives (e.g. from testing to stable and later oldstable).
// "o=Debian,n=jessie";
// "o=Debian,n=jessie-updates";
// "o=Debian,n=jessie-proposed-updates";
// "o=Debian,n=jessie,l=Debian-Security";
"o=${distro_id},n=${distro_codename}";
"o=${distro_id},n=${distro_codename}-updates";
"o=${distro_id},n=${distro_codename}-proposed-updates";
"o=${distro_id},n=${distro_codename},l=Debian-Security";
// Archive or Suite based matching:
// Note that this will silently match a different release after
// migration to the specified archive (e.g. testing becomes the
// new stable).
// "o=Debian,a=stable";
// "o=Debian,a=stable-updates";
// "o=Debian,a=proposed-updates";
"origin=Debian,codename=${distro_codename},label=Debian-Security";
};
Unattended-Upgrade::Mail "username@example.com";
Unattended-Upgrade::Automatic-Reboot "true";
Basically, we commented out those type of upgrade we want to apply. The second last line allows the system to email us the status. We must install mailutils or mailx first in Raspbian for the email notification to be effective. The last line allow the system to reboot automatically. Please also make sure that update-notifier-common has been installed.
There are more option that we can set such as reboot time and log file in the configuration file. Uncomment any option when necessary.
Next, we need to amend another auto upgrade configuration file.
sudo nano /etc/apt/apt.conf.d/20auto-upgradesThe configuration files should have the following:
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::Verbose "1";
APT::Periodic::AutocleanInterval "7";
Finally, we perform a test to see if the upgrade process works:
sudo unattended-upgrade -d -v --dry-runTo enable unattended-upgrade use the following command:
sudo dpkg-reconfigure --priority=low unattended-upgradesSources:
- https://apiit.atlassian.net/wiki/spaces/ITSM/pages/1205567492/How+to+configure+postfix+relay+to+Office365+on+Ubuntu
- https://stackoverflow.com/questions/15827191/mail-command-not-found-error-while-script-execution
- https://mailutils.org/manual/html_section/configuration.html
- https://unix.stackexchange.com/questions/695987/how-can-i-make-gnu-mailutils-to-use-an-external-smtp-server
- https://mailtrap.io/blog/linux-send-email/
- https://learn.microsoft.com/en-us/answers/questions/1291815/how-can-i-sent-an-email-via-smtp-office365-com-fro?cid=kerryherger
Install postfix and mailutil
sudo apt-get update sudo apt-get install postfix mailutilsConfigure postfix to use Office365 in /etc/postfix/main.cf
mynetworks = 127.0.0.0/8
inet_interfaces = loopback-only
smtp_use_tls = yes
smtp_always_send_ehlo = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_tls_security_level = encrypt
smtp_generic_maps = hash:/etc/postfix/generic
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
Remove any domain you want to be able to send mail to from mydestination.
Configure mail credentials in /etc/postfix/sasl_passwd
[smtp.office365.com]:587 username@yourdomain.com:password
Update postfix maps
sudo chown root:root /etc/postfix/sasl_passwd
sudo chmod 0600 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwdConfigure mail address in /etc/postfix/generic
sudo nano /etc/postfix/genericroot@localdomain user@domain.com
@localdomain user@domain.com
Update postfix maps:
sudo chown root:root /etc/postfix/generic
sudo chmod 0600 /etc/postfix/generic
sudo postmap /etc/postfix/genericRestart postfix
sudo /etc/init.d/postfix restartSend test mail using
echo "This is a test body" | mail -s "Relay Test Email" user@publicdomain -a "FROM:user@domain.com"Send test mail using
--ssl-reqd \
--url 'smtp://smtp.office365.com:587' \
--user 'user@domain.com:password' \
--mail-from sender@domain.com \
--mail-rcpt recipient@domain.com \
--upload-file - <<EOF
From: Sender <sender@domain.com>
To: Recipient <recipient@domain.com>
Subject: Test mail
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
This is a test mail sent from Linux.EOF