Thursday, March 18, 2010

Project: Building An All-Text Linux Workstation - Part 14

In this, our final installment, we will look at the screen terminal multiplexing program.  What the heck is a "terminal multiplexing program?"  I'm glad you asked.

Now that we have installed a bunch of interactive applications on our workstations and SSH to allow remote access, we have a slight problem.  Is it reasonable for an interactive program (like mutt) monopolize our terminal session?  Isn't Linux multi-tasking?  On the graphical desktop, we can have many applications running at once and, by moving the mouse, we can switch from application to application.  Of course, on the console, we can switch virtual terminals to provide multiple sessions and if we are using SSH, remotely accessing our workstation from a graphical desktop, we can open multiple terminal windows.

But there's another way.  The screen program allows multiple sessions inside a single terminal.  You can create any number of sessions and can even split screens to view two sessions at once.  Further (and this is the cool part), screen allows you to "detach" a session from a terminal and later re-attach the session to a different terminal.

Installing And Running screen

By this time, we all know the drill:

me@linuxbox:~$ sudo apt-get install screen

will install the screen package.  To run screen, we type screen at the prompt followed optionally by the name of a program we want to execute in the screen session.  If no program is specified, screen launches a shell.  Try this:

me@linuxbox:~$ screen top

After you run this command, top will execute and everything will appear normal.  However screen is now managing the terminal session.  screen recognizes a large number of commands.  You communicate with screen by pressing Ctrl-a followed by a command letter.  For example, to create another session type Ctrl-a c and a new shell prompt will appear.  There are now two sessions running in the same terminal.  We can cycle through the sessions by repeatedly typing Ctrl-a n (for next).

Listing Your Sessions

The Ctrl-a " command displays a list of your screen sessions:




From here you can use your up and down arrow keys to select a session to display.

Scrolling And Copying

If you are using screen on a terminal session displayed in a graphical terminal, you will notice that the normal scrolling mechanism no longer works.  This makes sense because if it did, your graphical terminal's scroll back buffer would contain the jumbled contents of all of the screen terminal sessions.  screen manages its own scroll back buffers, one for each screen session.  To access the scroll back buffer (which is called "copy mode" in the screen documentation), type: Ctrl-a [ and you will be able to use up arrow, PgUp, etc to navigate the buffer.  In this mode (which uses many of the vi keyboard sequences) you can copy text for later pasting.  You do this by marking text.  To mark text, you position the cursor  at the beginning of the text you want to copy and press the space bar, then move the cursor to the end of the text you want to copy and press the space bar again.  The marked region is copied into a paste buffer and screen exits copy mode.  To paste the copied text, type the screen command: Ctrl-a ]

Detaching And Reattaching Sessions

By far, the coolest feature of screen is its ability to detach and reattach terminal sessions.  Picture this scenario: you're at work and you have just started a long running job on your work computer in a terminal.  With screen, you can detach the session, log off, go home, reconnect with the your work computer, then reattach the still-running job to your new terminal session.

Here is a demonstration (assuming we have another computer besides our workstation, if not, you can use two virtual terminals on the workstation):

  1. Start screen on the workstation and create a few sessions and put applications in them.  Try top, mutt, and irssi, for example.
  2. After the applications are running, move over to your second computer and log into the workstation using SSH.
  3. On the second computer, enter the command screen -D -R into the remote SSH session.
  4. Poof!  All the screen sessions on the workstation are detached, you are logged off of the workstation console, and all of the sessions are reattached to the terminal running the SSH client on the second computer.  Pretty slick!

We've only touched on the capabilities of screen.  It has many commands and a configuration file that can be used to adjust many of its features.  See the links below for more detail.

In Conclusion

I hope you have enjoyed this series and that you continue to learn about the applications and techniques that we have covered.  While we created a workstation that did not have a windowing system, the programs we installed work just fine on graphical workstations too.  The text-based capabilities of Linux should never be overlooked.  Text-based applications are almost always faster and much less resource-intensive than their graphical counterparts, so they make great additions to you solutions toolbox.

Further Reading

The official GNU screen site and documentation:

A screen tutorial from the Debian project:

A quick reference guide to screen (this site also contains a lot of other well-written screen documentation):
Other installments in this series: 1 2 3 4 5 6 7 8 9 10 11 12 13 14

Tuesday, March 16, 2010

Project: Getting Ready For Ubuntu 10.04 - Part 2

Last time, we announced our intention to upgrade some of our systems to Ubuntu 10.04, so what's next?  To paraphrase a sight gag from an early episode of South Park:


In this installment we are going to cover the planning phase of the upgrade process.  Good planning is often the difference between a good upgrade experience experience and a bad one.  As a computing environment becomes more complex, planning becomes more essential.  My environment is fairly complex so I have to plan.

Objective

The first element to any good plan (and not just for OS upgrades) is a clear objective.  That is, in the broadest terms,  what do we hope to accomplish?  In my case, I want to install Ubuntu 10.04 on two computers (my main desktop system and my laptop) currently running Ubuntu 8.04 while maintaining all of the application set (and capabilities), network integration, and user data.

Notice that I said install and not upgrade.  I have learned through many years of experience that upgrades don't really work.  They kind of work sometimes, but they never really work.  Often, an OS upgrade is not able to apply every new feature in the new version.  For example, converting an existing file system to a new file system type is often impossible.  Also, I don't want to reuse my existing configuration and settings files.  I want to reconfigure based on the new default configuration, again to take advantage of everything the new release has to offer.

I know (from scanning the forums) that a lot of people are content to just pop in an installation CD and push the upgrade button and hope for the best.  Then those same people start crying because they get a black screen when they reboot, or their wireless stops working, or their sound is busted, etc., etc., etc.

System Survey

Since our objective states that we have to maintain the application set, network integration and user data, we better figure out what that is.  We do that by performing an inventory of our existing system  Here are some things to keep an eye on:

  • Required Applications.  When performing your system survey, go through the application menus and list everything you rely on.  In an upcoming installment we will write a script that will prepare a package list to compare against the new installation to ensure that we reinstall all the apps that we care about.  If you use Firefox, pay special attention to bookmarks, stored passwords, and add-ons.
  • Network Services.  My workstations mount file systems on NFSv4 and Samba shares.  I also use an LDAP database to manage my address book.
  • Hardware Features.  We will want to make sure that all of our hardware is working.  During the testing phase we will cover video, sound, wired and wireless networking, CD/DVD reading and writing, printing, scanners/cameras, and USB devices

This is also a good time to do some system maintenance.  Between cleanings, computers get a lot of application and data buildup.  I have added many applications to my base system, some of which I use and others which I don't.  It's good to make a list and decide what you really want on your "new" computer and what you can live without.  The same goes for data.  Do you really need all those video files?  See if you can clear a few gigabytes off that disk.  It will make things easier later.

Testing

We're going to get involved with Ubuntu 10.04 starting with the Beta 1 release scheduled for release on March 18.  I have a test computer prepared where I will attempt to build approximations of the finished systems.  In doing so, I will be able to see what, if anything, blocks my desired configuration.  It also provides a chance to look at the new features in this release, as well as alternate applications.  We will also use live CDs to test the hardware support on the real systems.

Installation

Once the final release of Ubuntu 10.04 occurs on or about April 29, we should be ready to install.  We'll make our installation media, create and verify our final system backup, perform the installation, and restore any additional applications.

Configuration

The final phase of the project is adjusting the configuration of the new system to our liking.  This will involve recreating accounts and application settings.   We will also restore the user data from our backups.

After everything is restored and configured we will verify that everything is in order.  The very last step is to re-enable the system backups and begin using the systems for production use.

Further Reading

Other installments in this series: 1 2 3 4 4a 5

Thursday, March 11, 2010

Project: Building An All-Text Linux Workstation - Part 13

Don't touch that dial!  Even the most die hard GUI fans among you will enjoy this.

You may have noticed that throughout this series, I have posted screen shots of the applications used on our all-text Linux workstation; screen shots that obviously are taken from a graphical desktop, so what gives?  Am I lying about this being an all-text workstation?  Not at all.  I do take the screen shots on a graphical desktop.  How?  By logging in to the workstation remotely from another computer.

One of the great joys of Unix-like operating systems (such as Linux) is the way they work with networks.  Much of the Internet's technology was developed on Unix systems and it shows.  Ever wonder why URLs use forward slashes?  Unix pathnames!

Back in the early days of my Unix career (the mid-1990s), there was a idea going around (foisted by the marketing people at Microsoft) that the newly introduced Windows NT was going to rapidly "kill" Unix.  Real Unix people knew this to be patent nonsense (though many of their pointy-haired bosses did not) because NT lacked an essential feature.  It didn't support remote administration.  I remember system admins complaining bitterly about how to fix even simple problems on NT, they had to travel to the machine and work the graphical interface personally.  Meanwhile, my team and I were managing a national network consisting of hundreds of Unix workstations and servers from our little office.  The only time we ever had to travel to a site was to replace hardware.

Over the years, there have been several Unix technologies used to perform remote administration.  Today, the overwhelming favorite is SSH (Secure SHell).  SSH allows the creation of a secure encrypted tunnel between machines through which can flow any number of network protocols.  It's most common use however is simple command line access to a remote system.

It works like this: a local machine runs a SSH client program that talks to a remote machine running a SSH server.  Every Linux system I have ever used comes equipped with a SSH client but most distributions do not install the server by default.  This is unfortunate since almost every system can benefit from remote administration.

Installing The OpenSSH Server

The most popular SSH implementation in the Linux world comes from the OpenBSD project.  It's called OpenSSH.  It is usually broken into two packages: the openssh-client package and the openssh-server package.  The client package is usually installed by default but we will need to install the server package on our workstation.  We can do this with the following command:

me@linuxbox:~$ sudo apt-get install openssh-server

That's all there is to it.  After the package installs, the service will start and our workstation can now be remotely accessed.  To demonstrate, we will open a terminal window on another machine on our network and use the SSH client program (called ssh) to log into our workstation:

bshotts@twin2:~$ ssh me@linuxbox
The authenticity of host 'linuxbox (192.168.1.7)' can't be established.
RSA key fingerprint is bf:bb:0e:9b:af:a1:dd:e0:b6:44:48:79:97:2f:34:97.
Are you sure you want to continue connecting (yes/no)? yes

The ssh program is invoked with this syntax:

ssh [user@]hostname

where user is an optional user name and hostname is the network name (or IP address) of the machine we want to connect with.  If the user name is omitted, ssh defaults to the name you are currently using on the local system.

The first time you connect with a remote system, ssh warns you that it has never seen this remote machine before.  One of the security features of SSH is that it authenticates the remote systems you talk to.  This ensures that the machine you are talking to really is the machine you think it is.

After answering "yes" to the prompt, ssh adds the remote system to its list of remote hosts that it will recognize in future sessions:

Warning: Permanently added 'linuxbox' (RSA) to the list of known hosts.

Finally, it prompts you for the user's password on the remote system. 

me@linuxbox's password:


Once that is entered, you are logged in!



From here, you can use any of the applications on the workstation just as if you were sitting in front of the workstation's console.

To end a SSH session, use the exit command:

me@linuxbox"~$ exit
Connection to linuxbox closed.
bshotts@twin2:~$

Executing A Single Command On A Remote System

We can also use the ssh program to remotely execute a single command on our workstation.  For example, we could ask our workstation about its uptime and load:

bshotts@twin2:~$ ssh me@linuxbox uptime
me@linuxbox's password:
 13:58:39 up 2 min,  0 users,  load average: 0.10, 0.14, 0.06
bshotts@twin2:~$

If a command follows the hostname, ssh will execute the command on the remote system and the command's output is transferred to the local machine for display.

Copying Files Using SSH

In addition to the ssh program, the openssh-client package also provides two additional programs used for securely copying files to and from remote systems.  The first is scp (secure copy) which is used much like the regular cp command.  To copy a file named somefile.txt to the home directory of user me on the workstation, we would do this.

bshotts@twin2:~$ scp somefile.txt me@linuxbox:
me@linuxbox's password:
somefile.txt                                  100%   10     0.0KB/s   00:00

To place the file in a specific directory (and/or rename the file) on the remote system, follow the hostname with the pathname of the desired destination:

bshotts@twin2:~$ scp somefile.txt me@linuxbox:/user/local/share/shared_file.txt

The second file copying program is sftp (secure ftp) which is a version of the ftp program that uses SSH for transport.  Remember, the ordinary ftp program sends all of its data over the network unencrypted (including user names and passwords), making it unsuitable for use over the Internet.

Using The GUI With OpenSSH

The sftp protocol makes another feature possible.  Most graphical file managers support it.  From our graphical desktop we can move files to and from the remote workstation.  Here's how:

In GNOME, we go to Places -> Connect to Server...  and fill out the dialog as follows:





We will next be prompted for the password on the remote workstation:




After that, voila!  We're browsing the file system on the remote workstation:




Adding Additional Users

With the ability to remotely connect to our workstation, it would make sense to add some user accounts.  This way, more than one person can be using the workstation at the same time.  To add a user account for an imaginary user named "user1", we would do this:

me@linuxbox:~$ su -
Password:
linuxbox:~# adduser user1
Adding user `user1' ...
Adding new group `user1' (1001) ...
Adding new user `user1' (1001) with group `user1' ...
Creating home directory `/home/user1' ...
Copying files from `/etc/skel' ...

Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

Changing the user information for user1

Enter the new value, or press ENTER for the default
        Full Name []: Workstation User 1
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n] Y

linuxbox:~# exit

logout
me@linuxbox:~$

Now user1 can log in to the workstation with the command:

ssh user1@linuxbox



Deleting A User Account

This command will remove the above user account, if desired:

deluser --remove-home user1

Invite Your Friends!

Next time you have your Linux buddies over with their laptops, surprise them with individual user accounts on your awesomely configured all-text workstation.  You'll be the hit of the party!

Further Reading

The man pages for ssh, scp, sftp

SSH is covered in The Linux Command Line (Chapter 17):

OpenSSH:

Windows users need not feel left out.  PuTTY is a popular SSH client for Windows:
Other installments in this series: 1 2 3 4 5 6 7 8 9 10 11 12 13 14

Wednesday, March 10, 2010

Tuesday, March 9, 2010

Project: Getting Ready For Ubuntu 10.04 - Part 1

As you have probably heard, the next release of Ubuntu, 10.04 ("Lucid Lynx") will occur during the final days of April 2010.  My production systems (the ones on which I do my writing and photography) are running Ubuntu 8.04 and I have decided to upgrade them to the upcoming version.  This is the first of five-part series that will document my transition to the new version.

The 10.04 version, like the earlier 8.04 and 6.06 releases, is a so-called LTS or Long Term Support version of Ubuntu.  This means that it receives security and bug fixes (but not application version upgrades) for a period of three years.  This differs from the usual eighteen month support period for ordinary Ubuntu releases.  I have used the LTS versions for several years and feel that it is the best choice for my production systems.  I use a lot of Linux distros in my work, but for the machines I must rely on, I choose stability over the latest features.  For example, my server systems are running CentOS 4 which first appeared in early 2005 and is still supported by Red Hat and the CentOS team.  In fact, the main reason I switched from Red Hat (Fedora) to Ubuntu for my desktop systems was the availability of the Long Term Support versions, a feature that Fedora does not offer.

The Opportunity

In a past life, I ran the QA department of a software company and I often employ these skills to perform software testing on new Linux releases.  This case will be no different.  The first beta release of 10.04 is scheduled for March 18 so we will begin our work then.  Testing is not just something I do for fun (it isn't) but it's important to look for problems that might interfere with the deployment.  By checking for problems now, we have a better chance of getting them fixed before the final release.

The Mission

Our mission is to upgrade the production systems while preserving the existing data and functionality of the current systems.  We'll also look for exciting new features and applications that will enhance their productive capacity.  We will probably do a little scripting and system administration along the way, too :-)

The Players

The two production systems involved are my Dell Inspiron 530N (which originally shipped with Ubuntu 8.04 factory installed) and my IBM ThinkPad T41 laptop.  We'll also use my main test computer, a Dell Dimension 2400N which is currently hosting our All-Text Linux Workstation.  We might also take a look at the 10.04 Netbook Remix version to see if it offers any compelling reasons for upgrading my two netbooks, which are now running 9.04 UNR.

Stay tuned.  This ought to be fun.

Further Reading

Other installments in this series: 1 2 3 4 4a 5