No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

README.md 6.4 KiB

hace 5 años
hace 1 año
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 1 año
hace 5 años
hace 5 años
hace 1 año
hace 1 año
hace 5 años
hace 1 año
hace 5 años
hace 1 año
hace 1 año
hace 5 años
hace 5 años
hace 5 años
hace 4 años
hace 4 años
hace 1 año
hace 1 año
hace 5 años
hace 1 año
hace 1 año
hace 1 año
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. # Email server setup script
  2. This script installs an email server with all the features required in the
  3. modern web.
  4. I've linked this file on Github to a shorter, more memorable address on my
  5. website so you can get it on your machine with this short command:
  6. ```sh
  7. curl -LO lukesmith.xyz/emailwiz.sh
  8. ```
  9. When prompted by a dialog menu at the beginning, select "Internet Site", then
  10. give your full domain without any subdomain, e.g. `lukesmith.xyz`.
  11. I'm glad to say that dozens, hundreds of people have now used it and there is a
  12. sizeable network of people with email servers thanks to this script.
  13. ## This script installs
  14. - **Postfix** to send and receive mail.
  15. - **Dovecot** to get mail to your email client (mutt, Thunderbird, etc.).
  16. - Config files that link the two above securely with native PAM log-ins.
  17. - **Spamassassin** to prevent spam and allow you to make custom filters.
  18. - **OpenDKIM** to validate you so you can send to Gmail and other big sites.
  19. - **Certbot** SSL certificates, if not already present.
  20. - **fail2ban** to increase server security, with enabled modules for the above
  21. programs.
  22. - (optionally) **a self-signed certificate** instead of OpenDKIM and Certbot. This allows to quickly set up an isolated mail server that collects email notifications from devices in the same local network(s) or serves as secure/private messaging system over VPN.
  23. ## This script does _not_...
  24. - use a SQL database or anything like that. We keep it simple and use normal
  25. Unix system users for accounts and passwords.
  26. - set up a graphical web interface for mail like Roundcube or Squirrel Mail.
  27. You are expected to use a normal mail client like Thunderbird or K-9 for
  28. Android or good old mutt with
  29. [mutt-wizard](https://github.com/lukesmithxyz/mutt-wizard). Note that there
  30. is a guide for [Rainloop](https://landchad.net/rainloop/) on
  31. [LandChad.net](https://landchad.net) for those that want such a web
  32. interface.
  33. ## Prerequisites for Installation
  34. 1. Debian or Ubuntu server.
  35. 2. DNS records that point at least your domain's `mail.` subdomain to your
  36. server's IP (IPv4 and IPv6). This is required on initial run for certbot to
  37. get an SSL certificate for your `mail.` subdomain.
  38. ## Mandatory Finishing Touches
  39. ### Unblock your ports
  40. While the script enables your mail ports on your server, it is common practice
  41. for all VPS providers to block mail ports on their end by default. Open a help
  42. ticket with your VPS provider asking them to open your mail ports and they will
  43. do it in short order.
  44. ### DNS records
  45. At the end of the script, you will be given some DNS records to add to your DNS
  46. server/registrar's website. These are mostly for authenticating your emails as
  47. non-spam. The 4 records are:
  48. 1. An MX record directing to `mail.yourdomain.tld`.
  49. 2. A TXT record for SPF (to reduce mail spoofing).
  50. 3. A TXT record for DMARC policies.
  51. 4. A TXT record with your public DKIM key. This record is long and **uniquely
  52. generated** while running `emailwiz.sh` and thus must be added after
  53. installation.
  54. They will look something like this:
  55. ```
  56. @ MX 10 mail.example.org
  57. mail._domainkey.example.org TXT v=DKIM1; k=rsa; p=anextremelylongsequenceoflettersandnumbersgeneratedbyopendkim
  58. _dmarc.example.org TXT v=DMARC1; p=reject; rua=mailto:dmarc@example.org; fo=1
  59. example.org TXT v=spf1 mx a: -all
  60. ```
  61. The script will create a file, `~/dns_emailwiz` that will list our the records
  62. for your convenience, and also prints them at the end of the script.
  63. ### Add a rDNS/PTR record as well!
  64. Set a reverse DNS or PTR record to avoid getting spammed. You can do this at
  65. your VPS provider, and should set it to `mail.yourdomain.tld`. Note that you
  66. should set this for both IPv4 and IPv6.
  67. ## Making new users/mail accounts
  68. Let's say we want to add a user Billy and let him receive mail, run this:
  69. ```
  70. useradd -m -G mail billy
  71. passwd billy
  72. ```
  73. Any user added to the `mail` group will be able to receive mail. Suppose a user
  74. Cassie already exists and we want to let her receive mail too. Just run:
  75. ```
  76. usermod -a -G mail cassie
  77. ```
  78. A user's mail will appear in `~/Mail/`. If you want to see your mail while ssh'd
  79. in the server, you could just install mutt, add `set spoolfile="+Inbox"` to
  80. your `~/.muttrc` and use mutt to view and reply to mail. You'll probably want
  81. to log in remotely though:
  82. ## Installing with self-signed certificate, in "isolated" mode
  83. This mode skips the setup of OpenDKIM and Certbot, and will instead create a self-signed cert that lasts 100 years. It also allows to customize the logic country name, state/province name and organization name to generate the certificate automatically. An example usecase is for an isolated server that collects notifications from devices in the same local network(s) or serves as secure/private messaging system over VPN (wireguard or whatever).
  84. This server with self-signed certificate as configured will NOT be able to send anything to public mail servers (Gmail, Outlook and so on), at least not directly.
  85. open the script and change the following line
  86. ```
  87. selfsigned="no" # yes no
  88. ```
  89. to become
  90. ```
  91. selfsigned="yes" # yes no
  92. ```
  93. it's also possible to customize and automate the self-signed certificate creation
  94. by changing the following lines in the script
  95. ```
  96. use_cert_config="no"
  97. ```
  98. to
  99. ```
  100. use_cert_config="yes"
  101. ```
  102. and then write country name, state/province name and organization name in the following lines
  103. ```
  104. country_name="" # IT US UK IN etc etc
  105. state_or_province_name=""
  106. organization_name=""
  107. ```
  108. ## Logging in from email clients (Thunderbird/mutt/etc)
  109. Let's say you want to access your mail with Thunderbird or mutt or another
  110. email program. For my domain, the server information will be as follows:
  111. - SMTP server: `mail.lukesmith.xyz`
  112. - SMTP port: 465
  113. - IMAP server: `mail.lukesmith.xyz`
  114. - IMAP port: 993
  115. ## Benefited from this?
  116. I am always glad to hear this script is still making life easy for people. If
  117. this script or documentation has saved you some frustration, donate here:
  118. - btc: `bc1qzw6mk80t3vrp2cugmgfjqgtgzhldrqac5axfh4`
  119. - xmr: `8A5v4Ci11Lz7BDoE2z2oPqMoNHzr5Zj8B3Q2N2qzqrUKhAKgNQYGSSaZDnBUWg6iXCiZyvC9mVCyGj5kGMJTi1zGKGM4Trm`
  120. ## Sites for Troubleshooting
  121. Can't send or receive mail? Getting marked as spam? There are tools to double-check your DNS records and more:
  122. - Always check `journalctl -xe` first for specific errors.
  123. - [Check your DNS](https://intodns.com/)
  124. - [Test your TXT records via mail](https://appmaildev.com/en/dkim)
  125. - [Is your IP blacklisted?](https://mxtoolbox.com/blacklists.aspx)
  126. - [mxtoolbox](https://mxtoolbox.com/SuperTool.aspx)