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.
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.
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.
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!
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.
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):
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.
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:
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.
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):
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:
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.
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.
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.
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.