Posts Tagged ‘Linux’

Re-Map Default Mouse Buttons in Ubuntu Karmic

November 9th, 2009

While setting up a new installation of Ubuntu 9.10 for a friend, I ran into a small issue: she was using a 4 button Kensington trackball mouse, and the default key mappings made little sense.  Naturally, there were no drivers or software available, but after some research I was able to figure out how to manually remap the mouse buttons.

Step 1. Find the name of your device.
This step is pretty simple.  Open up a terminal and type in the command:

xinput list

This will list all of the input devices recognized by the X window system.  The names are in quotes, and should be pretty self-explanatory; any external mice should be near the bottom.

xinput list

Step 2. Find your button numbers
Each mouse button has a unique number to the system, and your next job is to find out what they are.  In your termal window type:

xev

This will open a new smaller window.  Whenever your mouse is over the new window, the terminal will print any input it receives.  This includes both movement and button presses.  For each button on the mouse, press it, and write down what button number it displays.  Don’t forget that scroll up, down, left, and right and wheel click are all treated as different “buttons”.

xev

Step 3. Re-Map the buttons
You can modify your your mappings with the following command (substituting your device name from step 1)

xinput set-button-map "Device Name" 1 2 3 4 5

Running the above command will most likely change nothing, it will map all the buttons to their default functions.  Let’s say your left and right click map to 1 & 3 respectively.  If you wanted to switch them (perhaps for a left-handed user) the command would be:

xinput set-button-map "Device Name" 3 2 1 4 5

In the case of my friend (with a Kensington pro mouse) we needed to swap the 1 & 3 with the 8 & 9 buttons.  That looked like this:

xinput set-button-map "Kensington Pro PS/2" 8 2 9 4 5 6 7 1 3

Note that you can enter as many numbers as you like, up to the number of mouse buttons.  Any numbers you don’t enter will be assumed to be the sequential default.  Thus the following command is equivalent to the one above:

xinput set-button-map "Kensington Pro PS/2" 8 2 9 4 5 6 7 1 3 10 11 12 13

Step 4. Saving your mappings
Once you’ve found the correct sequence of numbers, you can have it load automatically by creating a startup item.  Navigate to the following menu:

System > Preferences > Startup Applications > Add

and enter the following:

Name: Mouse Button Remap
Command: xinput “Device Name” 1 2 3 4 5
Comment: “Swapped the left and right click”

Add Startup

Ta Da! You’re Done!

Ubuntu Server Setup Checklist

June 20th, 2009

I’ve now set up half a dozen or so Ubuntu Server installations over the past year or two.  For the last few, I created a checklist to make sure I don’t leave any of the smaller, less obvious things out.  I present it here, completely unmodified.  Note, this is more of a preliminary checklist, as it doesn’t include installation of Apache, MySql, PHP or any other programs such as Postfix.  Basically, I’ll perform these steps regardless of whether It’ll be a web or mail server.  These also assume you like the vi text editor, if not, you can substitute emacs, nano, or whatever your preference when neccesary.  Also, some of these are already done depending on your server host.

Time/Date/Language
Fix Locale Warnings:
# apt-get install language-pack-en

Set Timezone:
# dpkg-reconfigure tzdata

Install Time Daemon:
# apt-get install ntp

General
Install Manual Pages:
# apt-get install man

Add Domain name
# vi /etc/hosts
127.0.0.1 localhost
123.456.789.012 computername.domain.com computername (replace external ip)

Security
Add Administrative User (with home directory):
# useradd myusername -m

Give Admin user Sudo Powers
# visudo
myusername ALL=(ALL) ALL

Set Admin Password
# passwd myusername

Set Admin Shell Preference (optional)
# vi /etc/passwd
myusername: […] :bash

Disable Root SSH Login:
# vi /etc/ssh/sshd_config
PermitRootLogin no <–MAKE SURE YOU CREATED ADMIN & PASSWORD

Tighten default permissions for file & directory creation:
# vi /etc/profile
umask 027 (no default access for others)

Install and Set Up Firewall
# apt-get install ufw
# ufw allow ssh <–DO NOT FORGET THIS
# ufw enable

The Sticky Bit

January 20th, 2009

Just about any linux user is familiar with the unix permission system. You have three categories of users (user, group, other) and three different permission options (read, write execute). However, most users don’t know about several advanced permissions, one of which is the sticky bit.

Besides having a cool name, the sticky bit provides a very useful function: when set as a directory permission it lets anyone add things the the directory (write access), but they can only delete things they own. Normally, allowing all users write access also allows all users to delete anything (yeah, that’s dangerous).

In particular, users can only remove files if at least one of the following is true:
-The user is the owner of the file
-The user is the owner of the parent directory
-The user has write permissions on the file

When is this useful? It’s commonly found in var directories, when everyone needs to be able to create files, but shouldn’t modify files for other users. It’s also common in mailbox directories for the same reason. I found it particularly useful for a media folder that is shared between users. Users can add Pictures and Videos to the folder, but can’t delete those belonging to others.

So how do you set it?
-For chmod in relative mode, the sticky bit is designated by a “t”

# chmod t filename

-For chmod in absolute mode, the sticky bit can be added by prepending a “1” the the permission.

#chmod 1777 dirname

Cool huh?

Backing Up is the Cool Thing to Do

November 30th, 2008
External Backup Drive

External Backup Drive

Backups saved my life yesterday. No, seriously. I upgraded an installation of Drupal, and forgot to copy the files for my Email client before I wrote over the root directory. After trying to check my mail (and getting an empty folder), I had about 30 seconds of complete terror, before I realized I had implemented an automated daily backup system about two months ago. Whew! I found a recent version in my backup files, and bingo, there were my mail client files. So, I’d like to talk a bit about backing up.

Every single person who uses a computer should create an automated backup system. Period. And let me give you a few guidelines: Burning CDs doesn’t cut it. Burning DVDs doesn’t cut it. Both take way too much time and energy, and you will quickly forget to keep up. You need to buy a spare hard drive, and dedicate it to backups. Hard drives are cheap. You can find some excellent options here.

Next, create a system to AUTOMATE the process. You don’t want to have to remember. If you have OSX 10.5, that means setting up Time Machine. I commend Apple on their push for automatic user backups. If you’re using XP, look here. If you’re using Vista, look here. If you’re using Linux. Look here and here.

The last link above is what I use to backup my server, although I use a slightly modified version. I have it set up to backup all my files every night. I keep 6 days of nightly backups at all times. Then, once a week, I do a weekly backup, of which I keep 4 at all times. Finally, on the first of every month, I do a monthly backup, of which I keep the last 12 at all times. The advantages of keeping many versions of your files are two-fold. First, your hard drive may crash slowly. In this case, it will start corrupting files before it outright dies. If you’re only keeping one copy of files on you backup drive, you could end up writing over your good files with corrupted ones. Keeping multiple, redundant versions of your data ensures there will always be healthy versions available. Second, your backup solution now serves as an archive, where you can recover files you may have lost or accidentally deleted (see first paragraph).

After reading this, you have no reason not to have an automated, dedicated backup solution. Please, I urge you, go set one up. The $100-$200 you will spend on an external hard drive is NOTHING compared to the value of your non-replaceable pictures, music, and files.

Setting MP3 Bitrate in Rhythmbox

November 28th, 2008

Rhythmbox is the music player that comes on the default Ubuntu installation. Anyone that has ever used iTunes, Windows Media Player or any other similar program will find it very intuitive. You do need to download an extension to add MP3 capability, but this is easy to do.

What frustrated me for months has been the lack of options for ripping music from CDs. Although it has a great selection of formats (WAV, flac, ogg, mp3) it doesn’t give you any options for setting the mp3 bitrate. At last I found a way, and thought I would pass it on:

Open “Preferences” from the “Edit” menu
Select the “Edit” button to the right of “Preferred Format”
Select “CD Quality, MP3” from the menu and hit “Edit”
Under the “Gstreamer pipeline” field you will find the following:

audio/x-raw-int,rate=44100,channels=2 ! lame name=enc mode=0 vbr-quality=6 ! id3v2mux

To remove the default, remove the vbr-quality=6 statement, and replace it with vbr=0 bitrate=256. This will change it from variable to constant bit rate, and set it to 256 kb/s. You can set it to whatever bit rate you prefer, I like 256. You line should now look like the following:

audio/x-raw-int,rate=44100,channels=2 ! lame name=enc mode=0 vbr=0 bitrate=256 ! id3v2mux

Close the window, and Viola! You’ll now rip CDs at a higher quality