Xshell连接centos,修改ssh默认端口号(22)

1、修改/etc/ssh/sshd_config文本,在#Port 22后添加Port 25533,最好选择端口在20000以上的没有用到的端口,防止被轻易破解,如下:

[objc]  view plain  copy
  1. [root@cnt ~]# vi /etc/ssh/sshd_config  
[objc]  view plain  copy
  1. #Port 22  
  2. Port 25533  
  3. #AddressFamily any  
  4. #ListenAddress 0.0.0.0  
  5. #ListenAddress ::  

2、

[objc]  view plain  copy
  1. [root@cnt ~]# vim /etc/sysconfig/iptables  
在/etc/sysconfig/iptables文本中-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT行下添加如下规则:
[objc]  view plain  copy
  1. # Firewall configuration written by system-config-firewall  
  2. # Manual customization of this file is not recommended.  
  3. *filter  
  4. :INPUT ACCEPT [0:0]  
  5. :FORWARD ACCEPT [0:0]  
  6. :OUTPUT ACCEPT [0:0]  
  7. -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT  
  8. -A INPUT -p icmp -j ACCEPT  
  9. -A INPUT -i lo -j ACCEPT  
  10. -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT  
  11. -A INPUT -m state --state NEW -m tcp -p tcp --dport 25533 -j ACCEPT  

这样可以避免因为防火墙造成的无法连接,并且注意添加的红色字体的规则的位置,最好放在这里,避免不清楚防火墙策略语句造成的错误。

3、重启ssh服务:/etc/rc.d/init.d/sshd restart

[objc]  view plain  copy
  1. [root@cnt ~]# /etc/rc.d/init.d/sshd restart  
[objc]  view plain  copy
  1. Stopping sshd:                                             [  OK  ]  
  2. Starting sshd:                                             [  OK  ]  
4、重启防火墙服务:service iptables restart
[objc]  view plain  copy
  1. service iptables restart  

[objc]  view plain  copy
  1. iptables: Setting chains to policy ACCEPT: filter          [  OK  ]  
  2. iptables: Flushing firewall rules:                         [  OK  ]  
  3. iptables: Unloading modules:                               [  OK  ]  
  4. iptables: Applying firewall rules:                         [  OK  ]  

5、最后重新连接Xshell使用新的端口号25533即可。这样就可以安全的修改ssh端口了,避免被别人轻易破解。

转载自:https://blog.csdn.net/fuda_zwd_2015/article/details/76624623

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值