August 7

Linux: Installing QEMU

2013 – The following command worked
Fedora:
su -c “yum install qemu”

Ubuntu:
sudo apt-get install qemu-system

 

To boot an ISO do something similar to:

qemu-system-x86_64 -cdrom filename.iso

If you prepared a USB pen drive and want to test it, run it like this (/dev/sdx being your device name; you may need to sudo to access it):

qemu-system-x86_64 -hda /dev/sdx
Category: Linux | Comments Off on Linux: Installing QEMU
August 3

Linux: Combine MP4/M4V Files

You may want to combine multiple mp4/m4v video files into one continuous video. In order to do this, you need to install the gpac library of programs onto Ubuntu. Open up Terminal and run:

sudo apt-get install gpac

This will install the gpac library. One of the programs included with it is MP4Box, which you can use to concatenate the video files. If you are using 64 bit Linux or get an error like MP4Box: error while loading shared libraries: libgpac.so: cannot open shared object file: No such file or directory, then you need to link the shared library to /usr/lib: (I did not run into this issue -nh)

sudo ln -s /usr/local/lib64/libgpac.so /usr/lib/libgpac.so

Now to convert your files, add -cat filename.mp4 for each of your files to this command, with -new combinedfile.mp4 as your output, combined file:

MP4Box -cat vid1.mp4 -cat vid2.mp4 -cat vid3.mp4 -new combinedfile.mp4

Once the process finishes, your combined video file will be in combinedfile.mp4.

By: A. Martin

Category: Linux | Comments Off on Linux: Combine MP4/M4V Files
July 11

Linux: Batch convert mp3 to wav

Install mpg123
sudo apt-get install mpg123

Make certain all of your mp3 audio files are in the same directory.

Put the following code into a file:
vi mp3towav.sh

###Start of script###
for i in *.mp3 ; do
echo $i
b=`basename $i .mp3`
mpg123 -w $b.wav input $i
done
###End of script###

Put the conversion script into the same directory as your mp3s
chmod +x mp3towav.sh

Simply run ./mp3towav.sh

 

* Note – If there are spaces in your file names you will get errors and the conversion process will fail.
The easiest way to fix this is to replace the spaces with another character like a dash

Here is a script to remove the spaces in a file and replace them with dashes:
vi spacetodashconvert.sh

###Start of script###
#!/bin/bash

ls | while read -r FILE
do
mv -v “$FILE” `echo $FILE | tr ‘ ‘ ‘-‘ `
done
###End of script###

Run this in the same directory that contains your mp3 files, then re-run the mp3towav script

Category: Linux | Comments Off on Linux: Batch convert mp3 to wav
July 10

Linux: SFTP Chroot on CentOS

This came up today where I needed to give secure file transfer to customers. To complicate things I had to use an out-of-the-box RHEL6 system. The obvious answer was to use SSH and limit those users to SFTP only. Locking them into a chroot was not a requirement, but it seemed like a good idea to me. I found plenty of docs that got 80% of the way, or took a shortcut, but this should be complete.

The basic steps are:

  1. Create a group and the users to that group
  2. Modify the SSH daemon configuration to limit a group to sftp only
  3. Setup file system permissions
  4. Configure SELinux
  5. Test (of course)

Without further ado, lets get started. It should only take about 10 minutes, nothing here is especially complex.

Create a group that is limited to SFTP only and a user to be in that group.

1
2
3
groupadd sftponly
useradd sftptest
usermod -aG sftponly  sftptest

Now you need to make a little change to /etc/ssh/sshd_config. There will be a Subsystem line for sftp which you need to change to read:

1
Subsystem       sftp    internal-sftp

Now you need to create a block at the end to limit members of a group (ie the sftponly group you created above) and chroot them. Simply add the following to the end of the file:

1
2
3
4
5
Match Group sftponly
    ChrootDirectory %h
    ForceCommand internal-sftp
    X11Forwarding no
    AllowTcpForwarding no

These changes will require a reload of the SSH daemon: service sshd reload

Now you need to make some file permission changes. For some reason which I cannot work out for now, the home directory must be owned by root and have the permissions 755. So we will also need to make a folder in the home directory to upload to and make that owned by the user.

1
2
3
4
sudo -u sftptest mkdir -pv /home/sftptest/upload
chown root. /home/sftptest
chmod 755 /home/sftptest
chgrp -R sftponly /home/sftptest

The last thing we need to do is tell SELinux that we want to upload files via SFTP to a chroot as it is read-only by default. Of course you are running SELinux in enforcing mode aren’t you 🙂

1
setsebool -P ssh_chroot_rw_homedirs on

Now from another console you can sftp to your server

1
sftp sftptest@<server>

You should then be able to put a file in your upload folder. However if you try to ssh to the server as the user sftptest it should tell you to go away. Of course you should be able to ssh as your normal user with no problem. Pro tip: make sure to leave a root terminal open just in case.

By: C Cowley

Category: Linux | Comments Off on Linux: SFTP Chroot on CentOS