centos下修改ssh服务的默认端口

来源:互联网 发布:为什么淘宝不能买烟 编辑:程序博客网 时间:2024/04/27 18:15

1.修改SSH配置文件vi /etc/ssh/sshd_config,找到#port22,去掉#,将22改为任意大于1024的数字如12345


2.修改iptables

  vi /etc/sysconfig/iptables

  复制22端口ACCEPT规则

  -A INPUT -m state --state NEW -m tcp -p tcp --dport 12345 -j ACCEPT

3.修改 port contexts(关键),需要对context进行修改

  semanage port -a -t ssh_port_t -p tcp 12345

可以使用semanage port -l | grep ssh查看修改后的端口

4.重启SSH服务

  /etc/init.d/sshd restart

  此时SSH服务已经迁移到12345端口

5.使用ssh root@<IPADDR> -p 12345登录

Change SSH port editing ssdh_config file

vi /etc/ssh/sshd_config

For example change to: Port 2323

SELINUX only allow port 22 for ssh. Add new port context 2323. If you have't installed do the following

yum -y install policycoreutils-pythonsemanage port -a -t ssh_port_t -p tcp 2323

Check the port context for ssh

semanage port -l | grep ssh

Restart SSHD service

systemctl restart sshd.service

Add the port to firewall

firewall-cmd --permanent --zone=public --add-port=2323/tcp

Reload firewall

firewall-cmd --reload

Check listening

ss -tnlp|grep ssh

Try connecting again trough ssh

ssh root@<ipaddr> -p 2323



0 0
原创粉丝点击