Redhat7.2下更改sshd默认端口号

本文详细介绍如何在Linux系统中更改SSH默认端口至22000,包括修改sshd_config文件,使用semanage命令通知SELinux,以及在防火墙中添加新端口规则并重启相关服务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

****[root@ocp ~]# vi /etc/ssh/sshd_config

If you want to change the port on a SELinux system, you have to tell

SELinux about this change.

semanage port -a -t ssh_port_t -p tcp #PORTNUMBER

Port 22
Port 22000 #添加需要的端口号
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
[root@ocp ssh]# firewall-cmd --zone=public --add-port=22000/tcp --permanent #添加端口号22000至防火墙,允许此端口号通过防火墙
success
[root@ocp ssh]# firewall-cmd --reload #重新加载防火墙
success
[root@ocp ssh]# systemctl restart firewalld.service #重启防火墙
[root@ocp ssh]# systemctl status firewalld.service #查看防火墙状态
?.firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2018-12-09 10:48:30 CST; 34s ago #active (running) 防火墙开启状态
Main PID: 5684 (firewalld)
CGroup: /system.slice/firewalld.service
?..5684 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
Dec 09 10:48:33 ocp firewalld[5684]: 2018-12-09 10:48:33 ERROR: COMMAND_FAILED: '/sbin/iptables -…n?).
Dec 09 10:48:33 ocp firewalld[5684]: 2018-12-09 10:48:33 ERROR: COMMAND_FAILED: '/sbin/iptables -…n?).
Dec 09 10:48:33 ocp firewalld[5684]: 2018-12-09 10:48:33 ERROR: COMMAND_FAILED: '/sbin/iptables -…n?).
Dec 09 10:48:33 ocp firewalld[5684]: 2018-12-09 10:48:33 ERROR: COMMAND_FAILED: '/sbin/iptables -…ame.
Dec 09 10:48:33 ocp firewalld[5684]: 2018-12-09 10:48:33 ERROR: COMMAND_FAILED: '/sbin/iptables -…ame.
Dec 09 10:48:33 ocp firewalld[5684]: 2018-12-09 10:48:33 ERROR: COMMAND_FAILED: '/sbin/iptables -…n?).
Dec 09 10:48:33 ocp firewalld[5684]: 2018-12-09 10:48:33 ERROR: COMMAND_FAILED: '/sbin/iptables -…n?).
Dec 09 10:48:33 ocp firewalld[5684]: 2018-12-09 10:48:33 ERROR: COMMAND_FAILED: '/sbin/iptables -…n?).
Dec 09 10:48:33 ocp firewalld[5684]: 2018-12-09 10:48:33 ERROR: COMMAND_FAILED: '/sbin/iptables -…n?).
Dec 09 10:48:33 ocp firewalld[5684]: 2018-12-09 10:48:33 ERROR: COMMAND_FAILED: '/sbin/iptables -…n?).
Hint: Some lines were ellipsized, use -l to show in full.
[root@ocp ssh]# semanage port -a -t ssh_port_t -p tcp 22000
[root@ocp ssh]# semanage port -l |grep ssh
ssh_port_t tcp 22000, 22
[root@ocp ssh]# systemctl restart sshd.service #重启shh服务
[root@ocp ssh]# systemctl status sshd.service #查看shh服务状态
?.sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2018-12-09 10:54:58 CST; 15s ago #active (running)ssh服务状态开启状态
Docs: man:sshd(8)
man:sshd_config(5)
Main PID: 6285 (sshd)
CGroup: /system.slice/sshd.service
?..6285 /usr/sbin/sshd -D
Dec 09 10:54:58 ocp systemd[1]: Started OpenSSH server daemon.
Dec 09 10:54:58 ocp systemd[1]: Starting OpenSSH server daemon…
Dec 09 10:54:58 ocp sshd[6285]: Server listening on 0.0.0.0 port 22000.
Dec 09 10:54:58 ocp sshd[6285]: Server listening on :: port 22000.
Dec 09 10:54:58 ocp sshd[6285]: Server listening on 0.0.0.0 port 22.
Dec 09 10:54:58 ocp sshd[6285]: Server listening on :: port 22.****

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值