Tag: linux

Mounting a Linux Software RAID 1 partition

Server died, have to recover data from a Linux Software RAID 1 drive.
Take the drive and connect it to another linux computer.  You won’t be able to mount it out of the box; if you try you’ll get an error that states mount: unknown filesystem type ‘linux_raid_member’.
install mdadm:
apt-get install mdadm

mdadm –examine /dev/sdd1

fdisk -l /dev/sdd
create a virtual md device with mdadm
sudo mdadm -A -R /dev/md9 /dev/sdd1
now you can mount the RAID 1 device
sudo mount /dev/md9 /mnt/old_hdd/
If you run into a device is busy error, stop mdadm
mdadm –stop /dev/md126
mdadm –stop /dev/md127
then try again

Diable password ssh logins

If you want to disable root from being able to login via ssh edit /etc/ssh/sshd_config and find PermitRootLogin.  Change the value to no.

# Authentication:
LoginGraceTime 120
PermitRootLogin no
StrictModes yes

If you wish to disable all password logins which requires uses to use public keys instead in /etc/ssh/sshd_config and find PasswordAuthentication.  Change the value to no.

PasswordAuthentication yes

If you wish to diable password logins for only some users add the following to your /etc/ssh/sshd_config file

Match User user1, user2, user3    PasswordAuthentication no

Encrypting a directory with Ubuntu

I found a nice post on the ubuntu forums on how to encrypt a directory in Ubuntu. This is a copy and paste of that post by remmelt, I cannot take credit for it.
This guide describes how to create encrypted directories. These can come in handy for laptop users, password lists and the like.

1. Install the software
Code:

sudo apt-get install encfs fuse-utils
sudo modprobe fuse

And since we don’t want to modprobe each time we reboot, add “fuse” to /etc/modules (without quotes, on a line of its own)

2. Add yourself to the fuse group
The installer creates a fuse group and to use fusermount you need to be in this group. You can do this with your favourite GUI admin tool or command line:
Code:

sudo adduser fuse

3. Create a directory where your encrypted stuff will be stored
I put mine in my home dir, but you can put it anywhere you like.
Code:

mkdir ~/encrypted

4. Create a mountpoint
This is the directory where you will mount the encrypted directory. Through this path you can access the encrypted files.
Code:

mkdir ~/temp_encr

5. Create the encrypted system and mount it
The first time you try to mount the directory, encfs will create the encrypted filesystem. It works like the regular mount:
Code:

encfs

So for this example:
Code:

encfs /home//encrypted /home//temp_encr

Note that encfs wants absolute paths, i.e. starting with a /

6. Do the work
Put some files in your ~/temp_encr folder and look in the ~/encrypted one: they will show up there, encrypted.

7. Unmount the encrypted filesystem
Unmounting is as easy as
Code:

fusermount -u /home//temp_encr

8. Goto step 5
Repeat! EncFS will only create the filesystem once, after that first time it will ask for a password and mount your directory.

Remember to keep the two directories apart: in this example the “encrypted” folder holds your encrypted data and should not be used directly. The gateway to access this data is “temp_encr” or whatever you want to call it.

This was tested and verified on Ubuntu 10.04

scp a path with spaces

I find the easiset way to scp a path with spaces is like so:
scp username@host:”‘/this/is my path/with spaces/and this is my file.txt'” ./

Note the double quotes followed by a single qoute ( ” ‘ text ‘ “), and closed in reverse order. Your shell will ignore the double qoute and the remote shell will receive the single qoutes.

You can also escape it, but that’s kind of a pain. example:
scp username@host:/this/is\\ my\\ path/with\\ spaces/and\\ this\\ is\\ my\\ file.txt ./

My preferences is obvious.

Enable a Swap File in Linux

You can use a Swap File instead of a Swap Partition with the linux kernel 2.6. Yeah, old news, but I’ve still always used a partition out of habit. Time to change that habit!

1. Log in as root, or use sudo
2. Type following command to create 512MB swap file
sudo dd if=/dev/zero of=/swap.img bs=1024k count=512
could also do it this way (1024 * 512MB = 524288 block size)
sudo dd if=/dev/zero of=/swap.img bs=1024 count=524288
3. Format it as swap.
sudo mkswap /swap.img
4. Activate your swap file immediately
sudo swapon /swap.img
5. Optional, but I recommend activating the swap file on boot. Edit your /etc/fstab file and add the following:
/swap.img none swap sw 0 0
6. To verify that the swap is working type:
free -m

Links this information was taken from:
http://blog.mypapit.net/2007/07/how-to-add-linux-swap-file-if-you-dont-have-swap-partition.html
http://www.cyberciti.biz/faq/linux-add-a-swap-file-howto/

Convert FLAC to ALAC

If you have a ipod you know it can’t play FLAC files. If you still want lossless quality music you’ll have to convert it to ALAC. This can be done very easily with ffmpeg. Here is how to do it:


ffmpeg -i input_flac_file -acodec alac outputfile.m4a

Here is a script to convert all flac files in a directory to alac.


#!/bin/bash
#get all flac files in a directory
#loop over all files
#get file name without extention
#run it through ffmpeg with the output file as the filename.m4a

for file in *flac
do
basename=`basename "$file" .flac`
ffmpeg -i "$file" -acodec alac "$basename".m4a;
done