ssh服务不能远程时,使用telnet远程登录

在一次工作中,修改了一个服务器的配置,造成了ssh远程无法登陆,此时可以通过telnet登陆上去,以下为主要步骤:

telnet ip ,后边不用加端口。

一、安装telnet

1、检测telnet-server的rpm包是否安装
[root@localhost ~]# rpm -qa telnet-server

若无输入内容,则表示没有安装。出于安全考虑telnet-server.rpm是默认没有安装的,而telnet的客户端是标配。即telnet是默认安装的。

2、若未安装,则安装telnet-server,否则忽略此步骤
[root@localhost ~]#yum install telnet-server

3、检测telnet的rpm包是否安装
[root@localhost ~]# rpm -qa telnet

4、若未安装,则安装telnet,否则忽略此步骤
[root@localhost ~]# yum install telnet

二、重新启动xinetd守护进程

由于telnet服务也是由xinetd守护的,所以安装完telnet-server后,需要重新启动xinetd守护进程

step 5、service xinetd restart(如果启动正常直接跳到step7)


image.png

unit not found 说明xinetd未安装

step 6、yum -y install xinetd (安装xinetd,然后在继续执行step5)

三、测试

查看tcp的23端口是否正常开启

step 7、netstat -tnl |grep 23 (如果无输出说明未正常启动,则step8;否则整个安装过程完成)

如下图所示则表示启动正常:


image.png

step 8、修改 /etc/xinetd.d/telnet 文件,将disable=yes修改为disable=no,并重新执行step5

如果/etc/ xinetd.d/ 该路径下没有telnet文件,则构造一个telnet文件。

telnet文件内容如下:
# default: on
# description: The telnet server serves telnet sessions; it uses \
# unencrypted username/password pairs for authentication.
service telnet
{
        disable = yes
        flags           = REUSE
        socket_type     = stream
        wait            = no
        user            = root
        server          = /usr/sbin/in.telnetd
        log_on_failure  += USERID
}
以上就是在linux上安装telnet命令的整个过程。

以下为需要注意的地方:

防火墙设置:

iptables防火墙会阻止telnet,所以需要在iptables允许,用如下命令
当你启动telnet服务后,你可以用netstat -tunlp命令来查看telnet服务所使用的端口,可以发现有23。使用下面命令开启这些端口:

iptables -I INPUT -p tcp --dport 23 -jACCEPT
iptables -I INPUT -p udp --dport 23 -jACCEPT
service iptables save //保存
service iptables restart //重启防火墙

或者来点狠的!!关闭防火墙!
service iptables stop

允许root用户登录

默认情况下Linux不允许root用户以telnet方式登录Linux主机,若要允许root用户登录可采用以下3中方法:

(1)修改/etc/pam.d/login配置文件

RedHat Linux对于远程登录的限制体现在/etc/pam.d/login文件中,把限制内容注释即可。

[root@vm-rhel root]# cat /etc/pam.d/login
#%PAM-1.0
auth required pam_securetty.so
auth required pam_stack.so service=system-auth
#auth required pam_nologin.so
account required pam_stack.so service=system-auth
password required pam_stack.so service=system-auth
session required pam_stack.so service=system-auth
session optional pam_console.so

(2)移除/etc/securetty文件夹

验证规则设置在/etc/securetty文件中,该文件定义了root用户只能在tty1-tty6的终端上记录,删除该文件或将其改名即可避开验证规则从而实现root用户以telnet方式远程登录Linux主机。

[root@vm-rhel root]# mv /etc/securetty /etc/securetty.bak

(3)先用普通用户登录,然后切换到root用户

[bboss@vm-rhel bboss]$ su root
Password:
[root@vm-rhel bboss]#

【参考】https://blog.csdn.net/doubleqinyan/article/details/80492421
https://blog.csdn.net/shun35/article/details/90701491

你可能感兴趣的:(ssh服务不能远程时,使用telnet远程登录)