telnet问题总结及参考汇总

本文总结了telnet使用中遇到的问题,包括mount devpts提示No such device的解决方法,检查telnetd服务状态,以及在嵌入式Linux系统上配置telnet客户端和服务器的步骤,特别提到了Busybox集成的telnetd配置和对UNIX98_PTYS的支持。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1). mount -n -t devpts devpts /dev/pts提示No such device.

原因分析:内核配置中如果UNIX98_PTYS [=n]则会提示此错误。

修改:  

  | Symbol: DEVPTS_MULTIPLE_INSTANCES [=y]                                                                                                                              | 
  | Prompt: Support multiple instances of devpts                                                                                                                        | 
  |   Defined at drivers/char/Kconfig:459                                                                                                                               | 
  |   Depends on: UNIX98_PTYS [=y]                                                                                                                                      | 
  |   Location:                                                                                                                                                         | 
  |     -> Device Drivers                                                                                                                                               | 
  |       -> Character devices                                                                                                                                          | 
  |         -> Unix98 PTY support (UNIX98_PTYS [=y]) 

2). 可以使用mount命令查看devpts是否正确mount.

3).# telnet 127.0.0.1
Entering character mode
Escape character is '^]'.
Connection closed by foreign host

原因:可能是由上一个问题引起的。

4).确认telnetd程序正确启动,可以使用ps命令查看。

 

 

参考文档:

附件1:

Escape character is '^]'. Connection closed by foreign host.

telnet 192.168.2.51

Trying 192.168.2.51...

Connected to 192.168.2.51.

Escape character is '^]'.

Connection closed by foreign host.


用busybox做的ramdisk,内核编译启动后,telnet连接子总是失败,后来找到了原因,原来需要 mknod一下文件节点,在dev下建立pts文件夹,在/etc/init.d/rcS里面加一句

mount n /dev/pts -t devpts

mknod -m 666 /dev/ptmx c 5 2

就行了。附开启telnetd的过程:

第一种方式:通过inetd启动telnetd服务
必须这样设置busybox配置
   Networking Utilities --->
       去掉 [ ]   Support standalone telnetd (not inetd only)
配置/etc/inetd.conf
       [root@RITA ~]# vi /etc/inetd.conf
       telnet stream tcp nowait root /usr/sbin/telnetd telnetd
运行命令:
/usr/sbin/inetd
第二种方式:直接运行telnetd,启动服务
必须这样设置busybox配置:
   Networking Utilities --->   选择 [*]   Support standalone telnetd (not inetd only)运行命令:    /usr/sbin/telnetd可能出现的问题1)客户端登录不,查看/var/log/message,得到如下信息:
cat /var/log/message
Nov 18 10:04:11 RITA daemon.err telnetd[1442]: bind: Address already in use
解决方法:
修改busybox的配置
Networking Utilities --->
       去掉 [ ]   Support standalone telnetd (not inetd only)

cat /var/log/message

2)如果出现如下信息
Nov 18 11:48:50 RITA daemon.err telnetd[1782]: can't find free pty
解决方法一:
修改busybox配置
    Busybox Settings --->
         General Configuration --->
         去掉[ ] Use the devpts filesystem for Unix98 PTYs
解决方法二:
  mkdir /dev/pts
     mount -t devpts devpts /dev/pts //将devpts文件系统加载在/dev/pst
     mknod -m 666 /dev/ptmx c 5 2 //使用telnetd所必须的设备文件节点
    
     修改/etc/securetty,增加如下行:

   # psudo terminals used by telnet

      pts/0

      pts/1

      pts/2

      pts/3

      pts/4

      pts/5

      pts/6

      pts/7

经过述修改后, 客户端应该可以telnet,信息如下:
在192.168.0.1运行telnet:(子ip:192.168.0.100)
在客户端运行命令:
telnet 192.168.0.100 即出现如下登录提示信息:
     Welcome to RITA!
     RITAlogin: root
     Password: 

     [root@RITA ~]#



我的/etc/init.d/rcS内容为:

#! /bin/ash
ifconfig lo  127.0.0.1
mount none /proc -t proc
mount none /sys -t sysfs
ifconfig eth0 192.168.2.51 netmask 255.252.0.0
mount n /dev/pts -t devpts
mknod -m 666 /dev/ptmx c 5 2    #For telnetd 
telnetd
export PS1="Godson2@\w>"
export PATH=/mnt/bin:$PATH
 

附件2:
telnet协议是登陆远程网络主机最简单的方法之一,只是安全性非常低。对target board来说,必须执行telnet监控程序,这样才可以远程登陆到target board。同时,如果想从开发板通过telnet远程登陆其他host,就需要具备telent client。

    在嵌入式Linux系统上的telnet的工具有:
    ·
telnet client
    busybox telnet client。busybox本身就是为嵌入式系统量身打造,其telnet client精简,而且比较好用。

    ·
telnet server
    主要有telnetd和utelnetd。就文件大小而言,utelnetd套件产生的二进制文件比telnetd要小,但是utelnetd不支持 internet super-server.下面先看busybox的telnet功能。client很简单,选择上就可以用了;而telnetd则要相对麻烦一些。

    Telnetd的移植倒不麻烦,busybox已经集成了一个。但是因为开始时配置出现问题,所以费了些时间才算稳定。

(1)busybox的配置

    对Telnetd的配置部分:

Networking Utilities --->

[*]telnetd
[*]  Support standalone telnetd (not inetd only)

    这个地方的配置说明,telnetd可以由inetd来启动,也可以standalone启动。

配置内核
UNIX98_PTYS=y

在/etc/init.d/rcS中加入
mkdir /dev/pts
mount -t devpts devpts /dev/pts

红色部分也可以在/etc/fstab中添加
devpts /dev/pts devpts defaults 0 0

手动添加

首先我们介绍一下如何手动添加。以增加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文件中必须填写加密后的口令,而这个加密算法我们又不知道,即使知道,要经过转换后再添加,比较麻烦。此时,不妨试一下第二种方法。

自动添加
自动生成是使用了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用户登陆后的目录可以手动进行更改。

在rcS文件中添加如下脚本,启动telnetd
if [ -x /usr/sbin/telnetd ] ;
then
        telnetd&
fi
Ø        在/dev目录下增加 null设备文件,否则上述脚本运行时会出错:提示找不到null文件。
#mknod null c 1 3
此时,telnetd功能开机就可以启动了。

参考网址
http://student.youkuaiyun.com/space.php?uid=48851&do=blog&id=11401
http://linux.chinaunix.net/bbs/archiver/?tid-988432.html

执行telnet命令时,连接到远端机后使用“escape”字符可进入telnet命令模式,此模式下用户可以输入telnet能够解释的命令,来控制telnet或设定与telnet相关的参数。默认的“escape” 字符为“Ctrl+]”。用户可以使用set命令修改“escape”字符的默认值。
 
附件3:
Telnet协议是登陆远程网络主机最简单的方法之一,只是安全性非常低。对target board来说,必须执行 telnet监控程序,这样才可以远程登陆到target board。同时,如果想从 开发板通过 telnet远程登陆其他host,就需要具备telent client。
 
    在 嵌入式Linux系统上的 telnet的工具有:
 
    · telnet client
 
    busybox telnet client。busybox本身就是为 嵌入式系统量身打造,其 telnet client精简,而且比较好用。
 
    · telnet server
 
    主要有telnetd和utelnetd。就文件大小而言,utelnetd套件产生的二进制文件比telnetd要小,但是utelnetd不支持internet super-server.下面先看busybox的 telnet功能。client很简单,选择上就可以用了;而telnetd则要相对麻烦一些。
 
    Telnetd的移植倒不麻烦,busybox已经集成了一个。但是因为开始时 配置出现问题,所以费了些时间才算稳定。
 
(1)busybox的 配置
 
    对Telnetd的 配置部分:
 

Networking Utilities --->

 

[*]telnetd

[*]  Support standalone telnetd (not inetd only)

 
    这个地方的 配置说明,telnetd可以由inetd来启动,也可以standalone启动。
 
(2)编译之后,因为telnetd是busybox的一部分,我在编译busybox时采用了动态编译的方法,所以只要把busybox依赖的动态库放到/lib下,就能保证telnetd不会产生找不到动态库的问题。所以在make;make install之后,telnetd算是到了 开发板上。但是仅仅这样还不能让telnetd正常运行。参考 配置telnetd时的help部分:
 

    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....

 
    对Linux内核的 配置而言,默认已经满足。我出现错误主要是在mdev的初始化上,因为对mdev不熟悉,导致在安排文件挂载顺序时不合理,总是提示找不到/dev/pts。对于mdev如何安排顺序,应该看一下文档中的mdev.txt.
 

-------------
 MDEV Primer
-------------

For those of us who know how to use mdev, a primer might seem lame. For
everyone else, mdev is a weird black box that they hear is awesome, but can
't
seem to get their head around how it works. Thus, a primer.

-----------
 Basic Use
-----------

Mdev has two primary uses: initial population and dynamic updates. Both
require sysfs support in the kernel and have it mounted at /sys. For dynamic
updates, you also need to have hotplugging enabled in your kernel.

Here'
s a typical code snippet from the init script:
[1] mount -t sysfs sysfs /sys
[2] echo /bin/mdev > /proc/sys/kernel/hotplug
[3] mdev -s

Of course, a more "full" setup would entail executing this before the previous
code snippet:
[4] mount -t tmpfs mdev /dev
[5] mkdir /dev/pts
[6] mount -t devpts devpts /dev/pts

The simple explanation here is that [1] you need to have /sys mounted before
executing mdev. Then you [2] instruct the kernel to execute /bin/mdev whenever
a device is added or removed so that the device node can be created or
destroyed. Then you [3] seed /dev with all the device nodes that were created
while the system was booting.

For the "full" setup, you want to [4] make sure /dev is a tmpfs filesystem
(assuming you
're running out of flash). Then you want to [5] create the
/dev/pts mount point and finally [6] mount the devpts filesystem on it.

-------------
 MDEV Config (/etc/mdev.conf)
-------------

Mdev has an optional config file for controlling ownership/permissions of
device nodes if your system needs something more than the default root/root
660 permissions.

The file has the format:
        <device regex> <uid>:<gid> <octal permissions>
For example:
        hd[a-z][0-9]* 0:3 660

The config file parsing stops at the first matching line. If no line is
matched, then the default of 0:0 660 is used. To set your own default, simply
create your own total match like so:
        .* 1:1 777

If you also enable support for executing your own commands, then the file has
the format:
        <device regex> <uid>:<gid> <octal permissions> [<@|$|*> <command>]
The special characters have the meaning:
        @ Run after creating the device.
        $ Run before removing the device.
        * Run both after creating and before removing the device.

The command is executed via the system() function (which means you'
re giving a
command to the shell), so make sure you have a shell installed at /bin/sh.

For your convenience, the shell env var $MDEV is set to the device name. So if
the device 'hdc' was matched, MDEV would be set to "hdc".

----------
 FIRMWARE
----------

Some kernel device drivers need to request firmware at runtime in order to
properly initialize a device. Place all such firmware files into the
/lib/firmware/ directory. At runtime, the kernel will invoke mdev with the
filename of the firmware which mdev will load out of /lib/firmware/ and into
the kernel via the sysfs interface. The exact filename is hardcoded in the
kernel, so look there if you need to want to know what to name the file in
userspace.

 
    我修改之后的初始化顺序为:
 

[root@listentec ~]#cat /etc/fstab
proc /proc proc defaults 0 0
mdev /dev tmpfs defaults 0 0

[root@listentec ~]#cat /etc/init.d/rcS
#!/bin/sh
# Initial Environment

# mount /etc/fstab spcified device
/bin/mount -a

# mount devpts in order to use telnetd
/bin/mkdir /dev/pts
/bin/mount -t devpts devpts /dev/pts

# read the busybox docs: mdev.txt
/bin/mount -t sysfs sysfs /sys
/bin/echo /sbin/mdev > /proc/sys/kernel/hotplug
/sbin/mdev -s

# when mdev is mounted, /sys can be umounted
/bin/umount /sys

 
    这样,就没有问题了。
 

[root@listentec ~]#cat /etc/inittab
::sysinit:/etc/init.d/rcS

::respawn:-/bin/login
::restart:/sbin/init

::once:/sbin/telnetd -l /bin/login

::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r
::shutdown:/sbin/swapoff -a

 
    现在只能是单独启动。使用inetd还不行。经过测试,没有问题。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值