10.3 Network Login Through Telnet

The Telnet protocol is one of the simplest ways to log in to a remote network host. Consequently, it's the easiest way to access your target system once it is connected to a network. To enable remote login, your target must run a Telnet daemon. There are two main Telnet daemons available for use in embedded Linux systems, telnetd, which is part of the netkit packages mentioned earlier, and utelnetd, which is maintained by Robert Schwebel of Pengutronix. In terms of size, the binary generated by the utelnetd package is clearly smaller than the one generated by the netkit Telnet package. In addition, utelnetd does not require an internet super-server, while telnetd does. If your system has very limited resources and does not include other network services managed by an internet super-server, use utelnetd.

Though Telnet is a convenient, lightweight communications mechanism for managing your device on a dedicated network, it's not a secure protocol and is, therefore, not fit for use on the Internet. If you need to remotely log in a device that resides on the Internet, use SSH instead. We will discuss SSH in detail in Section 10.4.

10.3.1 netkit-telnetd

As with other netkit packages, netkit-telnet, which contains telnetd, is distributed at ftp://ftp.uk.linux.org/pub/linux/Networking/netkit/ under a BSD license. For my SYSM module, I used netkit-telnet Version 0.17.

Download and extract the netkit-telnet package into your ${PRJROOT}/sysapps directory and move to the package's directory for the rest of the manipulations:

$ cd ${PRJROOT}/sysapps/netkit-telnet-0.17

As in the case of the netkit-base package described earlier, the configure script included in netkit-telnet package attempts to run some test programs. Because these test programs are compiled using the target's compiler, they will fail. To avoid this, edit the configure script and comment out all the lines that attempt to execute test binaries. As earlier, here is an example commented line:

# ./_ _conftest || exit 1;

Once the script has been modified, you are ready to configure and compile the Telnet daemon. To link with glibc, type:

$ CC=arm-linux-gcc ./configure --prefix=${TARGET_PREFIX}
$ touch ${TARGET_PREFIX}/include/termcap.h
$ make -C telnetd

To build with uClibc, type:

$ CC=arm-uclibc-gcc ./configure --prefix=${TARGET_PREFIX}
$ touch ${PREFIX}/uclibc/include/termcap.h
$ make -C telnetd

As you can see, we compile only telnetd. The package also includes the telnet client, but the Makefile for that client doesn't allow cross-compilation. Even if it did, you'll find it better to use the miniature telnet client included in BusyBox. We used touch to create a termcap.h file in the appropriate header directory because telnetd's source files include this header file. We don't need the termcap library, however. The build process requires only the termcap header file to be present, and the file can be empty.

The complete build process for telnetd is fairly short. The resulting binary is quite small. When built with uClibc and stripped, the binary is 30 KB if linked dynamically and 65 KB if linked statically. When built with glibc and stripped, the binary is 30 KB if linked dynamically and 430 KB if linked statically.

Don't use make install, because the Makefile was not properly built for cross-platform development and attempts to use the host's strip command instead of the version we built earlier for the target.

Instead, copy the telnetd binary by hand to your target's root filesystem:

$ cp telnetd/telnetd ${PRJROOT}/rootfs/usr/sbin

You need to have a properly configured copy of either the inetd or xinetd internet super-server that allows Telnet connections to your target. Alternatively, you could edit your target's /etc/inittab to start the Telnet daemon using the -debug option so that it doesn't need to rely on any super-server. However, telnetd wasn't meant to be used this way.

In addition to the C library, telnetd depends on the login routines library (libutil). Hence, do not forget to copy this library to your target's /lib directory if you link telnetd dynamically.

For further information regarding the use of telnetd, have a look at the manpage included in the telnetd directory of the netkit-telnet package, or the manpage installed on your host for your workstation's native telnetd.

10.3.2 utelnetd

The utelnetd package is distributed at http://www.pengutronix.de/software/utelnetd_en.html under the terms of the GPL. utelnetd depends on the C library and can be built using uClibc. For my SYSM module, I used utelnetd 0.1.3.

Download and extract the utelnetd package into your ${PRJROOT}/sysapps directory and move to that package's directory for the rest of the installation:

$ cd ${PRJROOT}/utelnetd-0.1.3

utelnetd does not require any configuration before compilation. To compile the package against glibc, type:

$ CC=arm-linux-gcc make

The compilation time is very short, since the entire daemon is contained in a single source file. The resulting utelnetd binary is around 10 KB in size when linked dynamically with either glibc or uClibc and stripped. When linked statically, the binary is 375 KB if linked against glibc and stripped, and 25 KB if linked against uClibc and stripped.

There are no configuration files required for utelnetd. All you need is to copy the binary to your target's root filesystem and modify the system's initialization to start a copy of utelnetd at startup. Unlike telnetd, utelnetd is standalone and doesn't rely on an internet super-server such as inetd or xinetd. First, copy the file to your target's root filesystem:

$ cp utelnetd ${PRJROOT}/rootfs/usr/sbin

Now, edit your target's /etc/inittab file to start utelnetd at startup. As an example, here is the line I add for utelnetd in my SYSM module's /etc/inittab:


Though there is little documentation on the use of utelnetd, the package is simple enough that a quick glance at the source code should provide you with all the information you need.