评论

收藏

[Linux] Telnet安装与配置

服务系统 服务系统 发布于:2022-09-15 18:35 | 阅读数:542 | 评论:0

# Telnet安装与配置
**本实验基于我在cnaaa.com购买的云服务器CentOS 7.9 系统进行操作演示。**
```
[root@master ~]# cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)
```
### 1 、查询telnet相关服务组件是否已安装
> 查询telnet-server、telnet-client、xinetd等服务组件是否安装。
>
> **查询得知,xinetd、telnet和telnet-server未安装。**
```
[root@master ~]# rpm -qa | grep telnet
[root@master ~]# rpm -qa | grep xinetd
[root@master ~]# yum list | grep telnet
telnet.x86_64        1:0.17-66.el7        updates  
telnet-server.x86_64     1:0.17-66.el7        updates  
[root@master ~]# yum list | grep xinetd
xinetd.x86_64                 2:2.3.15-14.el7      base   
```
> **xinetd 是 Linux 系统的超级守护进程,长期驻存于后台,并监听来自网络的请求,从而启动对应的服务。而 telnet 正是 xinetd 管辖的服务之一。**
### 2、查询YUM源中是否提供telnet相关组件
> 查看一下所配置的YUM源内是否提供了telnet相关的安装包
>
> **yum provides telnet telnet-server xinetd**
```
[root@master ~]# yum list | grep telnet && yum list | grep xinetd
telnet.x86_64         1:0.17-66.el7        updates  
telnet-server.x86_64    1:0.17-66.el7        updates  
xinetd.x86_64         2:2.3.15-14.el7      base   
[root@master ~]# 
```
### 3、安装telnet相关服务组件
> 包含telnet、telnet-server、xinetd服务组件
>
> **yum install -y xinetd telnet telnet-server**
```
# 执行此命令进行安装
yum install -y xinetd telnet telnet-server
```
### 4、查询是否安装完成
> **yum list | grep telnet && yum list | grep xinetd**
```
# 执行此命令查询,带@符号的表示已安装。
[root@master ~]# yum list | grep telnet && yum list | grep xinetd
telnet.x86_64       1:0.17-66.el7        @updates 
telnet-server.x86_64    1:0.17-66.el7        @updates 
xinetd.x86_64       2:2.3.15-14.el7      @base  
# 参考链接:https://www.cnblogs.com/gengbo/p/15913541.html
# 查询所有已安装的软件信息
[root@master ~]# rpm -qa telnet telnet-server xinetd
xinetd-2.3.15-14.el7.x86_64
telnet-server-0.17-66.el7.x86_64
telnet-0.17-66.el7.x86_64
# 显示详细信息
[root@master ~]# rpm -qi telnet-server
Name    : telnet-server
Epoch     : 1
Version   : 0.17
Release   : 66.el7
Architecture: x86_64
Install Date: Tue 22 Feb 2022 11:34:33 AM CST
Group     : System Environment/Daemons
Size    : 56361
License   : BSD
Signature   : RSA/SHA256, Wed 18 Nov 2020 10:20:43 PM CST, Key ID 24c6a8a7f4a80eb5
Source RPM  : telnet-0.17-66.el7.src.rpm
Build Date  : Tue 17 Nov 2020 12:44:28 AM CST
Build Host  : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager  : CentOS BuildSystem 
Vendor    : CentOS
URL     : http://web.archive.org/web/20070819111735/www.hcs.harvard.edu/~dholland/computers/old-netkit.html
Summary   : The server program for the Telnet remote login protocol
Description :
Telnet is a popular protocol for logging into remote systems over the
Internet. The package includes a daemon that supports Telnet remote
logins into the host machine. The daemon is disabled by default.
You may enable the daemon by editing /etc/xinetd.d/telnet

# 显示所有文件列表
[root@master ~]# rpm -ql telnet telnet-server xinetd
/usr/bin/telnet
/usr/share/doc/telnet-0.17
/usr/share/doc/telnet-0.17/README
/usr/share/man/man1/telnet.1.gz
/usr/lib/systemd/system/telnet.socket
/usr/lib/systemd/system/telnet@.service
/usr/sbin/in.telnetd
/usr/share/man/man5/issue.net.5.gz
/usr/share/man/man8/in.telnetd.8.gz
/usr/share/man/man8/telnetd.8.gz
/etc/sysconfig/xinetd
/etc/xinetd.conf
/etc/xinetd.d/chargen-dgram
/etc/xinetd.d/chargen-stream
/etc/xinetd.d/daytime-dgram
/etc/xinetd.d/daytime-stream
/etc/xinetd.d/discard-dgram
/etc/xinetd.d/discard-stream
/etc/xinetd.d/echo-dgram
/etc/xinetd.d/echo-stream
/etc/xinetd.d/tcpmux-server
/etc/xinetd.d/time-dgram
/etc/xinetd.d/time-stream
/usr/lib/systemd/system/xinetd.service
/usr/sbin/xinetd
/usr/share/doc/xinetd-2.3.15
/usr/share/doc/xinetd-2.3.15/CHANGELOG
/usr/share/doc/xinetd-2.3.15/COPYRIGHT
/usr/share/doc/xinetd-2.3.15/README
/usr/share/doc/xinetd-2.3.15/empty.conf
/usr/share/doc/xinetd-2.3.15/sample.conf
/usr/share/man/man5/xinetd.conf.5.gz
/usr/share/man/man5/xinetd.log.5.gz
/usr/share/man/man8/xinetd.8.gz
```
### 5、启动telnet相关服务
> **执行命令,开启服务,并设置开机自启动。**
```
systemctl start telnet.socket xinetd
systemctl enable telnet.socket xinetd
systemctl status telnet.socket xinetd
```
### 6、查看服务监听端口
```
[root@master ~]# netstat -tnl |grep 23 
tcp6     0    0 :::23    :::*          LISTEN   
[root@master ~]# ss -tunpl | grep 23
tcp  LISTEN   0    128  [::]:23   [::]:*      users:(("systemd",pid=1,fd=33))
[root@master ~]# 
```
## Telnet远程连接测试
### 1、创建用户xybdiy
```
[root@master ~]# useradd xybdiy
[root@master ~]# passwd xybdiy
Changing password for user xybdiy.
New password: 
BAD PASSWORD: The password is a palindrome
Retype new password: 
passwd: all authentication tokens updated successfully.
```
### 2、使用xybdiy用户telnet登录
```
telnet 192.168.200.11
Kernel 3.10.0-1160.53.1.el7.x86_64 on an x86_64
master login: xybdiy
Password:
[xybdiy@master ~]$ su -
Password:
Last login: Tue Feb 22 12:39:35 CST 2022 on pts/1
Last failed login: Tue Feb 22 12:52:02 CST 2022 on pts/2
There was 1 failed login attempt since the last successful login.
[root@master ~]#
```
### 3、设置允许ROOT用户Telnet登录
```
# 修改login文件
 vim /etc/pam.d/login
 注释这一行文件
 #account  required   pam_nologin.so
按:wq保存退出。
# 注释掉securetty文件
mv /etc/securetty /etc/securetty.bak
C:\Users\xybdiy>telnet 192.168.200.11
Kernel 3.10.0-1160.53.1.el7.x86_64 on an x86_64
master login: root
Password:
Last failed login: Tue Feb 22 13:59:24 CST 2022 from ::ffff:192.168.200.2 on pts/1
There was 1 failed login attempt since the last successful login.
Last login: Tue Feb 22 13:45:55 on pts/2
[root@master ~]#
[root@master ~]# telnet localhost
Trying ::1...
Connected to localhost.
Escape character is '^]'.
Kernel 3.10.0-1160.53.1.el7.x86_64 on an x86_64
master login: root
Password: 
Last login: Tue Feb 22 14:11:49 from ::ffff:192.168.200.2
[root@master ~]# 
```