CentOS 6.2修改ssh远程连接端口

实现目的:把ssh默认远程连接端口修改为8909方法如下:
 

1、编辑防火墙配置:vi /etc/sysconfig/iptables
防火墙增加新端口8909

-A INPUT -m state --state NEW -m tcp -p tcp --dport 8909 -j ACCEPT
======================================================================
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8909-j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
重启防火墙,使配置生效:
/etc/init.d/iptables restart
service iptables restart
=======================================================================
2、备份ssh端口配置文件
cp /etc/ssh/ssh_config   /etc/ssh/ssh_configbak
cp /etc/ssh/sshd_config  /etc/ssh/sshd_configbak
修改ssh端口为:8909

vi /etc/ssh/sshd_config
在端口#Port 22下面增加Port8909 (把默认的22端口# 去掉)

vi /etc/ssh/ssh_config
在端口#Port 22下面增加Port 8909 (把默认的22端口#去掉)
重启:/etc/init.d/sshd restart
service sshd restart
用8909端口可以正常连接之后,再返回去重复上面的步骤。把22端口禁用了,以后ssh就只能用8909端口连接了!增强了系统的安全性。

本文出自 “linux系统与网络” 博客,谢绝转载!

你可能感兴趣的:(centos,6.2,修改ssh,远程连接端口)