
Linux çekirdeği resmi sitesi: https://www.kernel.org
Uzun süreli destek sürümü:
4.1.47 2017-12-07
Değişiklik listesi…
Archive | GNU/Linux
Shell Scripting Part4 – Input, Output, and Redirection
In the previous post, we talked about parameters and options in detail, today we will talk about something very important in shell scripting which are Input, Output, and Redirection. You can display the output from your shell scripts in two ways:
- Display output on the screen.
- Send output to a file.
Everything is a file in Linux and that includes input and output.
Each process can have 9 file descriptors opened at the same time. The file descriptors 0, 1, 2 are kept for the bash shell usage.
0 STDIN.
1 STDOUT.
2 STDERR.
You can use the above file descriptors to control input and output.
You need to fully understand these three because they are like the backbones of your shell scripting. So we are going to describe every one of them in detail.
STDIN
STDIN stands for standard input which is the keyboard by default.
You can replace the STDIN which is the keyboard and replace it with a file by using the input redirect symbol (<), it sends the data as keyboard typing. No magic!!
When you type the cat command without anything, it accepts input from STDIN. Any line you type, the cat command prints that line to the screen.
STDOUT
This stands for the standard output which is the screen by default.
You can redirect output to a file using the >> symbol.
If we have a file contains data, you can append data to it using this symbol like this:
pwd >> myfile
The output generated by pwd is appended to myfile without deleting the existed content.

The following command tries to redirect the output to a file using > symbol.
ls –l xfile > myfile

I have no file called xfile on my PC, and that generates an error which is sent to STDERR.
STDERR
This file descriptor is the standard error output of the shell which is sent to the screen by default.
If you need to redirect the errors to a log file instead of sending it to the screen, you can redirect errors using the redirection symbol.
Redirecting Errors
We can redirect the errors by placing the file descriptor which is 2 before the redirection symbol like this:
ls -l xfile 2>myfile
cat ./myfile

As you can see, the error now is in the file and nothing on the screen.
Redirecting Errors and Normal Output
To redirect errors and the normal output, you have to precede each with the proper file descriptor like this:
ls –l myfile xfile anotherfile 2> errorcontent 1> correctcontent

The ls command result is sent to the correctcontent file using the 1> symbol. And error messages were sent to the errorcontent file using the 2> symbol.
You can redirect normal output and errors to the same file using &> symbol like this:
ls –l myfile xfile anotherfile &> content

All errors and normal output are redirected to file named content.
Output Redirection
There are two ways for output redirection:
- Temporarily redirection.
- Permanently redirection.
Temporary Redirections
For temporary redirections, you can use the >&2 symbol like this:
#!/bin/bash
echo "Error message" >&2
echo "Normal message"

So if we run it, we will see both lines printed normally because as we know errors go to the screen by default.
You can redirect errors to a file like this:
./myscript 2> myfile

Shell scripting is Awesome! Normal output is sent to the screen, while the echo message which has >&2 symbol sends errors to the file.
Permanent Redirections
If you have much data that need to be redirected, you can have a permanent redirection using the exec command like this:
#!/bin/bash
exec 1>outfile
echo "Permanent redirection"
echo "from a shell to a file."
echo "without redirecting every line"

If we look at the file called outfile, we will see the output of the echo lines.
We redirect the STDOUT at the beginning, what about in the middle of a script like this:
#!/bin/bash
exec 2>myerror
echo "Script Begining ..."
echo "Redirecting Output"
exec 1>myfile
echo "Output goes to the myfile"
echo "Output goes to myerror file" >&2

The exec command redirects all errors to the file myerror, and standard output is sent to the screen.
The statement exec 1>myfile is used to redirect output to the myfile file, and finally, errors go to myerror file using >&2 symbol.
Redirecting Input
You can redirect input to a file instead of STDIN using exec command like this:
exec 0< myfile
This command tells the shell to take the input from a file called myfile instead of STDIN and here is an example:
#!/bin/bash
exec 0< testfile
total=1
while read line
do
echo "#$total: $line"
total=$(( $total + 1 ))
done

Shell scripting is easy.
You know how to use the read command to get user input. If you redirect the STDIN to a file, the read command will try to read from STDIN which points to the file.
Some Linux system administrators use this technique to read the log files for processing and we will discuss more ways to read the log on the upcoming posts in a professional way.
Creating Custom Redirection
You know that there are 9 file descriptors, you use only 3 of them for input, output, and error.
The remaining six file descriptors are available for use for input and output redirection.
The exec command is used to assign a file descriptor for output like this:
#!/bin/bash
exec 3>myfile
echo "This line appears on the screen"
echo "This line stored on myfile" >&3
echo "This line appears on the screen"

Creating Input File Descriptors
To redirect input file descriptors do the following:
1- Save the STDIN to another file descriptor.
2- Redirecting it to a file.
3- Revert STDIN to its original location.
Look at the following code to understand these steps:
#!/bin/bash
exec 7<&0
exec 0< myfile
total=1
while read line
do
echo "#$total: $line"
total=$(( $total + 1 ))
done
exec 0<&7
read -p "Finished? " res
case $res in
y) echo "Goodbye";;
n) echo "Sorry, this is the end.";;
esac

The STDIN is saved to file descriptor 7 and the STDIN is redirected to a file.
The STDIN reverted back to its original location after iterating over file lines.
The last read command just to make sure that STDIN is reverted back to and you can use the keyboard normally.
Close File Descriptors
The file descriptors are closed automatically when the script exits. If you want to close the file descriptor yourself, redirect the file descriptor to this symbol &- it will be closed.
#!/bin/bash
exec 3> myfile
echo "Testing ..." >&3
exec 3>&-
echo "Nothing works" >&3

As you can see, it gives error bad file descriptor because it is no longer exist.
lsof Command
The lsof command is used to list all the opened files on the system and background processes.
On many Linux systems like Fedora, the lsof command is located under /usr/sbin.
This is some of the important options for lsof command:
-p: for process ID.
-d: for the file descriptor.
You can get the process PID using $$ variable.

The -a is used to combine results of -p option and -d option.
Now, testing the command from a script:
#!/bin/bash
exec 4> myfile1
exec 5> myfile2
exec 6< myfile3
lsof -a -p $$ -d 0,1,2,4,5,6

The shell script creates the file descriptors 4 and 5 for writing and 6 for reading.
Suppressing Command Output
Sometimes you don’t want to see any output. We redirect the output to the black hole which is /dev/null.
For example, we can suppress errors like this:
ls -al badfile anotherfile 2> /dev/null
And this idea is also used when you want to truncate a file without deleting it completely.
cat /dev/null > myfile
Now you understand the input, output, how to redirect them, how to create your own file descriptor, and redirect to it.
I hope you enjoy it. keep coming back.
Thank you.
Debian Installer Buster Alpha 2 duyuruldu
Debian 10 Buster’in ikinci alpha sürümü, Cyril Brulebois tarafından duyuruldu. Debian Installer ekibinin Buster’in ikinci alpha sürümünü duyurmaktan memnuniyet duyduğunu söyleyen Brulebois; güvenlik yükseltmelerinin otomatik olarak yüklenmesini sağlamak istediklerini ifade etti. Bunun bir test sürümü olduğunun unutulmaması ve yalnızca test etmek amacıyla kullanılması gerektiği hatırlatılırken, test eden kullanıcıların tespit ettikleri hataları rapor etmeleri rica edildi. 4.13.0-1 Linux çekirdeği üzerine yapılandırılan sistemde, pek çok paketin günxcellenmiş olduğunu belirten Brulebois; sisteme ext4 64bit özelliği için destek eklendiğini söyledi. 75 dilin desteklendiği ve 25’inin tam çevirisinin tamamlandığı belirtilen sürümde, önemli oranda donanım desteği sağlandığı ifade ediliyor. Debian Installer Buster Alpha 2 hakkında geniş bilgi edinmek için sürüm duyurusunu inceleyebilirsiniz.
Debian Installer Buster Alpha 2 edinmek için aşağıdaki linklerden yararlanabilirsiniz.
Linux Bash Scripting Part3 – Parameters and Options
So far you’ve seen how to write Linux bash scripts that do the job without user inputs. Today we will continue our series about Linux bash scripting. I recommend you to review the previous posts if you want to know what we are talking about: bash scripting part1 and bash scripting part2. Today we will know how to retrieve input from the user and deal with that input, so our script becomes more interactive. To pass data to your shell script, you should use command line parameters.
$ ./myscript 3 5
Here we send 2 parameters (3 and 5) to the script. So how to read these parameters in our bash script?
Read Parameters
The shell gives you some read to use variables to process input parameters:
- $0 is the script’s name.
- $1 is the 1st parameter.
- $2 is the 2nd parameter.
Until the 9th parameter which is $9.
Let’s see those variables in action:
#!/bin/bash
# Script name
echo $0
# 1st parameter
echo $1
# 2nd parameter
echo $2
# 3rd parameter
echo $3
Check the results of the following command:
./myscript 5 10 15

Here is another example of how we can use two parameters and calculate the sum of them.
#!/bin/bash
total=$(( $1 + $2 ))
echo First passed parameter is $1.
echo Second passed parameter is $2.
echo Total is $total.
$ ./myscript 5 10

The parameters are not restricted to numbers, they could be strings like this:
#!/bin/bash
echo Hello $1, how do you do
./myscript Adam
And the result is as expected.

What if our parameter contains a space and we want to pass it as one value? I guess you know the answer from the previous posts. The answer is to use quotations.
If your script requires over nine parameters, you should use braces like this ${10}.
Check Parameters
If you don’t pass parameters and your code expecting it, your script will exit with an error.
That’s why we should an if statement to make sure that they exist.
#!/bin/bash
if [ -n "$1" ]
# If first parameter passed then print Hi
then
echo Hi $1.
else
echo "No parameters found. "
fi

Counting Parameters
To get how many parameters passed, you can use this variable ($#).
#!/bin/bash
echo There were $# parameters passed.
./myscript 1 2 3 4 5

How awesome is Linux bash scripting? This variable also provides a geeky way to get the last parameter. Look at this trick:
#!/bin/bash
echo Last passed parameter is ${!#}

Grabbing All Parameters
The $* variable holds all the parameters as one value.
The $@ variable holds all the parameters as separate values, so you can iterate over them.
This code shows how to use them:
#!/bin/bash
echo "The first variable \$* method: $*"
echo "-----------"
echo "The second variable \$@ method: $@"

The same result, but if you want to know the difference look at the following example:
#!/bin/bash
total=1
for var in "$*"
do
echo "\$* =======> #$total = $var"
total=$(( $total + 1 ))
done
total=1
for var in "$@"
do
echo "\$@ =======> #$total = $var"
total=$(( $total + 1 ))
done
Check the result to see the difference:

The result is pretty clear. You can use any one of them according to your needs.
Shift command
The shift command moves every parameter variable to the left:
variable $3 ==> variable $2.
variable $2 ==> variable $1.
variable $1 ==> dropped.
variable $0 ==> (the script name) as it is.
You can use the shift command to iterate over parameters like this:
#!/bin/bash
total=1
while [ -n "$1" ]
# while loop starts
do
echo "#$total = $1"
total=$(( $total + 1 ))
shift
done
Here, we have a while loop checking $1 length. If $1 becomes zero, the loop stops. And the shift command is shifting all passed parameters to the left.

Careful when using shift command, the shifted parameter is gone and cannot be recovered.
Bash Scripting Options
Options are single letters with a dash before it.
#!/bin/bash
echo
while [ -n "$1" ]
# while loop starts
do
case "$1" in
# Message for -a option
-a) echo "-a option passed" ;;
# Message for -b option
-b) echo "-b option passed" ;;
# Message for -c option
-c) echo "-c option passed" ;;
# In case you typed a different option other than a,b,c
*) echo "Option $1 not recognized" ;;
esac
shift
done
$ ./myscript -op1 -op2 -op3 -op4

The code check for one of the correct options. If you typed one of them, the suitable commands will run.
Separate Options From Parameters
Sometimes you need to use options and parameters on the same script. You have to separate them. By doing this, you are telling the bash where are the parameters and where are the options.
The double dash (–) is used to end the options list. After the shell sees the double dash, the remaining inputs are treated as parameters and not as options.
#!/bin/bash
while [ -n "$1" ]
# while loop starts
do
case "$1" in
# Message for -a option
-a) echo "-a option passed" ;;
# Message for -b option
-b) echo "-b option passed";;
# Message for -c option
-c) echo "-c option passed" ;;
# The double dash which separates options from parameters
--) shift
# Exit the loop using break command
break ;;
*) echo "Option $1 not recognized";;
esac
shift
done
total=1
for param in $@
do
echo "#$total: $param"
total=$(( $total + 1 ))
done
$ ./myscript -a -b -c -- 5 10 15

As you can see from the result, all the parameters after the double dash treated as parameters and not options.
Process Options With Values
When you dig deep onto Linux bash scripting, sometimes you need options with additional parameter values like this:
./myscript -a value1 -b -c value2
There should be a way to identify any additional parameter for the options and be able to process it.
#!/bin/bash
while [ -n "$1" ]
# while loop starts
do
case "$1" in
-a) echo "-a option passed";;
-b) param="$2"
echo "-b option passed, with value $param"
shift ;;
-c) echo "-c option passed";;
# The double dash makes them parameters
--) shift
break ;;
*) echo "Option $1 not recognized";;
esac
shift
done
total=1
for param in "$@"
do
echo "#$total: $param"
total=$(( $total + 1 ))
done
And if we run it with these options:
$ ./myscript -a -b test1 -d

From the results, you can see that we get the parameter for the -b option using the $2 variable.
Standard Options
When you start your Linux bash scripting, you are free to choose which letter is suitable for your option.
However, there are some letters that are commonly used in Linux programs.
And here is the list of the common options:
-a List all items.
-c Get count of items.
-d Output directory.
-e Expands items.
-f To specify a file.
-h To show help page.
-i To ignore character case.
-l To list a text.
-n To say no for a question.
-o To send output to a file or so.
-q Keep silent don’t ask the user.
-r To process something recursively.
-s Stealth mode.
-v Verbose mode.
-x Specify executable.
-y To say yes without prompting the user.
If you work with Linux, many of these options may look familiar to you.
it’s good to follow standards.
Getting User Input
Sometimes you need data from the user while the bash scripting is running.
The bash shell uses the read command for this purpose.
The read command reads input from standard input (the keyboard) or from a file descriptor and stores it in a variable:
#!/bin/bash
echo -n "What's your name: "
read name
echo "Hi $name,"
The -n option is used to disable the newline, so you can type your text in the same line.

You can specify multiple inputs like this:
#!/bin/bash
read -p "What's your name: " first last
echo "Your data for $last, $first…"

If you don’t specify variables for the read command, all incoming inputs are saved in REPLY variable.
#!/bin/bash
read -p "What's your name: "
echo Hello $REPLY,.

You can use the -t option to specify a timeout for input in seconds.
#!/bin/bash
if read -t 5 -p "What's your name: " name
then
echo "Hi $name, how are you?"
else
echo "You took much time!"
fi
If you do not enter data for five seconds the script will execute the else clause and print a sorry message.

Reading Password
In Linux bash scripting, sometimes you don’t want the user input to be displayed on the screen, like entering a password.
The -s option hides the data entered in the read command.
The data is actually printed on the screen, but the read command makes the text color as the background color of the shell.
#!/bin/bash
read -s -p "Enter password: " mypass
echo "Your password is $mypass? "

Read Files
The read command can read files one line on each call.
Now, if you want to get all file data, you can get the content using the cat command, then send it to the read command using while loop like this:
#!/bin/bash
count=1
# Get file content then pass to read command by iterating over lines using while command
cat myfile | while read line
do
echo "#$count: $line"
count=$(( $count + 1 ))
done
echo "Finished"

We just pass the file content to the while loop and iterate over every line and print the line number and the content, and each time you increase the count by one.
I hope you find this post interesting. Keep coming back.
Thank you.
Install, Secure, Access and Configure Linux Mail Server
If you want to send or receive an email, you should have a mail server. In this post, we will discuss Linux mail server and how the SMTP (Simple Mail Transfer Protocol) works as well as other mail-related protocols, like Post Office Protocol (POP) and Internet Message Access Protocol (IMAP) and the relationship between them. SMTP defines how a mail is sent from one host to another, it is also system independent, which means the sender and receiver can have different operating systems. SMTP requires only that a server is able to send straight ASCII text to another server, and this is done by connecting to the server on port 25 which is the standard SMTP port. Most Linux distros today are shipped with two of the most common implementations of SMTP which are sendmail and Postfix. Sendmail is a famous and free mail server, but it has a little complex design and less secure. The Postfix took mail server implementation one step further, it was developed with security in mind.
Mail Service Components
The mail service on any mail server has three components:
Mail user agent (MUA): this component that the user sees and interacts with like Thunderbird and Microsoft Outlook, these user agents are responsible for reading mail and allowing you to compose mail.
Mail transport agent (MTA): this component is responsible for getting the mail from one site to another like Sendmail and Postfix.
Mail delivery agent (MDA): this component is responsible for distributing received messages on the local machine to the appropriate user mailbox like postfix-maildrop and Procmail.
Setup Email Server
We chose Postfix mail server, which is very popular and common between system administrators today.
Postfix is the default mail server on most modern Linux distros.
First, check if it is installed on your system or not:
$ rpm -qa | grep postfix
If not installed, you can install Postfix mail server on Red Hat based distros like this:
$ dnf -y install postfix
Then start the postfix service and enable it on system startup:
$ systemctl start postfix
$ systemctl enable postfix
On Debian based distros like Ubuntu, you can install it like this:
$ apt-get -y install postfix
You will be prompted to select your Postfix mail server configuration type during the installation process.
Among the four choices No configuration, Internet site, Internet with smarthost, Satellite system and Local only, we will choose No configuration option.
Configure Linux Mail Server
After installing the Postfix mail server, you will need to configure it, most of its configuration files can be found under the /etc/postfix/ directory.
You can find the main configuration for Postfix mail server in /etc/postfix/main.cf file.
This file contains a lot of options like:
myhostname
This option is used for specifying the hostname of the mail server. This is the Internet hostname which Postfix will receive emails on it.
The hostnames could be like mail.example.com, smtp.example.com.
It is written like this:
myhostname = mail.example.com
mydomain
This option is the mail domain that you will be servicing, like example.com
The syntax is like this:
mydomain = example.com
myorigin
All emails sent from this mail server will look as though it came from this option. You can set this to $mydomain value.
myorigin = $mydomain
You can use any option value, just precede it with a $ like $mydomain.
mydestination
This option lists the domains that the Postfix server uses for incoming emails.
It can take values like this:
mydestination = $myhostname, localhost.$mydomain, $mydomain, mail.$mydomain, www.$mydomain
mail_spool_directory
There are two modes of delivery that Postfix mail server can use:
- Directly to a user’s mailbox.
- To a central spool directory, this way, the mail will be in /var/spool/mail with a file for each user.
mail_spool_directory = /var/spool/mail
mynetworks
This option allows you to configure what servers can relay through your Postfix server.
This option should take local addresses like local mail scripts on your server only.
Otherwise, spammers can utilize your mail server to relay their messages and your mail server blacklisted and as a result, you will not be able to receive many emails.
This option has the following syntax:
mynetworks = 127.0.0.0/8, 192.168.1.0/24
smtpd_banner
This variable sets the message that is sent when the client after successful connection.
It is better to change the banner to something that doesn’t give an indication about the server you are using.
inet_protocols
This option specifies the IP protocol version used for server connections.
inet_protocols = ipv4
If you change the configuration files for Postfix mail server, you need to reload the service:
$ systemctl reload postfix
When you type any configuration, you may make a mistake, you can check for errors using the following command:
$ postfix check
This tool will help you find exactly the line and the error so you can fix it.
Checking the Mail Queue
Sometimes the mail queues on your system are filled up. This can be caused by many reasons like network failure or any reason that can delay mail delivery.
To check the mail queue on your Linux mail server, use the following command:
$ mailq
This command shows the Postfix mail queue.
If your queue is filled up and the message takes several hours to be sent, then you should flush the mail queue.
$ postfix flush
Now, if you check your mail queue you should find it empty.
Test Linux Mail Server
After configuring Postfix mail server correctly, you should test your mail server.
The first step is to use a local mail user agent like mailx or mail which is a symlink to mailx.
Try to send a mail to someone else on the same server, if this works, then send to a remote site.
$ echo "This is message body" | mailx -s "This is Subject" -r "likegeeks<[email protected]>" -a /path/to/attachment [email protected]
Then try to receive a mail from a remote site.
If you have any problems, check the logs. The log file on Red Hat based distros in /var/log/maillog file and on Debian based distros in /var/log/mail.log file or as defined in the rsyslogd configuration.
I recommend you to review the Linux Syslog Server for a detailed explanation about logs and how to configure the rsyslogd.
If you still have problems, try checking your DNS settings and check your MX records using Linux network commands.
Secure Mail Boxes From Spam Using SpamAssassin
One of the ways to fight spam is to scan the mailboxes by some tool, searching for certain patterns associated with spam.
One of the best solutions is SpamAssassin, which is open-source.
You can install it like this:
$ dnf -y install spamassassin
Then start the service and enable it at startup:
$ systemctl start spamassassin
$ systemctl enable spamassassin
Once you’ve installed it, you can check the configuration in /etc/mail/spamassassin/local.cf file.
SpamAssassin determines if an email is spam or not based on the result of the different scripts scores.
If the message has a higher score, that means a higher possibility of the mail being spam.
In the configuration file, the parameter required_hits 5 indicates that SpamAssassin will mark an email as spam if its score is five or higher.
The report_safe option takes the values 0, 1, or 2. If set to 0 means email marked as spam is sent as it is, only modifying the headers to show that it is spam.
If it takes the value 1 or 2, a new report message is generated by SpamAssassin and sent to the recipient.
If the value is 1, that means the spam message is coded as content message/rfc822, while if the value is 2, that means the message is coded as text/plain content.
The text/plain is safer since some mail clients execute message/rfc822 and could infect the client computer.
Now we need to integrate it into postfix. The simplest way to do this is probably by using procmail.
We’ll have to create a file, named /etc/procmailrc, and add the following content:
:0 hbfw
| /usr/bin/spamc
Then we edit Postfix configuration file /etc/postfix/main.cf and change mailbox_command like this:
mailbox_command = /usr/bin/procmail
Finally, restart Postfix and SpamAssassin services:
$ systemctl restart postfix
$ systemctl restart spamassassin
However, SpamAssassin sometimes does not recognize spam messages, that led to mailboxes filled with spam messages.
Fortunately, you can filter messages before they enter the Postfix server using Realtime Blackhole Lists (RBLs). That will decrease the load on your mail server and keep your mail server clean.
Open the configuration file of postfix server /etc/postfix/main.cf and change smtpd_recipient_restrictions option and add the following options like this:
strict_rfc821_envelopes = yes
relay_domains_reject_code = 554
unknown_address_reject_code = 554
unknown_client_reject_code = 554
unknown_hostname_reject_code = 554
unknown_local_recipient_reject_code = 554
unknown_relay_recipient_reject_code = 554
unverified_recipient_reject_code = 554
smtpd_recipient_restrictions =
reject_invalid_hostname,
reject_unknown_recipient_domain,
reject_unauth_pipelining,
permit_mynetworks,
permit_sasl_authenticated,
reject_unauth_destination,
reject_rbl_client dsn.rfc-ignorant.org,
reject_rbl_client dul.dnsbl.sorbs.net,
reject_rbl_client list.dsbl.org,
reject_rbl_client sbl-xbl.spamhaus.org,
reject_rbl_client bl.spamcop.net,
reject_rbl_client dnsbl.sorbs.net,
permit
Then restart your postfix server:
$ systemctl restart postfix
The above RBLs are the common ones, you can find more lists on the web and try them.
Securing SMTP Connection
It is better to transfer your SMTP traffic over TLS to protect it from being modified in the middle.
First, we need to generate the certificate and the key using openssl command:
$ openssl genrsa -des3 -out mail.key
$ openssl req -new -key mail.key -out mail.csr
$ cp mail.key mail.key.original
$ openssl rsa -in mail.key.original -out mail_secure.key
$ openssl x509 -req -days 365 -in mail_secure.csr -signkey mail_secure.key -out mail_secure.crt
$ cp mail_secure.crt /etc/postfix/
$ cp mail_secure.key /etc/postfix/
Then add the following option to Postfix configuration file /etc/postfix/main.cf:
smtpd_use_tls = yes
smtpd_tls_cert_file = /etc/postfix/mail_secure.crt
smtpd_tls_key_file = /etc/postfix/mail_secure.key
smtp_tls_security_level = may
Finally, restart your postfix service:
$ systemctl restart postfix
Now, you have to choose the TLS on your client when connecting to the server.
You will receive a warning when you send a mail the first time after changing the setting because of the certificate is not signed.
Using Let’s Encrypt Certificates
Let’s Encrypt is a free SSL certificate provider that enables you to encrypt your traffic.
Instead of using self-signed certificates which annoy your users about trusting them, you can use this good solution.
First, install letsencrypt:
$ yum install letsencrypt
Or if you are using Debian based distro, you can use the following command:
$ apt-get install letsencrypt
Then run letsencrypt like this:
$ letsencrypt certonly --standalone -d yourdomain.com
You should replace yourdomain.com with your actual domain.
After answering the prompted questions about the contact email, the email server domain, and the license, everything should be OK now.
The certificates will be stored in /etc/letsencrypt/live/yourdomain.com/
One last thing you have to do which is making postfix use those certificates, you can use the following commands:
sudo postconf -e 'smtpd_tls_cert_file = /etc/letsencrypt/live/yourdomain.com/fullchain.pem'
sudo postconf -e 'smtpd_tls_key_file = /etc/letsencrypt/live/yourdomain.com/privkey.pem'
Don’t forget to replace yourdomain.com with your actual domain.
Finally, restart your postfix server
$ systemctl restart postfix
POP3 and IMAP Protocol Basics
So far we’ve seen how SMTP mail server sends and receives emails without problems, but consider the following situations:
- Users need local copies of e-mail for offline viewing.
- mbox file format is not supported. The mbox format is used by many mail user agents like mailx and mutt.
- Users cannot stay connected to a fast network to grab a local copy to read offline.
- Some mail servers don’t give access to the shared mail spool directories for security reasons.
To handle these cases, another class of protocols was introduced. This type of protocols may be described as mail access protocols.
The most common two popular mail access protocols are Post Office Protocol (POP) and Internet Message Access Protocol (IMAP).
The idea behind POP is very simple: A central Linux mail server remains online all the time and receives and store emails for all users. All received emails are queued on the server until a user grabs them.
When a user wants to send an email, the email client relays it through the central Linux mail server via SMTP normally.
Note that the SMTP server and POP server can be on the same system without any problem. Most servers do this today.
Features like keeping a master copy of a user’s email on the server were missing, that led to the development of IMAP.
By using IMAP, your Linux mail server will support three modes of access:
- The online mode is similar to having direct file system access to the Linux mail server.
- The offline mode is similar to how POP works, where the client is disconnected from the network except when grabbing his email. In this mode, the server normally does not retain a copy of the email.
- The disconnected mode works by allowing users to keep cached copies of their emails and the server retains a copy of the email.
There are several implementations for IMAP and POP, the most popular one is Dovecot server which provides both protocols.
The POP3, POP3S, IMAP, and IMAPS listen on ports 110, 995, 143, and 993 respectively.
Installing Dovecot
Most Linux distros come with dovecot preinstalled, however, you can install dovecot in Red Hat based distros like this:
$ dnf -y install dovecot
On Debian based distros, the IMAP and POP3 functionality are provided in two separate packages, you can install them like this:
$ apt-get -y install dovecot-imapd dovecot-pop3d
You will be prompted to create self-signed certificates for using IMAP and POP3 over SSL/TLS. Select yes and enter the hostname for your system when prompted.
Then you can run the service and enable it at startup like this:
$ systemctl start dovecot
$ systemctl enable dovecot
The main configuration file for Dovecot is /etc/dovecot/dovecot.conf file.
Some Linux distros put the configuration under /etc/dovecot/conf.d/ directory and use the include directive to include the settings in the files.
The following list is the some of the parameters used to configure dovecot:
protocols: the protocols you want to support.
protocols = imap pop3 lmtp
lmtp means local mail transfer protocol.
listen: IP addresses to listen on.
listen = *, ::
The asterisk means all ipv4 interfaces and :: means all ipv6 interfaces
userdb: user database for authenticating users.
userdb {
driver = pam
}
passdb: password database for authenticating users.
passdb {
driver = passwd
}
mail_location: this entry in /etc/dovecot/conf.d/10-mail.conf file, and it is written like this:
mail_location = mbox:~/mail:INBOX=/var/mail/%u
Secure Dovecot
Dovecot comes with generic SSL certificates and key files that are used in the /etc/dovecot/conf.d/10-ssl.conf
ssl_cert = </etc/pki/dovecot/certs/dovecot.pem
ssl_key = </etc/pki/dovecot/private/dovecot.pem
When a user tries to connect to dovecot server, it will show a warning because the certificates are not signed, you can purchase a certificate from a certificate authority if you want.
Or if you go with Let’s Encrypt certificates, you can point to them instead:
ssl_cert = </etc/letsencrypt/live/yourdomain.com/fullchain.pem
ssl_key = </etc/letsencrypt/live/yourdomain.com/privkey.pem
Don’t forget to open dovecot server ports in your iptables firewall by adding iptables rules for ports 110, 995, 143, 993, 25.
Then save the rules.
Or if you are using firewalld you can do the following:
$ firewall-cmd --permanent --add-port=110/tcp --add-port=995
$ firewall-cmd --permanent --add-port=143/tcp --add-port=993
$ firewall-cmd --reload
And again, for troubleshooting, you check the log files /var/log/messages, /var/log/maillog, and /var/log/mail.log files.
Linux mail server is one of the easiest servers to work with, especially Postfix mail server.
I hope you find the post useful and interesting. Keep coming back.
Thank you.
ReactOS 0.4.7 duyuruldu
Rus kökenli, Microsoft Windows NT platformunun tasarımını klonlayarak yapılandırılan, ancak açık kaynak kodlu bir sistem olan ReactOS‘un 0.4.7 sürümü duyuruldu. Kabuk iyileştirmeleriyle birlikte gelen yeni sürüm; çeşitli sürücü geliştirmeleri, geri dönüşüm kutusuna silme desteği, Wine Staging’e karşı DLL güncellemeleri ve tema iyileştirmeleri içeriyor. Ayrıca pek çok düzeltme içeren sürüm, pek çok donanım uyumluluğuna da sahip. ReactOS 0.4.7 hakkında bilgi edinmek için ilgili sürüm duyurusu ve değişiklikler sayfası incelenebilir.
ReactOS 0.4.7 edinmek için aşağıdaki linklerden yararlanabilirsiniz.
ROSA R10 duyuruldu
Linux tabanlı çözümler geliştiren bir Rus şirketi olan ROSA tarafından geliştirilen ve Mandriva Linux’tan çatallanmış bir dağıtım olan ROSA’nın KDE 4 veya Plasma 5 Masaüstü masaüstü ortamlarıyla kullanıma sunulan Fresh R10 sürümü, Vladimir Potapov tarafından duyuruldu. Sistem kitaplıklarının ve yazılım paketlerinin en son sürümlerine güncellendiği belirtilen sistem, varsayılan olarak 4.9.60 LTS Linux çekirdeği üzerine yapılandırılmış bulunuyor. 4.13 gibi diğer çekirdekler ise özel depolardan edinilebiliyor. ROSA 2016.1’e dayanan ikinci sürüm olduğu belirtilen yeni sürümün, özellikle yeni yazılım sürümlerini denemek isteyen GNU/Linux kullanıcılarını hedef aldığı ifade ediliyor. OpenGL 4.5 ile 17.1.6 sürümüne güncellenen MESA dışında, NVIDIA sürücüleri de 384.90 ve deneysel 387.12 ile yeni sürümlerine güncellenmiş bulunuyorlar. ROSA R10 hakkında ayrıntılı bilgi edinmek için sürüm duyurusunu ya da sürüm notlarını inceleyebilirsiniz.
ROSA R10 edinmek için aşağıdaki linklerden yararlanabilirsiniz.
- İndirme sayfası
- ROSA.FRESH.KDE.R10.x86_64.iso (2,004MB, MD5, torrent)
- ROSA.FRESH.KDE.R10.x86_64.uefi.iso (2,022MB, MD5, torrent)
- ROSA.FRESH.PLASMA.R10.x86_64.iso (2,030MB, MD5, torrent)
- ROSA.FRESH.PLASMA.R10.x86_64.uefi.iso (2,043MB, MD5, torrent)
