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

好了,所有工作都已經做完啦,現在就可以盡情的連接啦。使用愉快 ^_^

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM