Tuesday, November 3, 2015

How to configure Ubuntu 12.04 with Gmail SMTP

For this we need Ubuntu 12.04 LTS installed in your physical or virtual system. 

Lets get started with this,

We need to install required packages for the same,

sudo apt-get install mailutils postfix libsasl2-2 ca-certificates libsasl2-modules

When you install postfix for the first time, system will ask you for the smtp domain name and smtp type. Select "Internet Site" and "smtp.yourdomain.com" where ever applicable. (Where 'yourdomain.com' is your working domain name)

Now lets start configuring SMTP in postfix.

sudo vim /etc/postfix/main.cf

(Edit configuration file, so that it looks like this..)

relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes

(Save & Exit)

Now your google user name and password goes in this file:

vim /etc/postfix/sasl_passwd

(Edit as below)

[smtp.gmail.com]:587    <GMAILUSERNAME>:<GMAILPASSWD>

(Save & Exit)

Lets make sure postfix can read this file and not everyone else:

sudo chmod 400 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd

Lets use the certificate for the authentication:

cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem

and finally lets restart the postfix service:

/etc/init.d/postfix reload

Now let's test our configuration if its working or not:

echo "Test email from Postfix" | mail -s "Test Postfix" USERNAME@gmail.com

Verify is the mail is sent:

tail -f /var/log/mail.log

If required we can also add your gmail account in aliases:

vim /etc/aliases

root: GMAILADDRESS@gmail.com

(save & exit)

newaliases

Thanks for the visit
:)









Monday, August 10, 2015

Working with apt-get and dpkg package manager tools of 'Debian'



First of all we are going to work with Apt-get package manager. For those who are already familiar with Yum of Red Hat based distros may find this quite identical tool. Apt-get pulls and installs packages from the online repository to ease your pain to find, download and install packages and its dependency manually.

You have to be root using for the following hands-on, Let's get started:

root@yogeshkk21:~# apt-get update

This command pulls package information from repository server and caches the same locally

root@yogeshkk21:~# apt-cache search nginx

We can search for a specific package in the entire cache using this command


root@yogeshkk21:~# apt-get install nginx

This command is to install a package

root@yogeshkk21:~# which nginx

To verify nginx is installed

root@yogeshkk21:~# apt-cache search apache2

Let's search for Apache2 package as well

root@yogeshkk21:~# apt-get install apache2

And Install it same as nginx

root@yogeshkk21:~# apt-get remove ngnix

Now, let's learn How to remove it

root@yogeshkk21:~# apt-get remove --purge nginx

apt-get remove only removes the binary, but keeps associated library and configuration files. So to remove everything, use purge.

root@yogeshkk21:~# apt-get autoremove

This command removes unnecessary packages alongside the removed package

root@yogeshkk21:~# which ngnix

Let's verify

root@yogeshkk21:~# apt-get remove apache2 ; apt-get autoremove apache2

This removed apache2 package along with unnecessary packages of it

root@yogeshkk21:~# which apache2

Let's verify again

root@yogeshkk21:~# apt-get install apache2

Let us install apache2 package again

root@yogeshkk21:~# apt-get upgrade

This command allows you to upgrade any packages required for apache2

root@yogeshkk21:~# apt-get dist-upgrade

This command allows you to upgrade distribution kernel if available

Now if we talk about dpkg package manager, it's the little bit different from the apt-get. This does not pull the dependencies automatically like apt-get does. Let's see:

root@yogeshkk21:~# wget https://www.dropbox.com/download?dl=packages/ubuntu/dropbox_2015.02.12_amd64.deb

Let's try to install Dropbox application on our Ubuntu 12.04 distro.

root@yogeshkk21:~# mv download\?dl\=packages%2Fubuntu%2Fdropbox_2015.02.12_amd64.deb dropbox.deb

Let's rename this downloaded file to something more simple.

root@yogeshkk21:~# dpkg -i dropbox.deb

To install the Deb file, use -i option. Now you will see that lots of dependency errors are been thrown at you. Its simply because, dpkg can't pull all those dependency for you. So, what now? Should I download and install them manually? No, there is a way out.

root@yogeshkk21:~# apt-get update

Let's update our cache once again

root@yogeshkk21:~# apt-get -f upgrade

And this command will do the job for us. It automatically pulls all the required library packages along with other dependencies. Nice, right?

root@yogeshkk21:~# dpkg -i dropbox.deb

Now, let's try that deb file again for installation. And you will notice, it gets installed! :)

root@yogeshkk21:~# which dropbox

Let's verify! Worked well.

root@yogeshkk21:~# dpkg --get-selections

Now let's also find out, how can we list all installed packages. This command will do the magic for us.

root@yogeshkk21:~# dpkg --get-selections  |grep -i dropbox

We can find specific package name from the output using grep.

root@yogeshkk21:~# dpkg --remove dropbox

Just like apt-get we have remove command as well in dpkg and it removes all binary for us.

root@yogeshkk21:~# dpkg --purge dropbox

To remove the application completely, using this command.

So that's how we can use apt-get and dpkg.

HTH ^_^

Above command is tested and worked on:

root@yogeshkk21:~# lsb_release -a
No LSB modules are available.
Distributor ID:    Ubuntu
Description:    Ubuntu 12.04.5 LTS
Release:    12.04
Codename:    precise