Using a Video Projector with Linux

October 20, 2008 1 comment

One of the first problems a user faces is the need to show topics and presentations with the help of a video projector and a laptop running Linux.

For some reason beyond me, Linux newcomers get turned off by the mere mention of a command line. The whole concept of using a console is like alien.

Okay, there are two options: You can try to modify your Xorg.conf file until you mess it up, destroy your computer’s GUI, and get attacked by sharks (Let’s be honest, this is not worth the effort for just a single presentation), or you can go for a fast, secure and temporary on-the-fly screen resizing.

If you chose the second options, keep reading. This was tested on my HP Pavilion dv2000, with a standard VGA port, running Fedora 9 x86_64.

First some easy stuff (OPTIONAL STEP): let’s disable the screensaver and as we want our screen to be ready and visible throughout the presentation.

$ xset s off

Next we have to take care of the external output. The command here is xrandr, which stands for “X Resize And Rotate” and is used to “allow clients to dynamically change X screens, so as to resize, rotate and reflect the root window of a screen“.

On your console type xrandr -v to check if the package is installed (99% chance it is).

$ xrandr -v
Server reports RandR version 1.2

Now, connect the video projector to the laptop. And automagically you should see… nothing, since the screens are not yet configured.

In order to verify it the system recognized the device, lets query the connected screens with the command xrandr -q

$ xrandr -q

You should see something like the following:

LVDS: minimum 320 x 200, current 1280 x 800, maximum 1280 x 800
VGA connected 1920x1440+0+0 (normal left inverted right x axis y axis) 380mm x 285mm

As you can see, there is a device named LVDS which is the “Low-voltage differential signaling” for the laptop panel, and there is also a VGA device which represents our video projector.

Here you can use the same resolution on the laptop screen and the projector or using two different resolutions. The first approach is a little less prone to errors so we are going to use it.

To clone the screen:
$ xrandr --output LVDS --auto --output VGA --auto --same-as LVDS

To extend the screen to the right in the VGA projector:
$ xrandr --output LVDS --auto --output VGA --auto --right-of LVDS

And finally, to turn off projection:
$ xrandr --output VGA --off

This method can also be used with DVI and S-VIDEO cables. Just be sure to type the correct name of the output device as it is showed with the xrandr command.

Categories: Screens Tags: , ,

Path of the Linux Jedi

October 17, 2008 1 comment

If you really want to get your hands on the “dirty job” and become a serious Linux programmer, I really recommend you to read the following book.

It’s called Advanced Linux Programming and is distributed under the GNU General Public License so you’re free to copy, share, and most important: read it.


As the publisher says, this book will help you to:

Develop GNU/Linux software that works the way users expect it to.
Write more sophisticated programs with features such as multiprocessing, multi-threading, interprocess communication, and interaction with hardware devices.
Improve your programs by making them run faster, more reliably, and more securely.
Understand the preculiarities of a GNU/Linux system, including its limitations, special capabilities, and conventions.

If you’re a developer already experienced with programming for the GNU/Linux system, are experienced with another UNIX-like system and are interested in developing GNU/Linux software, or want to make the transition for a non-UNIX environment and are already familiar with the general principles of writing good software, this book is for you. In addition, you will find that this book is equally applicable to C and C++ programming. Even those progamming in other languages will find this book useful since the C language APIs and conventions are the lingua franca of GNU/Linux.

As an advice, you will need a solid grasp of C programming knowledge.

Thruth be told, good luck.

Turn off echo in a terminal

October 13, 2008 4 comments

Imagine you are writing a shell script that requires the user to input confidential information, lets say a password.

The user wont feel comfortable if the password is echoed on the screen like a simple text. If you ever used expect interactive scripting, you know for sure this kind of problem.

Don’t worry, its amazingly easy to perform this trick and stop echoing whatever the user types on the screen.

Simply add the following line to your script:

stty -echo

and you are done. The stty output will go offline. Let’s see an example:

echo Hello

stty -echo
# do what ever you want to do
echo 'I slept with your girlfriend'
stty echo
echo Bye
exit 0;

That’s it! Just remember to put it back to normal with the following command:

stty echo

Also, it would be helpful for you to read the whole man page for stty.

$ man stty

Categories: Shells Tags:

Connection closed by remote host: ssh_exchange_identification

October 9, 2008 1 comment

Often when a process that uses SSH runs in a regular basis, you may get a “Connection closed by remote host” error.

For example, in my case I was using a Nagios based monitor that needed to connect to a group of hosts and, from time to time I got bursts of this error when trying to access the monitored machines.

This is an example of the log file:

10 13:43:02  hoard04 [2]: Protocol error. ssh is complaining, see next
message. #d83bb35 (ssh_common.c 427)
10 13:43:02  hoard04 [2]: ssh_exchange_identification: Connection
closed by remote host

Even though the problem solves automatically by just ingnoring it for a while (really) I prefer to fix the problem rather than the symptoms, so with a little help from google I came up with the right solution.

This problem happens when the server hits the MaxStartups limit in the /etc/ssh/sshd_config file. This value acts as a security measure if for example someone tries to compromise your server with a DoS attack. By default its set to 10 so its relatively easy for SSH to get stuck at 10 connections.

Anyway, to solve the issue you just have to edit the mentioned file and bump the MaxStartups limit to, say 25 or 50 if you need a lot of connections.

Categories: networking, ssh Tags:

Custom Message for SSH logins

October 8, 2008 Leave a comment

If you ever wanted to show a message anytime someone logs to your server through SSH, here you have the how-to:

You will need root access to the server.

Login as root and use your favorite editor to modify the /etc/motd file. For this example I’m using vi.

# vi /etc/motd

Now type in the message you wish all users to see once they login to your server. Lets try something like this:

If you are not an authorized user for this server
or you are a hacker trying to access confidential info, think before you type.
Maybe join the human race and refrain from hacking it?  See
“Schlindler’s List” part where the German commandant is shooting
prisoners in the prsion year “because he can”.  Schlindler tells him
“true power is in not doing evil even though you can.”
You know, no one crushed you under their boot when you were a
baby, although they certainly could have…  With great power comes great responsibility.

OK, Now you’re done editing the file, type Esc to enter command mode and then type :wq to save the changes

Logout from SSH, then log back again and you will see your custom message.

Please note that the message will be displayed AFTER people log in. If you want to show a message BEFORE, you might want to edit your sshd_config file.

Categories: ssh Tags:

Linux Internet Connection Sharing

September 24, 2008 Leave a comment

Iptables is a well known program for its firewall and traffic filtering capabilities. But it also can be used to share our beloved Internet connection. And amazingly it’s relatively easy to setup a shared connection in Linux.

For this example I will be using a Fedora 9 x86_64 system with a wireless Ethernet device named wlan0

First you have to enable IP forwarding. Log in as root and type:

# echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
# /sbin/iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
# /etc/init.d/iptables save

Now a little bit of theory on what the previous commands do.

The first command is mostly self explanatory; it just tells the system to activate the IP forwarding feature.
Next, the iptables command line defines a Routing Table of NAT (Network Address Translation) type which is used to hide (masquerade) an IP address space behind a single IP address in another address space.
Finally, the last command just saves the configuration.

At this point, the configuration is ready and the only thing left is to actually modify the machines network configuration:

Example Router Address:

First Computer (Connected to Internet):

Second Computer:

That’s it, now both computers share the same Internet connection… fast and simple.

Be aware that this is a very simple example of network sharing, not an Enterprise Level solution. There are many alternative ways… more “elegant” and more secure ways to share a connection (proxy servers, SSH encrypted tunnels, etc)… you might want to try different methods and go for the one that fits your needs.

Categories: networking Tags: , ,

Change Windows XP Serial Number

September 6, 2008 4 comments

If you downloaded accidentally purchased a pirated copy of Windows XP and find that you cannot update it, you might have to enter a new valid serial number

You need to edit the Windows registry to do this so its recommended to make a Restore Point just in case you mess the things up.

Be careful though, if you make any error while editing the registry, you can potentially cause Windows to fail or be unable to boot, requiring you to reinstall Windows. Edit the registry at your own risk and always back up the registry before making any changes.

Having said that, lets get started:

Go to Start > Run, type regedit and press Enter

Go to HKey_Local_Machine\Software\Microsoft\WindowsNT\Current Version\WPAEvents

Double click on oobetimer and change at least one digit of this value to deactivate Windows.

Go to Start > Run (again) and type %systemroot%\system32\oobe\msoobe.exe /a

This will bring up the Activate Windows window. Click “Yes, I want to telephone a customer service representative to activate Windows” and then click Next.

Click Change Product Key and enter your downloaded legally purchased serial number for your Windows XP.

Now just click Update, close the window and reboot your computer.

Categories: Windows Tags: