What is postfix in ubuntu

Postfix is the default Mail Transfer Agent (MTA) in Ubuntu. It attempts to be fast and secure, with flexibility in administration. It is compatible with the MTA sendmail. This section will explain installation, including how to configure SMTP for secure communications.

Note

This guide does not cover setting up Postfix Virtual Domains, for information on Virtual Domains and other advanced configurations see References.

Installation

To install Postfix run the following command:

sudo apt install postfix

For now, it is ok to simply accept defaults by pressing return for each question. Some of the configuration options will be investigated in greater detail in the next stage.

Deprecation warning: please note that the mail-stack-delivery metapackage has been deprecated in Focal. The package still exists for compatibility reasons, but won’t setup a working email system.

Basic Configuration

There are four things you should decide before starting configuration:

  • The <Domain> for which you’ll accept email (we’ll use mail.example.com in our example)
  • The network and class range of your mail server (we’ll use 192.168.0.0/24)
  • The username (we’re using steve)
  • Type of mailbox format (mbox is default, we’ll use the alternative, Maildir)

To configure postfix, run the following command:

sudo dpkg-reconfigure postfix

The user interface will be displayed. On each screen, select the following values:

  • Internet Site
  • mail.example.com
  • steve
  • mail.example.com, localhost.localdomain, localhost
  • No
  • 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 192.168.0.0/24
  • 0
  • +
  • all

To set the mailbox format, you can either edit the configuration file directly, or use the postconf command. In either case, the configuration parameters will be stored in /etc/postfix/main.cf file. Later if you wish to re-configure a particular parameter, you can either run the command or change it manually in the file.

To configure the mailbox format for Maildir:

sudo postconf -e 'home_mailbox = Maildir/'

Note

This will place new mail in /home/username/Maildir so you will need to configure your Mail Delivery Agent (MDA) to use the same path.

SMTP Authentication

SMTP-AUTH allows a client to identify itself through the SASL authentication mechanism, using Transport Layer Security (TLS) to encrypt the authentication process. Once authenticated the SMTP server will allow the client to relay mail.

To configure Postfix for SMTP-AUTH using SASL (Dovecot SASL), run these commands at a terminal prompt:

sudo postconf -e 'smtpd_sasl_type = dovecot'
sudo postconf -e 'smtpd_sasl_path = private/auth'
sudo postconf -e 'smtpd_sasl_local_domain ='
sudo postconf -e 'smtpd_sasl_security_options = noanonymous,noplaintext'
sudo postconf -e 'smtpd_sasl_tls_security_options = noanonymous'
sudo postconf -e 'broken_sasl_auth_clients = yes'
sudo postconf -e 'smtpd_sasl_auth_enable = yes'
sudo postconf -e 'smtpd_recipient_restrictions = \
permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination'

Note

The smtpd_sasl_path config parameter is a path relative to the Postfix queue directory.

There are several SASL mechanism properties worth evaluating to improve the security of your deployment. The options “noanonymous,noplaintext” prevent use of mechanisms that permit anonymous authentication or that transmit credentials unencrypted.

Next, generate or obtain a digital certificate for TLS. See security – certificates in this guide for details about generating digital certificates and setting up your own Certificate Authority (CA).

Note

MUAs connecting to your mail server via TLS will need to recognize the certificate used for TLS. This can either be done using a certificate from Let’s Encrypt, from a commercial CA or with a self-signed certificate that users manually install/accept. For MTA to MTA TLS certficates are never validated without advance agreement from the affected organizations. For MTA to MTA TLS, unless local policy requires it, there is no reason not to use a self-signed certificate. Refer to security – certificates in this guide for more details.

Once you have a certificate, configure Postfix to provide TLS encryption for both incoming and outgoing mail:

sudo postconf -e 'smtp_tls_security_level = may'
sudo postconf -e 'smtpd_tls_security_level = may'
sudo postconf -e 'smtp_tls_note_starttls_offer = yes'
sudo postconf -e 'smtpd_tls_key_file = /etc/ssl/private/server.key'
sudo postconf -e 'smtpd_tls_cert_file = /etc/ssl/certs/server.crt'
sudo postconf -e 'smtpd_tls_loglevel = 1'
sudo postconf -e 'smtpd_tls_received_header = yes'
sudo postconf -e 'myhostname = mail.example.com'

If you are using your own Certificate Authority to sign the certificate enter:

sudo postconf -e 'smtpd_tls_CAfile = /etc/ssl/certs/cacert.pem'

Again, for more details about certificates see security – certificates in this guide.

Note

After running all the commands, Postfix is configured for SMTP-AUTH and a self-signed certificate has been created for TLS encryption.

Now, the file /etc/postfix/main.cf should look like this:

# See /usr/share/postfix/main.cf.dist for a commented, more complete
# version

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

myhostname = server1.example.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = server1.example.com, localhost.example.com, localhost
relayhost =
mynetworks = 127.0.0.0/8
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
smtpd_sasl_local_domain =
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions =
permit_sasl_authenticated,permit_mynetworks,reject _unauth_destination
smtpd_tls_auth_only = no
smtp_tls_security_level = may
smtpd_tls_security_level = may
smtp_tls_note_starttls_offer = yes
smtpd_tls_key_file = /etc/ssl/private/smtpd.key
smtpd_tls_cert_file = /etc/ssl/certs/smtpd.crt
smtpd_tls_CAfile = /etc/ssl/certs/cacert.pem
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom

The postfix initial configuration is complete. Run the following command to restart the postfix daemon:

sudo systemctl restart postfix.service

Postfix supports SMTP-AUTH as defined in RFC2554. It is based on SASL. However it is still necessary to set up SASL authentication before you can use SMTP-AUTH.

When using ipv6, the mynetworks parameter may need to be modified to allow ipv6 addresses, for example:

 mynetworks = 127.0.0.0/8, [::1]/128

Configuring SASL

Postfix supports two SASL implementations: Cyrus SASL and Dovecot SASL. To enable Dovecot SASL the dovecot-core package will need to be installed:

sudo apt install dovecot-core

Next, edit /etc/dovecot/conf.d/10-master.conf and change the following:

service auth {
  # auth_socket_path points to this userdb socket by default. It's typically
  # used by dovecot-lda, doveadm, possibly imap process, etc. Its default
  # permissions make it readable only by root, but you may need to relax these
  # permissions. Users that have access to this socket are able to get a list
  # of all usernames and get results of everyone's userdb lookups.
  unix_listener auth-userdb {
    #mode = 0600
    #user = 
    #group = 
  }

  # Postfix smtp-auth
  unix_listener /var/spool/postfix/private/auth {
    mode = 0660
    user = postfix
    group = postfix
  }
 }

To permit use of SMTP-AUTH by Outlook clients, change the following line in the authentication mechanisms section of /etc/dovecot/conf.d/10-auth.conf from:

auth_mechanisms = plain

to this:

auth_mechanisms = plain login

Once you have Dovecot configured, restart it with:

sudo systemctl restart dovecot.service

Testing

SMTP-AUTH configuration is complete. Now it is time to test the setup.

To see if SMTP-AUTH and TLS work properly, run the following command:

telnet mail.example.com 25

After you have established the connection to the Postfix mail server, type:

ehlo mail.example.com

If you see the following in the output, then everything is working perfectly. Type quit to exit.

250-STARTTLS
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250 8BITMIME

Troubleshooting

When problems arise, there are a few common ways to diagnose the cause.

Escaping chroot

The Ubuntu Postfix package will by default install into a chroot environment for security reasons. This can add greater complexity when troubleshooting problems.

To turn off the chroot usage, locate the following line in the /etc/postfix/master.cf configuration file:

smtp      inet  n       -       -       -       -       smtpd

and modify it as follows:

smtp      inet  n       -       n       -       -       smtpd

You will then need to restart Postfix to use the new configuration. From a terminal prompt enter:

sudo service postfix restart

SMTPS

If you need secure SMTP, edit /etc/postfix/master.cf and uncomment the following line:

smtps     inet  n       -       -       -       -       smtpd
  -o smtpd_tls_wrappermode=yes
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
  -o milter_macro_daemon_name=ORIGINATING
      

Log Viewing

Postfix sends all log messages to /var/log/mail.log. However, error and warning messages can sometimes get lost in the normal log output so they are also logged to /var/log/mail.err and /var/log/mail.warn respectively.

To see messages entered into the logs in real time you can use the tail -f command:

tail -f /var/log/mail.err

Increasing Logging Detail

The amount of detail that is recorded in the logs can be increased via the configuration options. For example, to increase TLS activity logging set the smtpd_tls_loglevel option to a value from 1 to 4.

    sudo postconf -e 'smtpd_tls_loglevel = 4'

Reload the service after any configuration change, to make the new config active:

    sudo systemctl reload postfix.service

Logging mail delivery

If you are having trouble sending or receiving mail from a specific domain you can add the domain to the debug_peer_list parameter.

    sudo postconf -e 'debug_peer_list = problem.domain'
    sudo systemctl reload postfix.service

Increasing daemon verbosity

You can increase the verbosity of any Postfix daemon process by editing the /etc/postfix/master.cf and adding a -v after the entry. For example, edit the smtp entry:

    smtp      unix  -       -       -       -       -       smtp -v

Then, reload the service as usual:

    sudo systemctl reload postfix.service

Logging SASL debug info

To increase the amount of information logged when troubleshooting SASL issues you can set the following options in /etc/dovecot/conf.d/10-logging.conf

    auth_debug=yes
    auth_debug_passwords=yes

Just like Postfix if you change a Dovecot configuration the process will need to be reloaded:

    sudo systemctl reload dovecot.service

Note

Some of the options above can drastically increase the amount of information sent to the log files. Remember to return the log level back to normal after you have corrected the problem. Then reload the appropriate daemon for the new configuration to take affect.

Read More

How to check logs in ubuntu

Goto /var/log diretcory

$ cd /var/log

List files and directories date wise descending order

$ ls -alt

ls by date in reverse date order use the -t flag as before but this time with the -r flag which is for ‘reverse’.

check which website get more load on ubuntu

System Load or System Load Average

It is run-queue i.e a queue of processes waiting for a resource(cpu, i/o etc.) to become available .

Consider a single-core cpu as a single lane of traffic with bridge and process as cars.

Now in this situation System load is

  • 0.0 – If there is no traffic on the road.
  • 1.0 -If the traffic on the road is exactly the capacity of bridge.
  • More than 1 – If the traffic on road is higher than the capacity of bridge and cars have to wait to pass trough the bridge.

This number is not normalized according to your cpu. In Multiprocessor system, load 2 mean 100 % utilization of we are using dual-core processor, load 4 means 100% utilization if we are using quad-core.

You can get your system load using

  • uptime
  • cat /proc/loadavg
  • top$uptime 22:49:47 up 11:47, 4 users, load average: 2.20, 1.03, 0.82

Here the last three number representing the system load average for 1, 5 and 15 minutes respectively.

The example above indicates that on average there were 2.20 processes waiting to be scheduled on the run-queue measured over the last minute.

check which website get more load on ubuntu

This works very well:

 while true; do uptime >> uptime.log; sleep 1; done
  • This will log your cpu load every second and append it to a file uptime.log.You can then import this file into Gnumeric or the OpenOffice spreadsheet to create a nice graph (select ‘separated by spaces’ on import).

As Scaine noticed, this won’t be enough to diagnose the problem. So, additionally, run this (or use his answer for this part):

while true; do (echo "%CPU %MEM ARGS $(date)" && ps -e -o pcpu,pmem,args --sort=pcpu | cut -d" " -f1-5 | tail) >> ps.log; sleep 5; done
  • This will append the Top 10 most CPU hungry processes to a file ps.log every five seconds.Note that this is not the full boat-load of information top would give you. This is just the top 10, and just their CPU Usage, Memory Usage and the first argument (i.e. their command without further arguments, as in /usr/bin/firefox)

After you’ve used a Spreadsheet to create a graph to see when your CPU load went through the roof, you can then search this file for the nearest time to see what process has caused it.

This is what those files will look like:

uptime.log

~$ cat uptime.log 
 22:57:42 up 1 day,  4:38,  4 users,  load average: 1.00, 1.26, 1.21
 22:57:43 up 1 day,  4:38,  4 users,  load average: 0.92, 1.24, 1.21
 22:57:44 up 1 day,  4:38,  4 users,  load average: 0.92, 1.24, 1.21
 22:57:45 up 1 day,  4:38,  4 users,  load average: 0.92, 1.24, 1.21
 ...

ps.log

%CPU %MEM ARGS Mo 17. Jan 23:09:47 CET 2011
 0.7  0.9 /usr/bin/compiz
 0.8  0.5 /usr/lib/gnome-panel/clock-applet
 1.1  1.7 /opt/google/chrome/chrome
 1.2  0.3 /usr/bin/pulseaudio
 1.8  4.0 /opt/google/chrome/chrome
 2.6  1.5 /opt/google/chrome/chrome
 2.6  3.2 /usr/bin/google-chrome
 3.6  2.6 /opt/google/chrome/chrome
 4.9  1.5 /usr/bin/X
 5.7  1.6 /opt/google/chrome/chrome
%CPU %MEM ARGS Mo 17. Jan 23:09:48 CET 2011
 0.7  0.9 /usr/bin/compiz
 0.8  0.5 /usr/lib/gnome-panel/clock-applet
 1.0  1.7 /opt/google/chrome/chrome
 1.2  0.3 /usr/bin/pulseaudio
 1.8  4.0 /opt/google/chrome/chrome
 2.6  1.5 /opt/google/chrome/chrome
 2.6  3.2 /usr/bin/google-chrome
 3.6  2.6 /opt/google/chrome/chrome
 4.9  1.5 /usr/bin/X
 5.7  1.6 /opt/google/chrome/chrome
 ...

remove all mail services from ubuntu

remove sendmail ubuntu

$ sudo apt-get purge sendmail*
$ apt-get remove sendmail
$ apt-get purge sendmail

remove postfix ubuntu

$ sudo apt remove postfix && apt purge postfix
$ sudo autoremove

When I install Postfix again, the installation does not ask the questions like on the first installation. I still have my previous configuration. Why can not I reset the Postfix configuration ?

If I reconfigure Postfix, I still have the previous configuration :

$ sudo dpkg-reconfigure postfix

remove mailutils ubuntu

$ sudo apt-get remove  mailutils
$ sudo apt-get remove --auto-remove mailutils
$ sudo apt-get purge mailutils
$ sudo apt-get purge --auto-remove mailutils

how to change email id in ubuntu server

By default, any email sent by system is sent to root@hostname. So critical server errors, log errors, corn jobs alerts e.t.c all are sent to this default email address. To change it to different appropriate email id, we can do this by two ways.

By updating email aliases file:

For this example, lets set email to system@mydomain.com

Step 1 : edit /etc/aliases file 

$ vi /etc/aliases

Add email ids at the bottom of the file.

postmaster: system@mydmomain.com

To add multiple email ids, we can simply separate them by comma.

postmaster: system@mydomain.com, linux@mydomain.com

linux@mydomain.com is second email id 

Step 2: Run the aliases command, to compile aliases file. 

$ newaliases

Step 3: Restart postfix server.

service postfix restart

Second way:

We can simply create .forward file to the folder root and add email address there.

$ vi /root/.forward
system@mydomain.com

Restart postfix server
$ service postfix restart.

How to change phpmyadmin url of ubuntu aws server

How to change phpmyadmin url of ubuntu aws server

http://www.domain.in/dbaditya/

this is the url

in this video we change dbaditya to newname

  1. login into server using putty
  2. cd /etc
  3. cd phpmyadmin
  4. ls
  5. sudo nano apache.conf
  6. modify this line Alias /dbaditya /usr/share/phpmyadmin
  7. ctrl + x and press y for exit
  8. sudo service apache2 restart for restart the apache service

Note: top command to show process monitor of server

q used for quit from top command window/screen

http://www.domain.in/mynewdata/
Done URL succcessfully changed

change default auto login user in ubuntu

sudo leafpad /etc/lxdm/default.conf
sudo leafpad /etc/lightdm/fileexample.conf

In the fist few line, you will see something like autologin=username change it to the original state of # autologin=dgod. Save the file, and then reboot your machine.

autologin-user=username
autologin-user-timeout=0

Using privileged admin account open up terminal or your favorite text file editor and edit the /etc/gdm3/custom.conf configuration file. Change from:

[daemon]
# Uncoment the line below to force the login screen to use Xorg
#WaylandEnable=false

# Enabling automatic login
#  AutomaticLoginEnable = true
#  AutomaticLogin = user1

php mail function not working on ubuntu server

I want to enable the simple php mail() function on an Ubuntu server.

three steps

sudo apt-get install sendmail
sudo sendmailconfig (answer Yes to everything)
sudo service apache2 restart

wget command in ubuntu

GNU Wget is a command-line utility for downloading files from the web. With Wget, you can download files using HTTP, HTTPS, and FTP protocols. Wget provides a number of options allowing you to download multiple files, resume downloads, limit the bandwidth, recursive downloads, download in the background, mirror a website and much more.

Installing Wget on Ubuntu and Debian 

sudo apt install wget

Installing Wget on CentOS and Fedora

sudo yum install wget

The wget utility expressions take the following form:

$ wget [options] [url]

Copy

  • options – The Wget options
  • url – URL of the file or directory you want to download or synchronize.

How to Download a File with Wget

In it’s simplest form when used without any option, wget will download the resource specified in the [url] to the current directory.

In the following example we are downloading the Linux kernel tar archive:

$ wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.17.2.tar.xz

Using Wget Command to Save the Downloaded File Under Different Name

To save the downloaded file under a different name, pass the -O option followed by the chosen name:

$ wget -O latest-hugo.zip https://github.com/gohugoio/hugo/archive/master.zip

The command above will save the latest hugo zip file from GitHub as latest-hugo.zip instead of its original name.

Using Wget Command to Download a File to a Specific Directory

By default, Wget will save the downloaded file in the current working directory. To save the file to a specific location, use the -P option:

$ wget -P /mnt/iso http://mirrors.mit.edu/centos/7/isos/x86_64/CentOS-7-x86_64-Minimal-1804.iso

How to Limit the Download Speed with Wget

To limit the download speed, use the --limit-rate option. By default, the speed is measured in bytes/second. Append k for kilobytes , m for megabytes and g for gigabytes.

The following command will download the Go binary and limit the download speed to 1mb:

$ wget --limit-rate=1m https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz

This option is useful when you don’t want wget to consume all the available bandwidth.

How to Resume a Download with Wget

You can resume a download using the -c option. This is useful if your connection drops during a download of a large file, and instead of starting the download from scratch, you can continue the previous one.

In the following example we are resuming the download of the Ubuntu 18.04 iso file:

$ wget -c http://releases.ubuntu.com/18.04/ubuntu-18.04-live-server-amd64.iso

If the remote server does not support resuming downloads, Wget will start the download from the beginning and overwrite the existing file.

How to Download in Background with Wget

To download in the background ,use the -b option. In the following example, we are downloading the OpenSuse iso file in the background:

$ wget -b https://download.opensuse.org/tumbleweed/iso/openSUSE-Tumbleweed-DVD-x86_64-Current.iso

By default, the output is redirected to wget-log file in the current directory. To watch the status of the download, use the tail command:

$ tail -f wget-log

How to change the Wget User-Agent of Wget

Sometimes when downloading a file, the remote server may be set to block the Wget User-Agent. In situations like this to emulate a different browser pass the -U option.

wget --user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0" http://wget-forbidden.com/

The command above will emulate Firefox 60 requesting the page from wget-forbidden.com

How to Download Multiple Files with Wget

If you want to download multiple files at once, use the -i option followed by the path to a local or external file containing a list of the URLs to be downloaded. Each URL needs to be on a separate line.

In the following example we are downloading the Arch Linux, Debian, and Fedora iso files with URLs specified in the linux-distros.txt file:

$ wget -i linux-distros.txt

linux-distros.txt

http://mirrors.edge.kernel.org/archlinux/iso/2018.06.01/archlinux-2018.06.01-x86_64.iso
https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-9.4.0-amd64-netinst.iso
https://download.fedoraproject.org/pub/fedora/linux/releases/28/Server/x86_64/iso/Fedora-Server-dvd-x86_64-28-1.1.iso

Copy

If you specify - as a filename, URLs will be read from the standard input.

Using Wget Command to Download via FTP

To download a file from a password-protected FTP server, specify the username and password as shown below:

$ wget --ftp-user=FTP_USERNAME --ftp-password=FTP_PASSWORD ftp://ftp.example.com/filename.tar.gz

Using Wget Command to Create a Mirror of a Website

To create a mirror of a website with Wget, use the -m option. This will create a complete local copy of the website by following and downloading all internal links as well as the website resources (JavaScript, CSS, Images).

$ wget -m https://example.com

If you want to use the downloaded website for local browsing, you will need to pass a few extra arguments to the command above.

$ wget -m -k -p https://example.com

The -k option will cause Wget to convert the links in the downloaded documents to make them suitable for local viewing. The -p option will tell wget to download all necessary files for displaying the HTML page.

How to Skip Certificate Check with Wget

If you want to download a file over HTTPS from a host that has an invalid SSL certificate, use the --no-check-certificate option:

$ wget --no-check-certificate https://domain-with-invalid-ss.com

How to Download to Standard Output with Wget

In the following example, Wget will quietly ( flag -q) download and output the latest WordPress version to stdout ( flag -O -) and pipe it to the tar utility which will extract the archive to the /var/www directory.

$ wget -q -O - "http://wordpress.org/latest.tar.gz" | tar -xzf - -C /var/www