Linux Tips and Tricks


Here are some tips for Linux laptop users, including how to sync files effortlessly between a laptop and desktop, how to switch CPU speeds on the fly from the desktop, how to power-save your hard disk, and more. Only one or two are specific to notebooks so desktop users may find them interesting too.

All are taken from the new book Ubuntu Kung Fu, which contains over 300 other fun and useful tips for Ubuntu Linux.

1. Slow Down a Touchpad’s Scrolling

If you have a notebook computer, you might be used to edge scroll on the touchpad when running Windows. This is where the right edge of the notebook’s touchpad is used as a virtual scrollbar—by running a finger up and down, the currently active window scrolls up and down correspondingly.

You might already have realized that you can activate the edge scroll functionality in Ubuntu using the Touchpad tab of System —> Preferences —> Mouse. The problem I had was that the scrolling was just too fast. A light touch on the pad caused the web page or file listing to fly up or down the screen. The solution was to add a line to the xorg.conf configuration file, as follows:

Open the Xorg configuration file into Gedit:

gksu gedit 
/etc/X11/xorg.conf

Look for the two lines that read as follows:

Section "InputDevice"Driver   "synaptics"

Then, beneath all the lines that begin Option, add a new line as follows:

Option "VertScrollDelta" "50"

You can align the words with the other entries in the list if you want, although this doesn’t matter.

<

Save the file, close any open programs, and then hit Ctrl+Alt+Backspace to restart the X server. Log in again as usual, and the changes should be instantly visible.

If the scrolling is now too slow, try changing the value of “VertScrollData” to 25 or perhaps even less—the lower the value, the more sensitive the edge scroll becomes.

To make Firefox scroll fewer lines as you drag and scroll, start Firefox, and type about:config into the URL bar. Agree to carry on despite the warning about voiding a possibly warranty. Then, in the search bar, type mousewheel.withnokey.sysnumlines. In the list of results, double-click the entry so that it reads false and turns bold. Now try the new scroll speed by opening a new tab and browsing to a website.

To speed up the scroll slightly, type mousewheel.withnokey.numlines, and change the value to anything greater than 1. For the ultimate in scrolling, click Edit —> Preferences in Firefox, click the Advanced icon, and put a check in Use smooth scrolling.

2. Set the CPU Speed from the Desktop

With some types of CPU, it’s possible to manually alter the clock speed while the system is running. This can be useful with a notebook computer, for example, where you might choose to throttle down the CPU speed when on battery power to save juice or to minimize heat generation when the computer is resting on your lap.

The CPU Frequency Scaling Monitor applet takes care of this function, but before it can be used, some additional configuration is necessary.

Open a terminal window, and type the following:

sudo dpkg-reconfigure gnome-applets

You’ll see a warning about how enabling the cpufreq-selector program could be a security risk if it is given root powers. This is true, but, as always, usability must be balanced against security. The chances of a hacker exploiting this are very slim. Hit Enter; then, on the next screen, use the cursor keys to highlight Yes, and hit Enter again.

After this, right-click a blank spot on the top panel, click Add to panel, and then select CPU Frequency Scaling Applet from the list. A new applet will be added, showing the current speed of the CPU. By clicking it, you’ll be able to set either the speed you want the CPU to run at or the power-saving mode it should use (these modes vary in name and nature from chip to chip, but what they offer should be obvious from their names).

If your CPU has more than one core, such as Intel’s CoreDuo series, each core must be configured separately. For example, a dual-core chip will need two CPU Frequency Scaling Monitor applets. Just right-click the panel as explained to add another. To alter which particular core each applet controls, right-click an applet, select Preferences, and choose the CPU core under the Monitored CPU heading.

Note that each core can run at a different speed compared to the other core and be switched to a different power-saving mode.

3. Closely Monitor the Power Consumption of a Laptop

Run gnome-power-statistics from a terminal window, and you'll see a graph of the exact power usage of your computer over the time since it booted up (provided your computer's hardware supports it). Try boosting the brightness of your screen or loading programs, and see how much of a drain they can be!

4. Set Hard Disk Power-Saving

Ubuntu has a powerful raft of power management features, accessible through System —> Preferences —> Power Management, but you might notice one missing if you're used to Windows or OS X: hard disk spin downtime. This is where the hard disk powers down after a period of inactivity. When data is requested after this, it spins up again, although there is sometimes a momentary pause while this happens.

It’s possible to set your hard disk to spin down under Ubuntu in order to save power and/or wear and tear (particularly on a computer left on most of the time), but you'll need to edit a configuration file. Follow these steps:

The configuration file containing the settings is hdparm.conf, so open it in Gedit by typing the following into a terminal window: gksu gedit /etc/hdparm.conf.

Look for the line that reads #spindown_time = 24, and remove the hash from the beginning of the line so it reads simply spindown_time = 24.

Alter the spindown_time time to any value you want. Each number is five seconds, so the default setting of 24 equates to 120 seconds (24 x 5 = 120 seconds). However, a value greater than 240 changes things—beyond 240, each unit equals 30 minutes. So, a value of 241 will spin down the disk after 30 minutes, a value of 242 will spin down the disk after 60 minutes, and so on. Setting the line to read spindown_time = 241 is a good choice, because the disk will spin down after 30 minutes of inactivity.

Save the file when you've finished, and reboot for the changes to take effect.

Remember that this doesn't mean the hard disk will spin down thirty minutes after you stop using the computer. It means it will spin down thirty minutes after all hard disk access has ceased. Often Ubuntu will do things like flush its caches or run anacron jobs in the background, meaning the hard disk can't spin down until thirty minutes after these jobs have finished.

To stop the hard disk spindown, edit the hdparm.conf once again, and put a hash (#) before the spindown_time line. Then save the file, and reboot the computer.

5. Synchronize Files Between a Laptop and Desktop PC

If you have two computers, you might want to synchronize data between the two. For example, if you have a laptop, you might want to transfer the files in your Documents folder to the main PC (and vice versa). You could do this manually by creating a network share, but it’s much better to do it automatically, with just a single click.

There are a variety of ways of synchronizing files under Ubuntu, and indeed, this is the kind of task that Linux excels in. However, perhaps the most fuss-free method is to use a program called Unison (or, actually, Unison GTK, which adds a graphical front end to the Unison command-line program; throughout I refer to the whole thing as Unison for simplicity). Unison uses built-in Linux tools to sync files but hides everything behind a friendly user interface.

The following are the steps required to sync the Documents folders on two separate computers using Unison. Before following these steps, ensure each computer has the correct time. This is essential because synchronization will fail otherwise.

These instructions make reference to a desktop PC and laptop computer but could be any two computers capable of running Ubuntu (or indeed any computer with Linux installed that can run Unison):

  1. On the desktop PC, use Synaptic to install the unison-gtk package. Meanwhile, on the laptop, use Synaptic to install the openssh-server and unison-gtk packages. As you might have guessed, Unison uses the SSH program in the background to provide the file transfer conduit but you won’t come into direct contact with it.
  2. Once installed on the desktop PC, Unison can be found on the Applications —> Accessories menu. When it starts, a wizard will walk you through creating an initial profile. The first step is to enter the folder on the desktop PC that you want to synchronize. Click the Browse button, and then locate your Documents folder. Click OK to close the file-browsing dialog box and OK again to move onto the next step of the wizard in Unison.
  3. In the next step, you must tell Unison which folder you want to synchronize with on the laptop. In the Directory text field, type Documents again. There’s no need to precede it with /home/username because Unison will automatically log into the laptop’s /home/ folder each time it synchronizes.
  4. Click the SSH radio button. You’ll now need to find the IP address of the laptop. This can be done by moving over to it, right-clicking its NetworkManager icon, and selecting Connection Information. Then look in the dialog box that appears for the line that reads IP Address. Type what you see (four numbers separated by dots) into the Host text field back on the desktop PC.
  5. In the User text field, still on the desktop PC, type the login name you use on the laptop. Then click the OK button.
  6. You’ll immediately be told that the laptop computer is being contacted. Then a dialog box will pop up telling you that the “authenticity of host can’t be established.” This is fine. Just type yes to continue, and hit OK.
  7. You’ll then be prompted for the login password on the laptop. Type it, and then click OK.
  8. After this, you’ll see a scary-looking warning dialog box saying that “no archives were found for these roots.” Don’t worry. This appears because this is the first time you’ve synchronized. Once you click OK, Unison will detect the files both on the desktop PC and on the laptop (it’s worth pointing out that you won’t see any sign of Unison running on the laptop, and you won’t have to do anything on the laptop—Unison runs automatically in the background).
  9. After a few minutes, the program window on the desktop PC will indicate the file differences between the two folders. The Path heading will show the file in question, and under the Action heading will be the “direction of travel,” indicated by an arrow—if the arrow points left, the file will be transferred to the desktop PC from the laptop. If it points right, the file will be transferred from the desktop PC to the laptop. If you don’t want to synchronize a particular file or folder, select it, and click the Skip button on the toolbar. However, assuming you’re happy with everything, click the Go button on the toolbar. The files will then be copied across. When Unison has finished (look at the status bar in the bottom left of the Unison window and the Status heading in the list of files), you can close the program window.

And that’s all there is to it. After this, you should run Unison on the desktop PC every time you want to sync the Documents folders on the two computers, such as when you get home from work. When Unison starts, just select default from the list.

Note that Unison always updates older files when synchronizing. For example, if you started a file on your desktop PC, transferred it to your laptop using Unison, and edited it while out and about, Unison would automatically overwrite the older file on the desktop PC with the updated version. This makes sense, of course. If the situation arises that the file gets updated on both machines between synchronizations, a question mark will appear alongside the file when you come to synchronize—see screenshot above—and it won’t get automatically copied across. You’ll then have to manually intervene to decide which to overwrite—the copy on the desktop PC or the copy on the laptop. Click the Right to Left toolbar button to overwrite the file on the desktop PC or the Left to Right button to overwrite the file on the laptop.

You can create additional profiles to sync other folders too—just click the Create New Profile button in Unison’s startup program window, type a name for the profile when prompted, and then double-click its entry in the list to start working through the wizard again. I find it useful to synchronize the Desktop folder on both machines because I tend to temporarily store a lot of files there. Don’t choose to sync your entire /home folder—hidden files are copied across too by Unison, and hidden files within your /home folder contain program configuration files unique to each computer. Upon synchronization there would be some almighty file clashes, and the likelihood of the login accounts on both systems getting damaged beyond repair because of mangled configuration files is high.

6. Use an Alternative Wifi Connection Manager

Wicd (http://wicd.sourceforge.net/) is an excellent swap-in replacement for NetworkManager. NetworkManager is the system software that sits in the notification area and handles network connections. Wicd does the same job but uses a piece of software that’s almost entirely independent of existing Ubuntu infrastructure and packs in a few extra features too, such as the ability to configure static IP/DNS addresses and use non-ISP-specific DNS servers such as that offered by OpenDNS

Here’s how to install and configure Wicd:

  1. You'll need to add a new software repository. To do so, click System —> Administration —> Software Sources, click the Third-Party Software tab, then click the Add button, and enter deb http://apt.wicd.net hardy extras. Click Close and then the Reload button to refresh the list of software.
  2. Use Synaptic to search for and install wicd. Once you have it installed, you'll need to reboot, and then you'll find Wicd on the Applications —> Internet menu. Note that the wicd package will remove the NetworkManager packages during installation. You might see a brief error message that the “NetworkManager applet could not find some required resources.” You can ignore this. Once Wicd has been installed, reboot the system, although if you want to set up a notification area icon for Wicd, follow the instructions in the next step first.
  3. To add a notification area icon, similar to that of NetworkManager, a few manual steps are necessary. Click System —> Preferences —> Sessions, and click Add. Type wicd into the Name field and /opt/wicd/tray.py into the Command text area. Leave the Comment text field clear. Then close the dialog box and reboot.
  4. When you start Wicd (it can be found on the Applications —> Internet menu), it will automatically scan for nearby wifi networks. If no networks are shown, click the Refresh toolbar button.
  5. Before you can connect, which is done by clicking the Connect link, “unfold” the configuration options by clicking the little chevron alongside the wifi base station’s entry on the list. Then unfold Advanced Settings, and put a check in Use Encryption. Select the type of wifi protection the base station uses from the list, and and type the key or password in the text box provided. Of course, if the network has no protection (usually described as an open network), then you can skip this step. Then click the blue Connect link. Once you’ve connected to the network, you can quit the Wicd configuration program.

To revert to using NetworkManager, should you want, use Synaptic to install the network-manager package and uninstall the wicd package. Then stop Wicd’s notification area applet starting at GNOME startup—click System —> Preferences —> Sessions, select the entry you created for Wicd, and click the Remove button. The reboot the computer.

7. Password-Protect and Encrypt Files

Any file or folder within Ubuntu can be encrypted so that it can be decrypted only by using a passphrase. This has obvious benefits for laptop users, whose computers might get stolen when they’re out and about: if your laptop should go missing, you can rest assured that any personal files can’t be viewed by the thief.

What actually happens is that an encrypted version of the file or folder is created that requires a passphrase to unlock it. The original file or folder must then be deleted by the user. Whenever you want to edit or view the file after this, you must double-click the encrypted file to extract a decrypted copy. Then, if you update the file in any way, you must reencrypt it.

Some setup work is necessary before the files or folders can be encrypted, and you must generate a personal key pair.

Files encrypted using the method outlined in this tip aren’t particularly “portable,” which is to say this isn’t a system designed to let you copy files to another machine and decrypt them. For that to happen, you would have to export your key pair, which represents a security risk. Nevertheless, how to do this is explained later in this tip.

Bear in mind that if you follow these instructions to encrypt files and then forget your passphrase, any files you encrypted are effectively lost forever. There is no “back door” and no way of cracking the system—the method of encryption used is extremely thorough.

First we look at creating a key pair and then look at how to encrypt/decrypt files or folders.

Creating a Key Pair

Follow these steps to create a key pair, which is necessary before you can encrypt/password-protect any files (note that you can skip these steps if you’ve already created a key pair for use with email encryption):

  1. Click Applications —> Accessories —> Passwords and Encryption Keys to start the Seahorse application, which is used to manage all encryption keys within Ubuntu.
  2. In the program window that appears, click the New button. In the dialog box that appears, select PGP Key, and click the Continue button.
  3. In the dialog box that appears, fill in the Full Name and Email Address fields (you can leave the Comment field blank). To be frank, the email field is used only if you later publish the public component of the key pair for email encryption purposes. If you don’t intend to do this, then it doesn’t matter what you type. Note that you must type both a forename and surname into the Full Name text field.
  4. In the Advanced key options drop-down list, you can choose a different type of encryption, although the default choice of DSA Elgamal and 2048 bits is considered extremely secure and also flexible enough to meet most needs. Once done, click the Create button.
  5. After this, you’ll be prompted for a passphrase. Essentially, this is the password you will need to decrypt files. It’s important you make the passphrase something hard to guess but also memorable enough so you don’t forget it. The passphrase can include letters, numbers, symbols, and space characters.
  6. After this, the key will be generated. Depending on the speed of your computer, this could take up to an hour. Once it’s done, quit the Seahorse application.

Encrypting/Decrypting Files or Folders

Once the key pair has been created, encrypting a file or folder is as simple as right-clicking it and selecting Encrypt. In the dialog box that appears, put a check alongside the key you created, and then click OK

If you’ve selected to encrypt a folder, you’ll be asked whether you want to encrypt each file separately or automatically create a zip archive that will then be encrypted. The latter is the best option in most cases.

If you password-protected a file, once the encrypting process is complete, you should find yourself with a new version of the file that has a .pgp extension. You can then delete the old file. If you encrypted a folder, you should find two files have been created—the protected .pgp version and a .zip archive of the original folder. That archive, along with the original folder itself, can then be deleted.

For security reasons, the unencrypted versions should be permanently deleted, rather than just sent to the trash. Ideally you should use the shred command too. Before destroying the old file, however, you might want to first test-run decrypting the file.

To do so, just double-click the .pgp file, and then type your passphrase when prompted. The original file will then reappear. In the case of a folder, the .zip archive will appear, and you can then double-click it to extract the contents.

Decrypting Files on Another Computer

As mentioned in the introduction to this tip, this isn’t a system designed to create portable encrypted files. To decrypt files on another computer, you need to export your key pair and then import it on the other computer. Anybody in possession of your key pair file along with any encrypted files will be able to decrypt them, so this represents a security risk. However, sometimes it might be necessary to decrypt files on another machine. Here are the necessary steps:

  1. On the computer that created the encrypted file(s), start Seahorse (Applications —> Accessories —> Passwords and Encryption Keys), and then right-click your personal key (the one created in the previous steps). Select Properties from the menu that appears.
  2. In the dialog box that appears, click the Details tab, and click the Export button alongside the Export Complete Key heading. Save the file to the desktop. You will find a new file has been created with an .asc extension. This is your key pair in text format.
  3. Copy the .asc file to a USB key stick or floppy disk, and take it over to the second computer. Still on the second computer, start Seahorse (Applications —> Accessories —> Passwords and Encryption Keys), and click the Import button. Navigate to your key file, and click Open. This will import the key. After this, close Seahorse. You can then double-click any encrypted files to decrypt them.
  4. If the other computer doesn’t have Seahorse installed—perhaps if it’s a different version of Linux or maybe an older version of Ubuntu—copy the key file to the desktop, and then type the following into a terminal window (these instructions assume gpg is installed, which is very likely):
    gpg --import "/home/username/Desktop/key file.asc"

    Obviously, you should replace key file.asc with the name of the .asc file and replace username with your username.

  5. Then, to decrypt a file, type the following:
    gpg filename.pgp

    Again, you should replace filename.pgp with the name of the file you want to decrypt. You’ll be prompted for your passphrase, so type it. After this, the original file will be restored in the same location as the .pgp file.

Note that you MUST ensure the internal PC clock is set correctly and shows the current time before exporting/importing keys. For various technical reasons, Seahorse and the gpg command cannot import a key if the time on the PC appears to be before the key file appears to have been created. Of course, this means that if the computer that created the key file had the wrong time, you will have real problems importing the key. The solution is to set your PC’s clock to a time and date in the future. Then import the key, and return the PC’s clock to the present time.

8. Use a Dial-Up Modem

Like all Linuxes, Ubuntu has spotty support when it comes to dial-up modems (those used to dial into ISPs over the phone line). Some work. Some don't. Generally speaking, those that work tend to be older models that connect via the serial port or newer, more expensive models that connect via USB (more expensive models have dedicated modem hardware, rather than relying on software drivers to handle the decoding, which is what causes problems for Ubuntu).

If your modem works, you can use the gnome-ppp software to connect/disconnect. It can be installed via Synaptic and, once it’s installed, you'll find it on the Applications —> Internet menu. When running it for the first time, click the Setup button, and then click the Detect button under the Modem heading in the dialog box that appears. Once done, click Close to return to the main dialog box, where you can enter your ISP's username, password, and phone number. Then click Connect to dial up.

When connected, gnome-ppp minimizes to the notification area. Right-click it to disconnect from the call.

9. Switch Monitor Resolutions with a Single Mouse Click

If you have an external monitor or projector you occasionally attach to a notebook computer, you might be used to switching resolutions on a regular basis. Unlike with Windows, this isn’t just a right-click procedure—you must navigate the System —> Preferences menu.

A good solution is to use Synaptic to search for and install resapplet. For some reason, although it’s officially a GNOME applet, resapplet doesn’t appear on the standard applet list. Instead, it must be configured to start at login. To do this, click System —> Preferences —> Sessions, ensure the Startup Programs tab is selected, and click the Add button. In the Name and Command fields of the dialog box that appears, type resapplet. Leave the Comment field blank. Then close the dialog box, and log out and back in again.

The new icon will then appear beside NetworkMonitor in the notification area. Clicking it will reveal a list of possible resolutions from which you can choose.

Incidentally, it should be possible to instantly step up and down resolutions by pressing Ctrl+Alt and tapping the +/- keys on the numeric keypad. Unfortunately, this doesn’t work on Ubuntu systems because of the way the graphical subsystem is configured. It may work on other Linux systems, however.

Continue
We Accept
Quick Find
 
Use keywords to find the product you are looking for.
Advanced Search
0 items
Currencies
Manufacturers


Ubuntu Certified