Testing SMTP from the CLI

By | All Linux HowTo's, Scripting HowTo's | No Comments

This article will show two ways to test your SMTP server from the command line in Linux, these tests are very useful when setting up a new server and you just want to make sure you have it working before you continue on. Lets get started

In this first example we are going to test the server with no auth on port 25:

nc mail.agix.com.au 25

The above example is using netcat which is very useful in cases like this, now that we are connected to our server on port 25 using netcat we can start our test, in our below example we need to say EHLO to the domain that the server is serving mail for in our example agix.com.au

EHLO agix.com.au

Now we need to tell it what sender address we are expecting to use, in this case it is brad@agix.com.au

mail from:brad@agix.com.au

Now we need to tell it where the mail needs to be delivered, this could be a local user or perhaps an external email.

rcpt to:null@agix.com.au

And lastly we need to give it some data to put in the email, you can use special flags such as the ones below setting a To, From and Subject, these will show up in the users email client. For our example we are going to make the mail be from support@agix.com.au

data

To: null
From: support
Subject: SMTP connection test

This is the body of the email.
.

To finish this command type . and then hit enter once you have done so you will be told what the queue number is for your message and then you can just type quit to exit netcat.

quit

Simple, if your server is working correctly then you should receive the email in your inbox and all is good, but what if your server requires authentication. Well that is where openssl client comes in, just follow the setups below:

First we need to create a base64 string containing our username and password. Be sure to leave the \0 characters in their place otherwise the command will not be formatted correctly. Just replace the username and password with yours.

AUTH_STRING="$(echo -en '\0brad\0lamepassword' | base64)"

Now we can go ahead and try to connect using the openssl client on the submission port 587 assuming that is what is in use.

openssl s_client -quiet -starttls smtp -crlf -connect mail.agix.com.au:587

Same deal as the last example we need to be polite and say EHLO,

EHLO agix.com.au

The server in this example is not going to like talking to us without auth, in fact it won’t so lets go ahead and give it our auth string.

AUTH PLAIN $AUTH_STRING

Now we can do the same as last time, tell the server who from, who to and some data just like before.

mail from:brad@agix.com.au
rcpt to:null@agix.com.au
data
To: null
From: support
Subject: SMTP over STARTTLS with AUTH test

Test
.

read more

Resetting a forgotten Owncloud password

By | All Linux HowTo's | No Comments

To reset a forgotten owncloud password (Including the admin account) you can do the following.

As root on your server enter the following command replacing $USER with the username of the account

sudo -u www-data php /var/www/html/owncloud/occ user:resetpassword $USER

You will be prompted to enter a new password and then type it again to confirm, once done you should see

Successfully reset password for $USER

Quick Bash Tip – Creating Test Files

By | All Linux HowTo's, Scripting HowTo's | No Comments

Need some test files sure you could use the below method:

touch file{"1","2","3"}

But why do that when you could just let bash do the work for you and use the following:

touch file{1..100}

I don’t want blank files to test with, they need to have some data in them.. Easy, just make sure you are in the directory with your test files and run the below command.

for i in *; do echo "This is data" >> $i; done

Freeing Space on Gentoo

By | All Linux HowTo's, Security HowTo's | No Comments

Gentoo machines (and Linux boxes in general) have a very nice habit of living for a long time and needing constant maintenance, while this is great it also means that they can go for long periods of time without a clean up and can start chewing up space on your disks. Luckily there are some simple steps to follow to get your server clean and give you your disk space back.

If you are using Gentoo then continue on reading if you are using RHEL or Ubuntu it would be best to go and read the article written by Andrew here as the process differs somewhat.

First thing to do is get rid of all the old things in your distfiles and packages directories. If you have the gentoolkit install (You should it is a great set of tools) then you can run the following commands.

#This removes old outdated packages and sources and will not touch the ones that are in use
/usr/bin/eclean distfiles ; /usr/bin/eclean packages

Depending on how regularly you run eclean you can often free up a few GB straight away, for example on our test system we opened up 3GB just by running the above commands.

Another directory that can grow quite large is /var/tmp/portage, if you are building a large package or multiple packages and they fail for some reason they will not be deleted automatically, they will sit in the /var/tmp directory.

rm -rf /var/tmp/portage

For our test system that was another 2MB cleaned.

User cache files are another thing that can take up space on a system, for example if a user views a folder full of images a .thumbnails folder would be created to store all of the thumbnails for the images.

Please be careful with the below command, just because it works on our test system does not mean that it will on yours, check your data first. Run the below command, if that only returns files you want to delete the uncomment the other command below.

find /home -name ".thumbnails" -exec echo "Found File:" {} \;
#Only uncomment if you are happy with the output of the first command
#find /home -name ".thumbnails" -exec rm -rf {} \;

Depending on how many users you have the gain from this can be pretty significant, on our test system it only cleared about 300k but on one of our production systems the above command cleaned out about 1GB of just thumbnails.

Another program that is good to run on a long living Gentoo box is eclean-kernel, chances are that you have been through a few kernel upgrades in the time you have had your box running and have not removed the old kernels from the system. To install eclean-kernel just follow the steps below

printf "#eclean-kernel requirements\n=dev-python/pymountboot-0.2.2 ~amd64\n=app-admin/eclean-kernel-0.4.1 ~amd64\n" >> /etc/portage/package.keywords
emerge --ask -jv app-admin/eclean-kernel
#Now just run
/usr/bin/eclean-kernel --ask

read more

Add a New or Existing user to Multiple Groups using Ansible

By | Uncategorized | No Comments

There are several popular search results for this answer but they all skip the important part – and are incorrect as a result.

---
- hosts: all

  sudo: yes

  tasks:

  - user: name=myuser comment="My User" groups=wheel,group1,group2 append=yes

This is where they are (and likely you are) going wrong. The “groups” option and the “append=yes” option. “groups” has an “s” in it. If you’re having trouble adding a new or existing user to multiple groups then this is likely the solution.

read more

Things to do when low on Disk Space

By | All Linux HowTo's | 2 Comments

Whenever i get an alert from a system-monitoring tool like Munin or Nagios, it’s almost always a disk usage issue. Unfortunately the issue is usually cause by developers who don’t clean-up after deployments or accumulate temp files without a means to remove them when no longer needed. But there is still plenty we can do.

1. Remove yum cache files. I suppose “apt” has something similar but i’m a Redhat man. You can do a yum cleanup as simply as the following. I’ve never seen this go wrong and i consider it very low risk:

read more

Roll your own Dropbox, Installing Owncloud

By | All Linux HowTo's | No Comments

I love the idea of my files being at my finger tips when I need them no matter where I am… I hate the idea of other people having my files at their finger tips when ever they want them. Good thing there is Owncloud, Owncloud is written in php and if you want you can dig down and check out the core functions as well as make new functionality of your own, this also allows you to see exactly what is happening with your data and see how secure or insecure it is.

This article is going to show you how to do a basic install of Owncloud on Gentoo, this is a simple installation and there are so many security and performance tweaks that can be made that I am going to cover them in another article later. Lets get started..

The first thing that we have to do is get a working Apache and PHP installation.

Install Apache:

emerge --ask -jv www-servers/apache ; rc-update add apache2 default

If Apache is running then make sure you stop it

/etc/init.d/apache2 stop

Add Apache to the global USE flags in /etc/portage/make.conf

vi /etc/portage/make.conf
#Edit the USE= line to match below, keeping in your other use flags that are already set such as -doc
USE="-doc apache2"

Change the default for the /etc/conf.d/apache2 config file as below

vi /etc/conf.d/apache2
#Replace: 
APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE"
#With: 
APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE -D PHP5"

Now we can install PHP because it will pick up the global Apache USE flag in the make.conf

emerge --ask -jv dev-lang/php

read more

Create a .img file linux

By | All Linux HowTo's | No Comments

Simple article to help you create a .img file that you can use to do some testing of different technologies or add to a virtual machine your hosting for more storage space or anything else you might need a .img file for.

dd if=/dev/zero of=/home/brad/Desktop/test.img bs=1M

Now you can use the file like a normal block device, for example.

mkfs.ext4 /home/brad/Desktop/test.img

Contact AGIX Support

Level 2, 170 Greenhill Road
Parkside 5063 South Australia
Phone: (08) 7324 4429
or 0422 927 598
support@agix.com.au