嵌入式linux开发,启用busybox的telnetd服务

        Telnet协议是TCP/IP协议族中的一员,是Internet远程登录服务的标准协议和主要方式。它为用户提供了在本地计算机上完成远程主机工作的能力。在终端使用者的电脑上使用telnet程序,用它连接到服务器终端使用者可以在telnet程序中输入命令,这些命令会在服务器上运行,就像直接在服务器的控制台上输入一样。可以在本地就能控制服务器。要开始一个telnet会话,必须输入用户名和密码来登录服务器。Telnet是常用的远程控制Web服务器的方法。

一、启用用户登录

https://blog.csdn.net/weixin_43782998/article/details/121285658

二、busybox

        telnet需要一个交互的登录界面,须要有getty、login和passwd程序。如果没有,无法实现telnet。此三个程序可由busybox生成。

        1、telnet、telnetd

Networking Utilities --->
    [*]  telnet
    [*]    Pass TERM type to remote host
    {*}    Pass USER type to remote host
    [*]  telnetd
    [*]    Support standalone telnetd (not innetd only)
    [*]      Support -w SEC option (inetd wati mode)

2、 inetd

Networking Utilities --->
    [*]  inetd

3、mdev

Linux System Utilities --->
    [*]  mdev
    [*]    Support /etc/mdev.conf
    [*]      Support subdirs/symlinks
    [*]        Support regular expressions substitutions when renaming device
    [*]      Support command executiong at device addition/removal
    [*]    Support loading of firmwares

 

 三、kernel

        修改内核配置,启用Legacy (BSD) PTY support。

Device Drivers --->
    Character devices --->
        -*-  Unix98 PTY support
        []  Support multiple instances of devpts
        [*]  Legacy (BSD) PTY support
        (256)  Maximum number of legacy PTY in use

 四、rootfs

1、/etc/services

        直接拷贝Ubuntu下的对应文件。

2、/etc/inetd.conf

# /etc/inetd.conf:  see inetd(8) for further informations.
#
# Internet server configuration database
#
# If you want to disable an entry so it isn't touched during
# package updates just comment it out with a single '#' character.
#
# <service_name> <sock_type> <proto> <flags> <user> <server_path> <args>
#
#:INTERNAL: Internal services
#echo           stream  tcp     nowait  root    internal
#echo           dgram   udp     wait    root    internal
#chargen        stream  tcp     nowait  root    internal
#chargen        dgram   udp     wait    root    internal
#discard                stream  tcp     nowait  root    internal
#discard                dgram   udp     wait    root    internal
#daytime                stream  tcp     nowait  root    internal
#daytime        dgram   udp     wait    root    internal
#time           stream  tcp     nowait  root    internal
#time           dgram   udp     wait    root    internali

# These are standard services.
#

telnet  stream  tcp     nowait  root    /usr/sbin/telnetd   telnetd -i
tftp    dgram   udp     wait    nobody  /bin/tftpd
ftp     stream  tcp     nowait  root    /usr/sbin/ftpd      bftpd

3、/etc/rc.d/netd

        须追加执行权限。

#!/bin/sh

base=inetd

# See how we were called.
case "$1" in
  start)
                /usr/sbin/$base
        ;;
  stop)
        pid=`/bin/pidof $base`
        if [ -n "$pid" ]; then
                kill -9 $pid
        fi
        ;;
esac

exit 0

4、/etc/hostname

moshui

5、/etc/fstab

proc  /proc      proc    defaults     0      0
none  /var/shm   shm     defaults     0      0
sysfs /sys       sysfs   defaults     0      0
none  /tmp   ramfs     defaults     0      0
none  /mnt   ramfs     defaults     0      0

6、/etc/mdev.conf

sd[a-z][0-9] 0:0 666 @/etc/hotplug/usb/usb_insert
sd[a-z] 0:0 666 $/etc/hotplug/usb/usb_remove
mmcblk[0-9]p[0-9] 0:0 660 @/etc/hotplug/sd/sd_insert
mmcblk[0-9] 0:0 660 $/etc/hotplug/sd/sd_remove

 或 

mmcblk([0-9]+)p([0-9]+) 0:0 660 */sbin/automount.sh $MDEV X${ACTION}
mmcblk([0-9]+)          0:0 660 */sbin/automount.sh $MDEV X${ACTION}
sd([a-z]+)([0-9]+)      0:0 660 */sbin/automount.sh $MDEV X${ACTION}
sd([a-z]+)              0:0 660 */sbin/automount.sh $MDEV X${ACTION}
#mtdblock([0-9]+)        0:0 660 */sbin/automount.sh $MDEV X${ACTION}

 /sbin/automount.sh,须追加执行权限。 

#! /bin/sh

# debugging message
#echo "MDEV=$1 : ACTION=$2 : SUBSYSTEM=$SUBSYSTEM : DEVPATH=$DEVPATH : DEVNAME=$DEVNAME" >> /dev/console

if [ "$1" == "" ]; then
        echo "parameter is none" > /tmp/error.txt
        exit 1
fi

MNT=$1
#if [ $(echo $1 | grep mmcblk) ]; then
#       if [ $(echo $1 | grep p[25]) ]; then
#               MNT=sdcard2
#       else
#               MNT=sdcard
#       fi
#elif [ $(echo $1 | grep sd) ]; then
#       if [ $(echo $1 | grep p[25]) ]; then
#               MNT=nandcard2
#       else
#               MNT=nandcard
#       fi
#fi

# there is no ACTION, it is for initial population
if [ "$2" = "X" ]; then
        mounted=`mount | grep $1 | wc -l`
        if [ $mounted -ge 1 ]; then
                # mounted, assume the ACTION is remove
                #ACT=Xremove
                # only set add for initial population
                ACT=Xadd
        else
                # not mounted, assume the ACTION is add
                ACT=Xadd
        fi
else
        ACT=$2
fi

if [ "$ACT" = "Xremove" ]; then
        # umount the device
        echo "$ACT /mnt/$1" >> /tmp/mdev.log
        if ! umount -l "/mnt/$1"; then
                exit 1
        else
                rm -f "/mnt/$MNT"
                echo "[Umount FS]: /dev/$1 -X-> /mnt/$MNT" > /dev/console
        fi

        if ! rmdir "/mnt/$1"; then
                exit 1
        fi
else
        # mount the device
        mounted=`mount | grep $1 | wc -l`
        #echo "par=$1,mounted=$mounted,MNT=$MNT" > /dev/console
        if [ $mounted -ge 1 ]; then
                #echo "device $1 is already mounted" > /dev/console
                exit 0
        fi

        if ! mkdir -p "/mnt/$1"; then
                exit 1
        fi

        if [ $(echo $1 | grep mtd) ]; then
                if mount -t jffs2 "/dev/$1" "/mnt/$1"; then
                        echo "[Mount JFFS2]: /dev/$1 --> /mnt/$MNT" > /dev/console
                        echo "$ACT /mnt/$1" >> /tmp/mdev.log
                elif mount -t yaffs2 -o"inband-tags" "/dev/$1" "/mnt/$1"; then
                        echo "[Mount YAFFS2]: /dev/$1 --> /mnt/$MNT" > /dev/console
                        echo "$ACT /mnt/$1" >> /tmp/mdev.log
                elif mount -t ubifs "/dev/$1" "/mnt/$1"; then
                        echo "[Mount UBIFS]: /dev/$1 --> /mnt/$MNT" > /dev/console
                        echo "$ACT /mnt/$1" >> /tmp/mdev.log
                else
                        # failed to mount, clean up mountpoint
                        if ! rmdir "/mnt/$1"; then
                                exit 1
                        fi
                fi
        else
                # try vfat only
                if mount -t vfat -o noatime,shortname=mixed,utf8 "/dev/$1" "/mnt/$1"; then
                        ln -s /mnt/$1 /mnt/$MNT
                        echo "[Mount VFAT]: /dev/$1 --> /mnt/$MNT" > /dev/console
                        echo "$ACT /mnt/$1" >> /tmp/mdev.log
                else
                        # failed to mount, clean up mountpoint
                        if ! rmdir "/mnt/$1"; then
                                exit 1
                        fi
                        exit 1
                fi
        fi
fi

7、/etc/init.d/rcS

hostname -F /etc/hostname

echo /sbin/mdev > /proc/sys/kernel/hotplug
/sbin/mdev -s

mkdir -p /dev/pts
mount -t devpts devpts /dev/pts
或
mount -n -t devpts none /dev/pts -o mode=0622

mkdir /dev/pts
mount devpts -t devpts /dev/pts  //加载devpts文件系统

inetd
或
/etc/rc.d/netd start

Guess you like

Origin blog.csdn.net/weixin_43782998/article/details/121285466