ssh远程链接不上linux

远程链接工具是:Xmanager Enterprise 5-->Xshelllinux

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

问题:ssh一直均可以远程链接上linux,一段时间后忽然ssh使用本来的IP链接不上linux,发生这种状况时的解决办法网络

 

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

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

[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.检查防火墙是否开启。ui

若是防火墙是关闭的,则进行步骤4;若是防火墙没有关闭,则 永久性的关闭它,而后进行步骤4。this

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

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

查看系统SELinux目前的状态rest

[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 ~]#

好了,全部工做都已经作完啦,如今就能够尽情的链接啦。使用愉快 ^_^

相关文章
相关标签/搜索