Install Firefox 3.6 in Debian Lenny
Two reasons for this:
1. It's the newest version of Firefox.
2. "Firefox" sounds cooler than "Iceweasel"
Downside:
This won't be upgraded with "apt-get upgrade"
This is being run on a very sparse system. Here are the packages you should probably get, if you don't already have them:
apt-get update && apt-get install xorg iceweasel bzip2 libdbus-glib-1-2
Download the most recent version of Firefox.
Hacked – SSH Bruteforce
This isn't much of a surprise, as the box had an incredibly simple root password. Here's some info:
This was a brute force ssh attack. ssh root login was not disabled. Here are some of early attempts before success:
cat /var/log/auth.log.1 | grep "Invalid user" | cut -d ':' -f 4 | sort | uniq | tail -n 25
Invalid user wilson from 64.124.102.44 Invalid user windows from 64.124.102.44 Invalid user worthy from 122.201.70.12 Invalid user www123 from 64.124.102.44 Invalid user www from 64.124.102.44 Invalid user www from 66.235.201.39 Invalid user www from 75.126.69.5 Invalid user wwwrun from 64.124.102.44 Invalid user xam from 64.124.102.44 Invalid user xbitchx from 64.124.102.44 Invalid user xchat from 64.124.102.44 Invalid user xfs123 from 64.124.102.44 Invalid user xfs from 64.124.102.44 Invalid user ydnah from 64.124.102.44 Invalid user yoshida123 from 64.124.102.44 Invalid user yoshida321 from 64.124.102.44 Invalid user yoshida from 64.124.102.44 Invalid user yssor from 64.124.102.44 Invalid user z1x2c3 from 64.124.102.44 Invalid user zabbix from 75.126.69.5 Invalid user zachary from 64.124.102.44 Invalid user zoe from 64.124.102.44 Invalid user zuperman from 64.124.102.44 Invalid user zxcvb from 64.124.102.44 Invalid user zxcvbn from 64.124.102.44
The full list is at the bottom of the post.
How to Install MPD in Debian Lenny
mpd is my favorite music player. Here's how to install it in Debian Lenny.
You'll need to be root for this (type "su" without the quotes), or add "sudo" before each command.
Install mpd (Music Player Daemon) and mpc (Music Player Command).
apt-get install mpd mpc
Configure mpd. You can use nano (or any text editor) in place of vim if you prefer. I didn't change anything except I commented-out (with the hash symbol) the bind_to_address, as it was causing the following error when I tried to use mpc:
MPD_HOST and/or MPD_PORT environment variables are not set error: problems getting a response from "localhost" on port 6600 : Connection refused
The bind_to_address line should look like this:
#bind_to_address "127.0.0.1"
Put a symbolic link to your music in mpd's default music directory. Obviously you'll need to replace /home/james/music with the path to your music directory.
ln -s /home/james/music /var/lib/mpd/music
Make sure mpd has permission to read your music files. In my case, because all of my music is on an external NTFS drive, all of the file permissions on my music were a little odd. They belonged to the user "james" (me) and the group "users", and did not allow anyone who was not the owner or not in the group to read them. To fix this I added the user "mpd" (which was created when we installed mpd) to the group "users".
usermod -G users mpd
Create the music database. If you're music files don't scroll down the screen, then mpd isn't finding them. Make sure you made the symbolic link to mpd's default music folder, and that the permissions are set correctly.
mpd --create-db
Restart mpd, because earlier we changed mpd.conf.
/etc/init.d/mpd restart
Find and play your music. Replace yourawesomeband with whatever artist you want to listen to.
mpc search artist yourawesomeband | mpc add ; mpc play
Lightweight Debian Samba Fileserver

(The above photo is "Granny's flowers", by Abbie F (C) via Flickr).
This is the lightest way I know of installing a samba fileserver (network fileserver compatible with Windows machines). This will work for any extremely old machine you may have around. Once it's set up, you can run it headless (just the tower connected to power and the network; no monitor, keyboard, or mouse).
- Download and burn the Debian "netinst" cd image. You can get it at http://www.debian.org/CD/netinst/.
- Boot the computer from the netinst disk. You can follow most of the defaults in the installation. Obviously you'll want to make note of any user names, passwords, host names, etc. that you choose. When you get to the Select and Install software section, de-select everything (no Desktop Environment, no Standard System, or whatever they're calling it -- nothing).
- Once it's installed, login. This will be a text-only login, nothing fancy.
- mkdir ~/shared
- su (then enter your password) (this makes you the super user, AKA root).
- apt-get update && apt-get dist-upgrade
- apt-get install samba
- cd /etc/samba
- cp smb.conf smb.conf.original
- vim smb.conf (or you can use nano if you don't like vim: nano smb.conf)
- Erase everything in the file and replace it with the text from my smb.conf file (found below) (make sure you replace YOURUSERNAME with your actual username, and make sure all of the quotes are straight quotes), then save and close the file.
- /etc/init.d/samba restart
- smbpasswd -a YOURUSERNAME (and enter the password you want to use when asked)
Here's my smb.conf file. Other than changing the YOURUSERNAME to your actual user name, most users won't need to make any changes (there are a few exceptions though). Make sure all of the quotes are "straight" quotes, as WordPress likes replacing them with "smart" quotes, which breaks stuff (you are seriously going to have to replace those quotes).
[global]
server string = Fileserver
interfaces = 127.0.0.0/8, eth0
bind interfaces only = Yes
syslog = 0
log file = /var/log/samba/log.%m
max log size = 1000
smb ports = 139
load printers = No
printcap name = /dev/null
disable spoolss = Yes
show add printer wizard = No
panic action = /usr/share/samba/panic-action %d
printing = bsd
print command = lpr -r -P'%p' %s
lpq command = lpq -P'%p'
lprm command = lprm -P'%p' %j
[files]
comment = Shared files
path = /home/YOURUSERNAME/shared
force user = YOURUSERNAME
force group = YOURUSERNAME
read only = No
create mask = 0775
directory mask = 0775
That's it. You can access the fileserver from a Windows machine by typing \\THEHOSTNAMEYOUPICKED and entering your username and the password you selected in the "smbpasswd" step. I usually also install ssh and set up a static IP address, but that's beyond the scope here. Feel free to mention any problems, omissions, errors, and security flaws.
Install SCMPC – Audioscrobbling MPD to Last.fm in Ubuntu 9.10

I've been using SCMPC to scrobble my music played with MPD to Last.fm for a couple of years now. I can't find a package for it in the repositories, but it's easy to install from source. The source hasn't changed in almost 3 years, but it still seems to be working fine.
Here's how I installed it in Ubuntu 9.10 Karmic Koala.
The SCMPC homepage is here. You can download the source at this link.
First install the dependencies you'll need:
sudo apt-get install libargtable2-dev libconfuse-dev libdaemon-dev
You may also need libcurl (I apparently already had it).
Then extract the source code (the file was scmpc-0.2.2.tar.bz2 in my case) by right-clicking and selecting "Extract here". In a terminal, cd into the directory you just extracted. Then just:
./configure make sudo make install
That should install it. Now create a directory for the config file in your home directory:
mkdir ~/.scmpc
You can copy a template for the config file:
cp /usr/local/share/scmpc/scmpc.conf ~/.scmpc/
And then fill in your own details.
Or you can just make your own. Here's copy of mine.
log_level = debug
log_file = "/home/james/.scmpc/scmpc.log"
pid_file = "/home/james/.scmpc/scmpc.pid"
cache_file = "/home/james/.scmpc/scmpc.cache"
mpd {
#host = "localhost"
#port = 6600
#timeout = 5
#password =
}
audioscrobbler {
username = "my_user_name"
password_hash = "a_hash_of_my_password"
}
I keep all of SCMPC's operating files in ~/.scmpc
I use password_hash= instead of password= so I don't have to store my password in plain text. You can get a hash of your password like this:
echo -n your_password | md5sum
Don't include any spaces or the dash ( - ) symbol that follow the hash.
Now just start SCMPC and restart MPD. Add SCMPC to your startup programs (System -> Preferences -> Startup Applications) if you want it running at startup.
scmpc sudo /etc/init.d/mpd restart
BASH – Get Size of Directory in "ls -l" Output

(The above photo is "flowring cabbage regular", by abundantlyabove29 (C) via Flickr).
UPDATE: I've written a newer and much better version of this script. You can find it at: http://www.shellperson.net/show-directory-size-with-ls/
I found a function like this a long time ago in some forum, but I remember it not working with filenames that include spaces. There's almost certainly a better and more-efficient way of doing this, but here's draft one.
This will output the same data as "ls -lh", in almost the exact same format, except directories will show the size of the sum of their contents (du -sh) instead of the 4.0K of space the directory "file" takes up. The only noticeable difference in format is that there is a slightly larger gap between the size and the date columns.
#!/bin/bash ## mimic "ls -l" except display size of sum of directory's contents for x in *; do echo -e "$(ls -lL | grep -w "$x" | cut -d ' ' -f 1-4) $(du -sh "$x" | cut -d ' ' -f 1)" "\t" "$(ls -lL | grep -w "$x" | cut -d ' ' -f 5-20 | sed s/^\ *// | cut -d ' ' -f 2-20)"; done
It's hard to enter code in a presentable way in wordpress - and this code doesn't appear perfectly. Note that the multiple-space gap that delimits (-d) the second "cut" command is a tab. You can add a tab at the command line by using CTRL+v followed by TAB. The code does work if you use the copy-to-clipboard button on the code block.
I saved this as "lsd", made it executable, and put it in a directory in my $PATH (~/bin).
Installing MPD & MPC in Ubuntu 9.10 Karmic Koala

(The above photo is "more flowers", by Abbie F (C) via Flickr).
EDIT: After running the setup described herein for several days, I've uninstalled PulseAudio and use ALSA instead. While PulseAudio may be a theoretically better system, its implementation in 9.10 is perfectly awful. Not only was MPD/MPC constantly crashing, but sometimes I'd lose sound system-wide. Also once Pulse is gone, you can roll back to Adobe Flash 9 (with sound!), which is infinitely better on my machine than 9.10's implementation of Flash 10.
The installation wasn't as straight-forward as I'd hoped, so maybe these notes will help others. This is specifically for Ubuntu 9.10 Karmic Koala (I'm running the 32 bit / i386 desktop edition), running the default pulse audio.
Install from official sources:
sudo apt-get install mpd mpc
Symlink your music folders to MPD's default watch folder:
sudo ln -s /path/to/music /var/lib/mpd/music
Update your MPD database. The new version of MPD has changed some things about the "mpd --update-db" command, so you should use:
mpc update
At this point I could play music, I just couldn't change the volume. I got the following error:
error: ACK [52@0] {setvol} problems setting volume
The problem was that MPD was trying to use ALSA instead of pulse audio. Edit the MPD configuration file to enable pulse audio. Find the Audio Output section of the file and add or un-comment the following lines:
audio_output {
type "pulse"
name "My MPD PulseAudio Output"
}
I did follow the instructions at http://ubuntuforums.org/showthread.php?t=1298789 regarding the PulseAudio Preferences (paprefs), but I don't know if it's necessary.
Finally, add the user "mpd" to the PulseAudio groups in order to give it permission to use PulseAudio:
sudo usermod -aG pulse,pulse-access mpd
Restart MPD:
sudo /etc/init.d/mpd restart
That's what worked for me.
Easily Change Text Color with BASH

Here's a script to easily add color to other BASH scripts. The only trick to it is that it uses a character that I don't know how to put on the web.
NB - If you select the "view plain" link at the top of the container surrounding the script, it will open a new link with the plain text of the script. You should use this plain text. Not only does it preserve the special character the script uses to change colors, it also preserves other characters that WordPress changes (note line 5, between "cat" and "EOF"). If you don't use the "view plain" link and try to cut, but instead paste the script directly from this page, it won't work. Also, if you need to create the special character I use to make it display different colors, you can make it in gnome-terminal by pressing "ctrl+v" followed by "ctrl+[".
#!/bin/bash
## Specify color to write in using arguments
function --help {
cat << EOF
ERROR: $0 requires a color argument.
USAGE: Changes the color of the text piped into it.
These color arguments are availabe:
ARGUMENT SHORTCUT
white ------ w
red ------ r
green ------ g
yellow ------ y
blue ------ b
purple ------ p
teal ------ t
bold ------ bb
The "bold" argument will modify any color.
Use a max of 2 arguments (one color and bold).
EOF
}
function bold {
# make the color bold
BOLD=1\;
}
function white {
COLOR=1
}
function red {
COLOR=31
}
function green {
COLOR=32
}
function yellow {
COLOR=33
}
function blue {
COLOR=34
}
function purple {
COLOR=35
}
function teal {
COLOR=36
}
## shortcuts
function bb {
bold
}
function w {
white
}
function r {
red
}
function g {
green
}
function y {
yellow
}
function b {
blue
}
function p {
purple
}
function t {
teal
}
## Execution
if [ "$#" = 0 ]
then
--help
fi
while (($#));
do
$1
shift
done
echo -n "["$BOLD""$COLOR"m"
cat
echo -n "[0m"
Here's a link to an example of what it looks like in action. Note that the input must be piped into the script.
Quickly Check Gmail with BASH

A very simple script to check if I have any new gmail:
#!/bin/bash ## Quickly checks if I have new gmail echo -e "Checking for new messages... \c" atomlines=`wget -T 3 -t 1 -q --secure-protocol=TLSv1 \ --no-check-certificate \ --user=USERNAME --password=PASSWORD \ https://mail.google.com/mail/feed/atom -O - \ | wc -l` echo -e "\r\c" [ $atomlines -gt "8" ] \ && echo -e " You have new gmail. \c" \ || echo -e " No new gmail. \c"
Just replace USERNAME and PASSWORD with your information (caution - your password is stored in plain text). I use colors on mine, but I'm not sure I can correctly post the requisite special character in WordPress. Here's what it looks like in gedit.

I can make that special character in gnome-terminal by pressing CTRL+v and then CTRL+[
There's probably an easier way to use colors, I just don't know it.
In case it's not clear from the script, this just downloads the atom feed (an XML file) and checks if it's more than eight lines long. If it is, then you have unread mail. (At least on my account, when my inbox has no unread items, the atom feed is eight lines long). The number may need to be adjusted if gmail changes the format of their feeds.
ssh Shortcuts in Bash

(The above photo is "Good and Evil", by Abbie F (C) via Flickr).
This is the bash script I use to ssh into my fileserver (without having to type the whole IP address, etc). It works for simply logging in with ssh, or for sending a command only. If you want to send a series of commands, you'll need to separate each command with \; or else it (a lone semi-colon) will be interpreted as an instruction to run the command on the local machine after the first command is sent via ssh (you're 'escaping' the semi-colon, so it gets sent through ssh as a regular character, instead of its typical role of separating commands). This method works for me, but I'd love to learn a better way if there is one.
I name the script something short and put it in my path. I also use it in conjunction with password-less login. I know it's not such a big deal to write out:
ssh user@ipaddress "command -arguments"
but it saves time if you're constantly ssh'ing to that machine.
Here it is in a more-legible format, that shouldn't be copied and pasted (because of the way WordPress changes quotation marks):
#!/bin/bash
SSH_ARGUMENTS=`while (($#)) ; do echo -n "$1 " ; shift ; done ; echo`
ssh administrator@192.168.0.202 "$SSH_ARGUMENTS"
And here it is in a way that's easier to copy and paste (but harder to read, in my opinion):
#!/bin/bash SSH_ARGUMENTS=`while (($#)) ; do echo -n "$1 " ; shift ; done ; echo` ssh administrator@192.168.0.202 "$SSH_ARGUMENTS"
Also, here's a slight variation that's useful if you have multiple machines with a sequential naming scheme, where you can specify the machine number:
#!/bin/bash ## for example: comp 4 shutdown -r now ## note: in my setup, the username correlates with the computer's number WORKSTATION_NUMBER=$1 shift SSH_ARGUMENTS=`while (($#)) ; do echo -n "$1 " ; shift ; done ; echo` ssh $WORKSTATION_NUMBER@192.168.0.10$WORKSTATION_NUMBER "$SSH_ARGUMENTS"
Edit: I suppose anyone who knows anything about BASH would know that the entire SSH_ARGUMENTS line could be removed and the variable $SSH_ARGUMENTS replaced with $*
...every day learning a little bit more.