Create new users on Raspberry Pi
In this guide, I will show how to create new users from the terminal and how to get them ready for email
If you haven’t already, configure postfix email for Gmail or iCloud with these instructions.
New User
Create a new user with a home folder
$ sudo useradd <newuser> -m
Set the password
$ sudo passwd <newuser>
Create the mail file, otherwise, it will fail when running the mail command
$ sudo touch /var/mail/<newuser>
Set the appropriate file permissions
$ sudo chown <newuser>:mail /var/mail/<newuser>
$ sudo chmod o-r,g+w /var/mail/<newuser>
After the above, now you can run the mail
command as your new user, it should print our “No mail for <newuser>”
$ sudo su - <newuser>
$ mail
Test sending emails as your new user
$ echo "email body" | mail -a "From: Sender <sender@mail.com>" -s "Email Subject" RECIPIENT@EMAIL.COM
Forwarding email
Local users can send emails to each other using the mail
command, or daemons like bitcoind
can send notifications via email, but we would only know of these emails until after we login. If we would like to be notified right away, a solution is to enable forwarding, follow the steps below to forward any email sent to our local user:
$ echo "EMAIL@ADDRESS.COM" > ~/.forward
$ chmod 644 ~/.forward
EMAIL@ADDRESS.COM will now receive all emails sent to your local user
That’s it, enjoy!