ssh远程连接不上linux

远程连接工具是:Xmanager Enterprise 5-->Xshell

linux 发行版本是:CentOS-6.3-x86_64

问题:ssh一直都可以远程连接上linux,一段时间后突然ssh使用原本的IP连接不上linux,发生这种情况时的解决办法

 

1.查看网络配置文件中的IP有没有改变。

先查看IPADDR有没有改变,要是没有被改变,那么继续步骤2;要是发生了改变则将IPADDR改成之前的,然后进行步骤2。

[root@fanycb ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO=none
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="e57636db-84f8-4c15-af74-97d44a107fa2"
HWADDR=00:0C:29:14:5A:57
IPADDR=192.168.1.100
PREFIX=24
GATEWAY=192.168.1.1
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
[root@fanycb ~]# 

2.检查sshd服务的状态以及端口是否正常。

  • 查看sshd的22端口是否处于正常的LISTEN状态,如果正常,则进行步骤3;如果不正常,则重新启动sshd服务,然后进行步骤3;
[root@fanycb ~]# netstat -nlp | grep :22
tcp    0      0 0.0.0.0:22          0.0.0.0:*         LISTEN      2896/sshd           
tcp    0      0 :::22                  :::*           LISTEN      2896/sshd  
[root@fanycb ~]# 
  • 重启sshd服务
[root@fanycb ~]# /etc/init.d/sshd restart
停止 sshd:                                                [确定]
正在启动 sshd:                                            [确定]
[root@fanycb ~]# 

3.检查防火墙是否开启。

如果防火墙是关闭的,则进行步骤4;如果防火墙没有关闭,则 永久性的关闭它,然后进行步骤4。

[root@fanycb ~]# chkconfig iptables off            <====永久关闭防火墙
[root@fanycb ~]# /etc/init.d/iptables status         <====然后确认一下是否关闭了
iptables:未运行防火墙
[root@fanycb ~]# 

4.这点也是很重要的,那就是,检查SELinux是否开启。

查看系统SELinux目前的状态

[root@fanycb ~]# getenforce 
Disabled                         <====这是我系统上SELinux的状态,这是关闭的
[root@fanycb ~]#

如果结果也是"disabled",那么一切的检查就ok了,那就可以连接了

可如果结果是"Enforcing"活着"permissive",说明系统上的SELinux是开启的,需要将它关闭。因为SELinux的开启与关闭和两个重要的配置文件有关,分别是/etc/selinux/config和/boot/grub/menu.lst,所以要关闭SELinux就需要修改这两个文件,方法如下所示:

[root@fanycb ~]# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
#SELINUX=enforcing
SELINUX=disabled                       <====将=号后改为disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 
[root@fanycb ~]# cat /boot/grub/menu.lst
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/sda5
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32-279.el6.x86_64)
 root (hd0,0)
 kernel /vmlinuz-2.6.32-279.el6.x86_64 ro root=UUID=edc1b124-6bc5-4dbe-b2d4-88805da96d4d rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=128M LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhg
b quiet selinux=0                     <====seliux=0 是添加上去的
initrd /initramfs-2.6.32-279.el6.x86_64.img
[root@fanycb ~]#

好了,所有工作都已经做完啦,现在就可以尽情的连接啦。使用愉快 ^_^

 

posted @ 2017-11-16 21:24  樊辰木风  阅读(68564)  评论(2编辑  收藏  举报