busybox中telnet功能的添加

来源:互联网 发布:react native vue.js 编辑:程序博客网 时间:2024/05/16 04:55


http://www.embedu.org/Column/Column239.htm

使用busybox制作的一个基本根文件系统如何添加telnetd服务呢?

下面把本人的添加过程列出来供大家分享,如有不同意见请不吝赐教!

1、 添加telnet的支持(busybox中配置)

Networking Utilities ---> 
                [*] telnet 
                [*] Pass TERM type to remote host
                [*] Pass USER type to remote host
                [*] telnetd
                [*] Support standalone telnetd (not inetd only)

2、 添加mdev的支持(busybox中配置)

        Linux System Utilities ---> 
                [*] mdev

3、 添加login(busybox中配置)

Login/Password Management Utilities ---> 
        [*] login

4、 修改etc/init.d/rcS添加mdev内容

#!/bin/sh

mount -a
        mkdir /dev/pts
        mount -t devpts devpts /dev/pts
        echo /sbin/mdev>/proc/sys/kernel/hotplug
        mdev -s
        /bin/hostname -F /etc/hostname

5、 创建etc/hostnam,并添加主机名

farsight

6、 在etc下创建文件passwd,group,shadow,创建目录/home

7、 修改etc/fstab为

#device mount-point type options dump fsck order
        proc /proc proc defaults 0 0
        tmpfs /tmp tmpfs defaults 0 0
        sysfs /sys sysfs defaults 0 0
        tmpfs /dev tmpfs defaults 0 0

8、 内核中添加相应的支持

UNIX98_PTYS=y
        DEVPTS_FS=y

9、 使用adduser添加用户

#adduser linux

10、 添加命令行提示符格式,修改/etc/profile添加如下内容

PS1='[\u@\h \W]\# '
        HOSTNAME=`/bin/hostname`
        export USER LOGNAME PS1

11、 启动telnet服务,在/etc/profile下添加如下内容

telnetd

这个时候我们就可以同过telnet client登陆我们的板子了。上面这些步骤有些不是必须的,大家可以根据需求选择。

12、 参考文献

A daemon for the TELNET protocol, allowing you to log onto the host running the daemon. Please keep in mind that the TELNET protocol sends passwords in plain text. If you can't afford the space for an SSH daemon and you trust your network, you may say 'y' here. As a more secure alternative, you should seriously consider installing the very small Dropbear SSH daemon instead:

http://matt.ucc.asn.au/dropbear/dropbear.html 
        Note that for busybox telnetd to work you need several things:
        First of all, your kernel needs:
        UNIX98_PTYS=y
        DEVPTS_FS=y
        Next, you need a /dev/pts directory on your root filesystem:
        $ ls -ld /dev/pts
        drwxr-xr-x 2 root root 0 Sep 23 13:21 /dev/pts/
        Next you need the pseudo terminal master multiplexer /dev/ptmx:
        $ ls -la /dev/ptmx
        crw-rw-rw- 1 root tty 5, 2 Sep 23 13:55 /dev/ptmx
        Any /dev/ttyp[0-9]* files you may have can be removed.
        Next, you need to mount the devpts filesystem on /dev/pts using:
        mount -t devpts devpts /dev/pts
        You need to be sure that Busybox has LOGIN and FEATURE_SUID enabled. And finally, you should make certain that Busybox has been installed setuid root: 
        chown root.root /bin/busybox
        chmod 4755 /bin/busybox with all that done, telnetd _should_ work....

http://blog.donews.com/tmsonhust/archive/2009/03/14/1477052.aspx

8.2      终端登录用户验证功能添加
需要在etc目录下增加passwd、group和shadow(在编译busybox时如果不选择shadow功能将不需要这个文件)3个文件。
生成这3个文件的方法有:
Ø        手动生成,按照格式规范自己编写内容;
Ø        通过busybox提供的工具adderuser自动生成
8.2.1        手动方式
首先我们介绍一下如何手动添加。以增加root用户为例,增加passwd文件,其内容为:
#cat passwd
root:x:0:0:root:/root:/bin/sh
同时,此时要确定root目录已经存在。
passwd一共由7个字段组成,6个冒号将其隔开。它们的含义分别为:
1     用户名
2     是否有加密口令,x表示有,不填表示无,采用MD5、DES加密。
3     用户ID
4     组ID
5     注释字段
6     登录目录
7     所使用的shell程序
增加group文件,其内容为:
#cat group
root:x:0:
Group一共由4个字段组成,3个冒号将其隔开,它们的含义分别为:
1     组名
2     是否有加密口令,同passwd
3     组ID
4     指向各用户名指针的数组
由于busybox默认启动了shadow模式,因此需要增加shadow文件,其内容为:
#cat shadow
root:$1$3jZ93Mwq$oaeef6lWIuThavs8wD0Wh1:0:0:99999:7:::
shadow一共由9个字段组成,8个冒号将其隔开,它们的含义分别为:
1     用户名
2     加密后的口令,若为空,表示该用户不需要口令即可登陆,若为*号,表示该账号被禁用。 上面的表示的是123456加密后的口令。
3     从1970年1月1日至口令最近一次被修改的天数
4     口令在多少天内不能被用户修改
5     口令在多少天后必须被修改(0为没有修改过)
6     口令过期多少天后用户账号被禁止
7     口令在到期多少天内给用户发出警告
8     口令自1970年1月1日被禁止的天数
9     保留域
这里强调一下shadow文件的由来。/etc/passwd文件对系统的所有用户都是可读的,这样的好处是每个用户都知道系统上有哪些用户,但缺点是其他用户的口令容易受到攻击,尤其是当口令较简单时。所以一些linux系统中使用到了影子口令文件shadow,将用户的口令存储在另一个文件/etc/shadow中,该文件只有根用户root可读,大大提高了安全性。
不过,采用这种手动添加文件的方法有一个缺陷,就是如果要为用户设置登陆口令的话,shadow文件中必须填写加密后的口令,而这个加密算法我们又不知道,即使知道,要经过转换后再添加,比较麻烦。此时,不妨试一下第二种方法。
8.2.2        自动方式
自动生成是使用了busybox提供的adduser工具和passwd工具。
在文件系统正常运行起来后,使用adduser命令,使用方法为:
#adduser root
然后就会在etc目录下自动生成passwd 、group和shadow3个文件。但是运行该命令后会打印出如下消息:
passwd:unknown uid 0
这表示不能为该用户设置密码,此时你会发现要passwd命令也无法使用。
解决的办法是,打开passwd文件,其内容为:
root:x:1000:1000:Linux User…:/home/root:/bin/sh
将用户ID和组ID均更改为0
打开group文件,其内容为:
root:x:1000:
同样将组ID改为0
然后,passwd命令就可以正常使用了。这时为root用户设置口令:
#passwd root
根据提示输入密码。其中,root用户登陆后的目录可以手动进行更改。
8.3      telnetd功能添加
busybox默认已经添加了对telnetd和telnet功能的支持,只需要完成一些相关的设置工作就可以启动这2个功能了。
Ø          创建/dev/pts目录
Ø        在/etc/fstab中添加如下信息,挂载devpts文件系统
devpts /dev/pts devpts defaults 0 0
Ø        在/dev目录下增加ptmx设备文件:
#mknod ptmx c 5 2
Ø        在rcS文件中添加如下脚本,启动telnetd
if [ -x /usr/sbin/telnetd ] ;
then
        telnetd&
fi
Ø        在/dev目录下增加null设备文件,否则上述脚本运行时会出错:提示找不到null文件。
#mknod null c 1 3
此时,telnetd功能开机就可以启动了。

原创粉丝点击