Thursday, April 30, 2015

Merging multiple files using the cat command

Nothing major today, this is a straightforward case that I was surprised would work with the Linux cat command.

I had a folder with several mp3's that were part of one long mixtape but were split into dozens of files, when they should have really been one big file.

I could have used a tool to fix this, but it can be accomplished natively using a Linux or Mac terminal.

First navigate to the folder where the files are located. If they are in numerical order, that's short and easy.

 cat *.mp3 > ../mylongsong.mp3

This combines all the files into one and dumps in one directory above to avoid an endless loop, depending on the shell you're using.

If the files have arbitrary names, but you can figure out the order, you can use a slightly longer command:

cat 1.mp3 2.mp3 a.mp3 myfav.mp3 wow.mp3 > ../mylongsong2.mp3

The caveat is that all the files need to be encoded the same way and be of the same filetype. It will not merge mp3 with wma, it will not merge a 320kbps mp3 with a 128kbps version.

Thursday, February 19, 2015

Installing MySQL 5.6 on CentOS 6

MySQL on CentOS6 is currently limited to version 5.1, which sucks. A lot of modern web applications can benefit of running the most recent version of MySQL (up to 5.6 at the writing of this post), and as a result we will be installing MySQL 5.6 on CentOS 6.x, patched to the latest sub-version.

There are several ways of accomplishing this, but I think it's a good idea to take the software directly from the source.

It's also a pretty good idea to have a backup mechanism, and sadly the free version does not play well with hot backups, which are performed while the database is running in full read/write made.

Percona has a wonderful set of tools, and offer a free hot backup solution for MySQL that works awesomely. I'll provide the instructions to install the tool, you can feel free to peruse their docs to implement your own backup strategy :)

More on Percona Xtrabackup here:

More on MySQL Community Server here:

0. Got root/sudo

1. Get and Install the RPM from MySQL/Oracle
cd /tmp
rpm -Uvh mysql-community-release-el6-5.noarch.rpm

2. Install MySQL and start / enable service
yum install mysql-community-server 
service mysqld start && chkconfig mysqld on

3. Secure MySQL server

4.  Install Percona with repos
rpm -Uvh
 Verify successful install and check version
xtrabackup --version



Thursday, January 8, 2015

Pluggable Authentication Modules (PAM) - some basic tricks on CentOS 6

I've been playing around with PAM on a couple distros recently, and I thought I'd share some quick tips and tricks in setting up a secure CentOS 6 Linux multi-user environment. Whilst these are not bulletproof password policies, they are a step beyond the default distribution configuration and are not too complex that the users would be bugging you, the friendly neighbourhood sysadmin.

As usual, any feedback is appreciated, so drop me a line: Once it gets past the spam filters, I'll try my best to respond asap.

1. Use PAM to disable the use of null passwords in user Accounts.

vi /etc/pam.d/system-auth

Find line 
password sufficient md5 shadow nullok try_first_pass use_authtok

Remove/delete nullok option, so the line now reads:
password sufficient md5 shadow try_first_pass use_authtok

save and close file

2. Use PAM to prevent re-using/recycling passwords .

This example prevents the use of the last 3 passwords.

vi /etc/pam.d/system-auth
find line
password sufficient md5 shadow nullok try_first_pass use_authtok

Add to end of line
password sufficient md5 shadow nullok try_first_pass use_authtok remember=3

save and close file

3. Set password minimum length

This example sets the minimum password length to 8 characters.

vi /etc/pam.d/system-auth

find line
password sufficient md5 shadow nullok try_first_pass use_authtok

Add new line BEFORE
passwd password requisite minlen=8
save and close file

4. Configure server to deny access with multiple incorrect login attempts

This example temporarily denies access after 5 attempts. The temporary lockout time can also be configured for a certain time, which will be set to 1 hour (3600 seconds) in this example.

vi /etc/pam.d/system-auth

Add the following line to end of file
auth required onerr=fail deny=5 unlock_time=3600

save and close file