在Linux系统上启用Telnet服务
一、前言
二、在CentOS6上的安装及启用
三、在CentOS7上的安装及启用
四、使用telnet客户端远程登录
一、前言
Telnet是一个用来远程连接服务器或者设备执行操作的一个服务。但是由于是使用明文传输,现在基本上已经弃用了。
为什么我这里还要讲这个安装呢?主要是有时候在Linux系统做升级OpenSSH时,为了保险起见,一般都需要先启用Telnet服务,以防止由于OpenSSH升级失败而登录不上服务器或者设备。
转载本站文章请注明出处:黄海兵haibing.org
由于Telnet服务在CentOS6和CentOS7上安装和配置方法都不一样,所以需要分开来写。
转载本站文章请注明出处:haibing.org
二、在CentOS6上的安装及启用
2.1 安装telnet-server
在CentOS6中,telnet服务是由xinetd管理的,没有单独的服务,所以需要一起安装xinetd才行。
注意,在Linux系统中,telnet服务相对应的软件名称是telnet-server,而不是telnet,telnet这个名称只是telnet服务的客户端。
# yum install xinetd telnet-server
转载本站文章请注明出处:黄海兵haibing.org
执行 chkconfig –list,在最后一段会显示由xinetd管理的一些服务。
# chkconfig –list
........ xinetd based services: chargen-dgram: off chargen-stream: off daytime-dgram: off daytime-stream: off discard-dgram: off discard-stream: off echo-dgram: off echo-stream: off rsync: off tcpmux-server: off telnet: off time-dgram: off time-stream: off
可以看到,telnet服务是off的状态。
转载本站文章请注明出处:haibing.org
2.2 配置文件,启用telnet服务
由于是xinetd服务管的,配置文件都在/etc/xinetd.d目录下。
转载本站文章请注明出处:黄海兵haibing.org
修改/etc/xinetd.d/telnet文件,只要把其中的“disable = yes”改为“ disable = no”,就是启用telnet服务了。
# cat /etc/xinetd.d/telnet
# default: on # description: The telnet server serves telnet sessions; it uses \ # unencrypted username/password pairs for authentication. service telnet { flags = REUSE socket_type = stream wait = no user = root server = /usr/sbin/in.telnetd log_on_failure += USERID disable = no }
转载本站文章请注明出处:黄海兵haibing.org
修改完,重启xinetd服务就可以了。
# chkconfig xinted on
# service xinetd restart
2.3 启用root用户登录
默认情况下,telnet不允许root用户登陆,需要做些配置。
转载本站文章请注明出处:haibing.org
在 /etc/securetty 文件最后,多添加一些pts终端入口,就可以以root用户登陆了。
# vim /etc/securetty
...... pts/0 pts/1 pts/2 pts/3 pts/4 pts/5 pts/6 pts/7 pts/8 pts/9
转载本站文章请注明出处:黄海兵haibing.org
2.4 防火墙的设置
为了方便,可以直接关闭防火墙。
# service iptables stop
如果一定要开防火墙的话,可以放行telnet服务的端口23.
# iptables -I INPUT -m state –state NEW -m tcp -p tcp –dport 23 -j ACCEPT
转载本站文章请注明出处:黄海兵haibing.org
三、在CentOS7上的安装及启用
3.1 安装telnet-server
Telnet服务在CentOS7上是单独的一个服务,不用安装xinetd,只要安装telnet-server,然后启动telnet服务就可以了。
转载本站文章请注明出处:haibing.org
# yum install telnet-server
3.2 启动telnet服务
# systemctl enable telnet.socket
# systemctl start telnet.socket
3.3 启用root用户登录
如果要使用root用户登录,也是需要在/etc/securetty文件中添加pts终端入口的,可以参考上面的教程。
转载本站文章请注明出处:haibing.org
3.4 防火墙的设置
为了方便,可以直接关闭防火墙。
# systemctl stop firewalld
转载本站文章请注明出处:黄海兵haibing.org
如果一定要开防火墙的话,可以放行telnet服务的端口23.
#firewall-cmd –permanent –zone=public –add-port=23/tcp //永久
#firewall-cmd –zone=public –add-port=23/tcp //临时
#firewall-cmd –reload
转载本站文章请注明出处:黄海兵haibing.org
四、使用telnet客户端远程登录
要使用telnet客户端,需要先安装telnet客户端软件。
# yum install telnet
telnet命令格式:
telnet 远程服务器IP地址或主机名 远程服务器telnet服务端口
实例:
# telnet 192.168.3.11
Trying 192.168.3.11... Connected to 192.168.3.11. Escape character is '^]'. CentOS release 6.8 (Final) Kernel 2.6.32-642.el6.x86_64 on an x86_64 login: root Password: Last login: Wed Dec 4 08:09:40 from 192.168.1.103