Archive for August, 2009


Connecting to a server across the internet is much more secure using SSH. There is a way that you can mount a folder on a remove server using the SSHFS service.sshfs is a filesystem client based on the SSH File Transfer Protocol. Since most SSH servers already support this protocol it is very easy to set up: i.e. on the server side there’s nothing to do. On the client side mounting the filesystem is as easy as logging into the server with ssh.

sshfs is based on FUSE (userspace filesystem framework for Linux), thus you will have to prepare fuse kernel module to be able to use it.

Install sshfs in Ubuntu

sudo apt-get install sshfs

This will complete the installation part.

Now we will use the modprobe command to load it

sudo modprobe fuse

Now you need to set up some permissions in order to access the utilities. Replace with your username.

sudo adduser fuse

sudo chown root:fuse /dev/fuse

sudo chmod +x /dev/fusermount

Since we’ve added ourselves to a user group, we need to logout and back in at this point before we continue.

Now we’ll create a directory to mount the remote folder in. I chose to create it in my home directory and call it remoteserv.

mkdir ~/remoteserv

Now we have the command to actually mount it. You’ll be prompted to save the server key and for your remote password.

sshfs username@ipaddress:/remotepath ~/remoteserv

In the above command you need to replace usename and ipaddress.

Now you should be able to cd into the directory and start using it as if it was local.

user@testserver:~/remoteserv$ ls -l
total 16
drwxr-xr-x 1 951247 155725 4096 2006-16-13 13:03 Music
drwxr-sr-x 1 root root 4096 2006-10-11 06:05 logs
drwx—— 1 951247 155725 4096 2006-02-11 16:19 Documents
drwxrwxr-x 1 951247 155725 4096 2006-10-09 02:43 scripts

Advertisements
https://i0.wp.com/i30.tinypic.com/azjm80.jpg
AutoKey is a text replacement and hotkey utility. It allows you to manage collection of phrases or other text, and assign abbreviations and hotkeys to these phrases allowing you to insert them on demand into whatever program you are using. This is the most basic functionality, and is similar to a well-known Windows utility called AutoHotkey.

To add the AutoKey Ubuntu repository, type this in a terminal:

-for Ubuntu Jaunty Jackalope:

sudo sh -c "echo 'deb http://ppa.launchpad.net/cdekter/ppa/ubuntu jaunty main' >> /etc/apt/sources.list"

-For Ubuntu Intrepid Ibex:

sudo sh -c "echo 'deb http://ppa.launchpad.net/cdekter/ppa/ubuntu intrepid main' >> /etc/apt/sources.list"

-For Ubuntu Hardy Heron:

sudo sh -c "echo 'deb http://ppa.launchpad.net/cdekter/ppa/ubuntu hardy main' >> /etc/apt/sources.list"

Then we need to add the PPA key. The following command is for any Ubuntu version:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 6E3C0CE5

And then, to install AutoKey:

sudo apt-get update && sudo apt-get install autokey

For other Linux distributions, download AutoKey from here.

After installing AutoKey and launching it from your Accessories menu, you simply head to its system tray icon and hit Configure to get started. Give a new “phrase” a descriptive name, type in the text you want to appear when it’s triggered, choose whether or not the trigger phrase disappears, and then assign an abbreviation to it. By default, AutoKey triggers text replacements when you type your abbreviations and hit Enter, but you can configure phrases to automatically trigger or be launched only from keyboard shortcuts or the tray menu. Ubuntu 9.04’s graphical server is reported to have a few issues with the abbreviation triggers, but I’ve found it to work in most cases, and having the tray menu and keyboard shortcuts to type in abbreviations is almost as handy in most cases.

I needed a fast way to have people sharing documents and other data remotely. I wanted to avoid the cloud, I really rather having things locally at work.

This was made in a Debian 5 (lenny) sever and pretty much works the same way for a recent Ubuntu server. I’ve done most of this in a 9.04 Ubuntu box.

First I configured apache with the webdav module:

#aptitude install apache2

Activate de webdav module:

# a2enmod dav_fs

The webdav acess should be limited to authorized users. So we create a protected /webdav location by editing /etc/apache2/sites-available/webdav:

# vim /etc/apache2/sites-available/webdav

Alias /webdav /var/www/webdav

DAV On
AuthType Digest
AuthName “webdav”
AuthUserFile /etc/apache2/webdav.passwd
Require valid-user

we also need, for more secure authentication, to activate the auth_digest module:

# a2enmod auth_digest

The we need to create our users and passwords:

# htdigest -c /etc/apache2/webdav.passwd webdav username

When adding a new user don’t use the -c flag because it will override the previous settings.

Then we need to add our directory and make it writable by the www-data group:

# mkdir /var/www/webdav
# chgrp www-data /var/www/webdav
# chmod g+w /var/www/webdav

Lest’s activate our site:

#a2ensite webdav

And reload apache:

# /etc/init.d/apache2 reload

Test it with a webdav client like cadaver

$ cadaver http://yourdomain/webdav

Now to secure the connection with openssl:

# aptitude install openssl

# a2enmod ssl

We need to generate a personal certificate for our server:

# openssl genrsa -des3 -out server.key 1024

# openssl req -new -key server.key -out server.csr

# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

Now we have 3 files: server.key, server.csr and server.crt. Let’s copy erver.key and server.crt to the certs and private directories:

# cp server.crt /etc/ssl/certs

# cp server.key /etc/ssl/private

Now we need to edit /etc/apache2/ports.conf:

# vim /etc/apache2/ports.conf

You have change the port from 80 to 443. It should look like this:

NameVirtualHost *:443

#Listen 80

# SSL name based virtual hosts are not yet supported, therefore no

# NameVirtualHost statement here

Listen 443

Now edit /etc/apache2/sites-enabled/000-default and change the port 80 to 443 in the firts line:
Note that http requests will be bloqued, and only https requests will be accepted.

Now lets edit /etc/apache2/sites-available/default to tell apache where to find the certificate:

#vim /etc/apache2/sites-available/default

DocumentRoot /var/www/

SSLEngine on

SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire

SSLCertificateFile /etc/ssl/certs/server.crt

SSLCertificateKeyFile /etc/ssl/private/server.key

(…)

Time to reload apache and try it out!

# /etc/init.d/apache2 force-reload

Have you ever wondered how to keep your Ubuntu clean after installing/removing programs and such? Here’s a few tips on how to do it:

Tip #1 – Getting rid of Residual Config packages – In Synaptic Package Manger, there is a built-in feature that gets rid of old Residual Config packages. Residual Config packages are usually dependency packages that are left behind after you uninstall a package from your machine. To use this feature, go to System > Administration > Synaptic Package Manager. On the bottom left hand corner of the window, click the Status button. In the list above the Sections, Status, Search, and Custom buttons, you should see the following text:

Quote:
Installed
Installed (local or obsolete)
Not installed
Residual config

Click on the “Residual config” text. (If the “Residual config dialogue does not appear, that means you do not have any Residual Config packages on your machine and you can skip down to Tip #2.) Do you see the packages that popped up in the window on the right? Those are the Residual Config packages. To get rid of these pests, click on the box to the left of the package name and select “Mark for Complete Removal”. After you have done that for all of the Residual Config packages, look at the top of the Synaptic Package Manger window. Do you see the green check mark with the text “Apply” right under it? Click that button, and you’ll flush all those Residual Config packages down the toilet!

================================================== ================================================== ====================

Tip #2 – Getting rid of partial packages – This is yet another built-in feature, but this time it is not used in Synaptic Package Manager. It is used in the Terminal. To access the Terminal, go to Applications > Accessories > Terminal. Now, in the Terminal, key in the following command (or you can just copy and paste from here):

Code:
sudo apt-get autoclean

Enter your password when prompted and press Enter. See the package names that appeared in the Terminal? Those were partial packages that have just been deleted. Say goodbye! That’s it! This command deletes the not-so-fully-downloaded packages that you acquire when a package that is being downloaded is suddenly cancelled. This is my favorite little trick when it comes to getting rid of junk files.

================================================== ================================================== ====================

Tip #3 – Getting rid of unnecessary locale data – For this tip, you need to download the “localepurge” package found in Synaptic Package Manager. “localepurge” is just a simple script to recover diskspace wasted for unneeded locale files and localized man pages. It will automagically be invoked upon completion of any apt installation run.

To open Synaptic Package Manager, follow the instructions in Tip #1. After opening up Synaptic Package Manager, click the Sections button on the bottom left hand corner of the window, if it is not already clicked. Next, at the top of the Synaptic Package Manager window, click the Search button. In the search window, key in the following text :

Quote:
localepurge

Did the “localepurge” package popup in the package window? It probably did, unless you do not have the correct Repositories. Now, click on the box next to the “localepurge” package name. Click on Mark for Installation. Now click the Apply button at the top of the window and wait for the downloading and installing of the “localepurge” package to finish. Once it is done, a new window should popup that has a bunch of abbreviations on it. for example:

Quote:
en
fr
po
sp
ka
etc…

You want to select the abbreviation of the language that you speak, or use with Ubuntu, ignoring the capitalized ones. For example, I speak english, so I would select the “en” abbreviation. A french speaker would select the “fr” abbreviation. So on and so forth… Then click next. All done!

================================================== ================================================== ====================

Tip #4 – Getting rid of “orphaned” packages – For this tip, you need to download the “deborphan” package found in Synaptic Package Manager. “deborphan” finds “orphaned” packages on your system. It determines which packages have no other packages depending on their installation, and shows you a list of these packages. It is most useful when finding libraries, but it can be used on packages in all sections…

To open Synaptic Package Manager, follow the instructions in Tip #1. After opening up Synaptic Package Manager, click the Sections button on the bottom left hand corner of the window, if it is not already clicked. Next, at the top of the Synaptic Package Manager window, click the Search button. In the search window, key in the following text :

Quote:
deborphan

Did the “deborphan” package popup in the package window? It probably did, unless you do not have the correct Repositories. Now, click on the box next to the “deborphan” package name. Click on Mark for Installation. Now click the Apply button at the top of the window and wait for the downloading and installing of the “deborphan” package to finish. Once that is done, open up the Terminal. Instructions for doing that are located in Tip #2. After you have gotten the Terminal open, key in the following command (or copy and paste from here):

Code:
sudo deborphan | xargs sudo apt-get -y remove --purge

Enter your password when prompted and press Enter. See the package names that appeared in the Terminal? Those were orphaned packages that have just been deleted. Say goodbye! This is my second favorite way of dealing with junk files.

================================================== ================================================== ====================

Tip #5 – Adding a “Find orphaned packages” to Synaptic Package Manager – This is not really much of a tip on how to get rid of junk files. It’s more like adding a “deborphan” shortcut to Synaptic Package Manager so that you don’t have to use the Terminal to find “orphaned” packages.

Please note: You must have the “deborphan” package installed or else this will not work.

To start this out, open up Synaptic Package Manager with the instructions from Tip #1. Now, at the top of the Synaptic Package Manager window, click the Settings button, followed by the Filters button. In the Filters window, on the bottom left hand corner, push the New button. You can name the new Filter if you like, but it is not necessary. I named mine “Orphaned”. With your new Filter selected, in the “Status” tab on the right, click the Deselect All button. Next, check the “Orphaned” option under the “Other” category. Then click the OK button.

To use this new filter, click the Custom button on the bottom left hand corner of the Synaptic Package Manager window. You should see the following text, or something similiar :

Quote:
Broken
Marked Changes
(Whatever you named your “deborphan” Filter)
Package with Debconf
Search Filter

Click on the “(Whatever you named your “deborphan Filter)” text. Do you see the packages that popped up in the window on the right? Those are the “orphaned” packages. To get rid of these buggers, click on the box to the left of the package name and select “Mark for Complete Removal”. After you have done that for all of the “orphaned” packages, look at the top of the Synaptic Package Manger window. Do you see the green check mark with the text “Apply” right under it? Click that button, and you’ll get rid of all the “orphaned” packages forever (Probably)!

#!/bin/bash
if ( `gconftool –get /apps/nautilus/preferences/show_desktop` == “true” ) then
gconftool –set /apps/nautilus/preferences/show_desktop \
–type boolean false
else
gconftool –set /apps/nautilus/preferences/show_desktop \
–type boolean true
fi
# EOF

Create the script and put it in your home directory.

make executeable sudo chmod +x toggledesktop

then you can create launcher on you desktop when you press it will hide all your desktop files and folders,press again and you will make everything visible again

Let me know what you think about this and let me know if you have a better way

WHAT IS HEX?

HEX is short for hexidecimal. Hexidecimal is base 16. Where humans are used to the decimal system (base 10) with numbers 0 through 9, hex has the digits 0,1,2,3,4,5,6,7,8,9,A,B,C D,E, and F. Although this may appear confusing, the reason HEX was chosen is that it provides a simple way to represent 4 binary bits as a single digit. EXAMPLE: Binary 0000 = HEX 0 or binary 0101 = HEX 5 or binary 1100 = HEX C. The table below shows binary numbers and their hexadecimal equivalents.

BINARY HEX
0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
1001 9
1010 A
1011 B
1100 C
1101 D
1110 E
1111 F

From the above table you can see that if you wish to represent the binary number 1110010100110010 you can write it as E532 hex. This is why hex has become the defacto standard to represent and display binary data; it allows humans to represent large groups of binary data in a compact form.


WHAT IS ASCII?

ASCII stands for American Standard Code for Information Interchange. This is a standard translation for HEX (binary) codes into printable or readable characters. The letters you are reading on the screen right now are represented in the computer as groups of bits. Without a standard, any computer manufacturer could decide which group of bits would represent which letter or number. In ASCII an upper case A is represented by the value 41H. the number 3 is represented by the value 33H. When you view the editor display of a device programmer you should see a display of HEX information and also (usually to the right) a display of the ASCII translation of the HEX data. If the data from an EPROM contains characters which are to be displayed to a user, these characters will appear in the ASCII display area.

To really understand what’s going, it’s best to learn C languages bit operators and about truth tables.

    | bit OR
    & bit AND
    ~ bit NOT
    ^ bit EXLUSIVE OR (XOR)
    << bit LEFT SHIFT
    >> bit RIGHT SHIFT

These operators work on bits and not logical values. Take two 8 bit bytes, combine with any of these operators, and you will get another 8 bit byte according to the operator’s function. These operators work on the individual bits inside the byte.

A truth table helps to explain each operation. In a truth table, a 1 bit stands for true, and a 0 stands for false.

The OR operation truth table:

    0 OR 0 = 0
    0 OR 1 = 1
    1 OR 0 = 1
    1 OR 1 = 1

The AND operation truth table:

    0 AND 0 = 0
    0 AND 1 = 0
    1 AND 0 = 0
    1 AND 1 = 1

The XOR operation truth table:

    0 XOR 0 = 0
    0 XOR 1 = 1
    1 XOR 0 = 1
    1 XOR 1 = 0

The NOT operator inverts the sense of the bit, so a 1 becomes a 0, and a 0 becomes a 1.

So let’s say I have a byte foo that is initialized to 0:

Code:
unsigned char foo = 0;

To set bit 0 in foo and then store the result back into foo:

Code:
foo = foo | 0x01;

The OR operation is used between the variable that we want to change and a constant which is called a BIT MASK or simply the MASK. The mask is used to identify the bit that we want changed.

Remember that we write the constants in hexadecimal because it’s shorter than writing it in binary. It is assumed that the reader knows how to convert back and forth between hex and binary. Wink

Usually, though the statement is made shorter in real programming practice to take advantage of C’s compound assignment:

Code:
foo |= 0x01;

This is equivalent to the statement above.

To clear bit 0 in foo requires 2 bit operators:

Code:
foo = foo & ~0x01;

This uses the AND operator and the NOT operator. Why do we use the NOT operator? Most programmers find it easier to specify a mask wherein the bit that they are interested in changing, is set. However, this kind of mask can only be used in setting a bit (using the OR operator). To clear a bit, the mask must be inverted and then ANDed with the variable in question. It is up to the reader to do the math to show why this works in clearing the desired bit.

Again, the statement is made shorter with a compound assignment:

Code:
foo &= ~0x01;

To see if a bit is set or clear just requires the AND operator, but with no assignment. To see if bit 7 is set in the variable foo:

Code:
if(foo & 0x80)
{
}

The condition will be zero if the bit is clear, and the condition will be non-zero if the bit is set. NOTE! The condition will be NON-ZERO when the bit is set. But the condition will not NECESSARILY BE ONE. It is left to the reader to calculate the value of the condition to understand why this is the case.

There is another useful tool that is not often seen, and that is when you want to flip a bit, but you don’t know and you don’t care what state the bit is currently in. Then you would use the XOR operator:

Code:
foo = foo ^ 0x01;

Or the shorter statement:

Code:
foo ^= 0x01;

A lot of times the bit mask is built up dynamically in other statements and stored in a variable to be used in the assignment statement:

Code:
foo |= bar;

Sometimes, a programmer wants to specify the bit NUMBER that they want to change and not the bit MASK. The bit number always starts at 0 and increases by 1 for each bit. An 8 bit byte has bit numbers 0-7 inclusive. The way to build a bit mask with only a bit number is to LEFT SHIFT a bit by the bit number. To build a bit mask that has bit number 2 set:

Code:
(0x01 << 2)

To build a bit mask that has bit number 7 set:

Code:
(0x01 << 7)

To build a bit mask that has bit number 0 set:

Code:
(0x01 << 0)

Which ends up shifting the constant 0 bytes to the left, leaving it at 0x01.

MACROS

Because there are a number of programmers who don’t seem to have a familiarity with bit flipping (because they weren’t taught it at school, or they don’t need to know it because of working on PCs), most programmers usually write macros for all of these operations. Also, it provides a fast way of understanding what is happening when reading the code, or it provides additional functionality.

Below is a set of macros that works with ANSI C to do bit operations:

Code:
#define bit_get(p,m) ((p) & (m))
#define bit_set(p,m) ((p) |= (m))
#define bit_clear(p,m) ((p) &= ~(m))
#define bit_flip(p,m) ((p) ^= (m))
#define bit_write(c,p,m) (c ? bit_set(p,m) : bit_clear(p,m))
#define BIT(x) (0x01 << (x))
#define LONGBIT(x) ((unsigned long)0x00000001 << (x))

To set a bit:

Code:
bit_set(foo, 0x01);

To set bit number 5:

Code:
bit_set(foo, BIT(5));

To clear bit number 6 with a bit mask:

Code:
bit_clear(foo, 0x40);

To flip bit number 0:

Code:
bit_flip(foo, BIT(0));

To check bit number 3:

Code:
if(bit_get(foo, BIT(3)))
{
}

To set or clear a bit based on bit number 4:

Code:
if(bit_get(foo, BIT(4)))
{
bit_set(bar, BIT(0));
}
else
{
bit_clear(bar, BIT(0));
}

To do it with a macro:

Code:
bit_write(bit_get(foo, BIT(4)), bar, BIT(0));

If you are using an unsigned long (32 bit) variable foo, and have to change a bit, use the macro LONGBIT which creates un unsigned long mask. Otherwise, using the BIT() macro, the compiler will truncate the value to 16-bits.[/list]


Most of Windows users may know “Norton Ghost”. Norton Ghost is a backup software for hard disks. It can backup a whole hard disk or a partition to an image file. Also, Norton Ghost can copy all the contents from a hard disk to another exactly. However, Norton Ghost is a Windows software, users on other operating system (such as Linux) can not enjoy its powerful function. Fortunately, most of Unix/Linux operating system provides a command line whose function is similar to Norton Ghost, it is called “dd”.

In fact, “dd” is much powerful than Norton Ghost. You can use many arguments to control it. In this short article, we only concern on how to backup a whole hard disk or a partition.

Hard Disk Clone

Suppose you have a 40GB hard disk and a removable hard disk whose capacity is 60GB, and you want to backup all the files from the hard disk to the removable disk. With “dd”, it is a very easy task. Again, suppose your hard disk’s Unix device name is /dev/sda and the removable disk is /dev/sdb. The following command can copy all the content from /dev/sda to /dev/sdb:

dd if=/dev/sda of=/dev/sdb

Here, if=… sets the source and of=… sets the destination. “dd” doesn’t care of the contents of the hard disk. It just reads bytes from /dev/sda and writes them into /dev/sdb. It doesn’t know what are files. So, the hard disk file system and how many partitions it has are not important. For example, if /dev/sda is splitted into three partitions, the /dev/sdb will have the same partitions. i.e. “destination” is completely same with “source”.

Notice: to execute “dd” you should login as “root” or switch to “root” using “su” command. And you must be careful, a small mistake may cause a serious problem!

Making a Hard Disk Image File

Most of time you don’t want to make a complete duplication of your hard disk. You may prefer to creating an image file of the hard disk and save it in other storage devices. The following command will create an image file “disk1.img” in your user’s directory from /dev/sda:

dd if=/dev/sda of=~/disk1.img

Since you have created an image file, you can compress it with “gzip” or “bzip2”:

gzip disk1.img #generates disk1.img.gz or

bzip2 disk1.img #generates disk1.img.bz2

You can save much storage space with compression. But it will take very long time.

Partition Clone

Backing up a hard disk partition is much similar to backing up a whole hard disk. The reason is that Unix/Linux uses device name, such as /dev/sda1, /dev/sda5… to indicate the partitions. For example, if you want to create an image file from the first partition of /dev/sda, use “dd” like this:

dd if=/dev/sda1 of=~/disk2.img

Also, you can compress the image file:

gzip disk2.img

By the way, you can copy a partition to another partition completely, just set “of” to the partition’s device name. For example:

dd if=/dev/sda1 of=/dev/sdb5

This command will copy all the contents from /dev/sda1 to /dev/sdb5. You must be sure that the capacity of /dev/sdb5 is larger than /dev/sda1.

Restoring from an Image File

To restore a partition or a hard disk from an image file, just exchange the arguments “if” and “of”. For example, restore the whole hard disk from the image file “disk1.img”:

dd if=disk1.img of=/dev/sda

Restore the first partition of /dev/sda from the image file “disk2.img”:

dd if=disk2.img of=/dev/sda1