說明:
CentOS7服務器環境,默認SSH端口爲22,考慮到安全方面問題,欲修改端口爲62231(機器內網IP爲192.168.1.31)python
ssh配置文件和iptables中端口開放配置調整時,原先的先不要移除,顯式的同時打開22和62231端口,待配置完成確認62231端口訪問正常後再逐個移除22端口的配置,防止配置過程當中出現差錯致使服務器訪問不了。linux
[root@localhost ~]# sestatus SELinux status: enabled SELinuxfs mount: /sys/fs/selinux SELinux root directory: /etc/selinux Loaded policy name: targeted Current mode: enforcing Mode from config file: enforcing Policy MLS status: enabled Policy deny_unknown status: allowed Max kernel policy version: 28
[root@localhost ~]# yum -y install semanage [root@localhost ~]# yum provides semanage 已加載插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.cn99.com * extras: mirrors.cn99.com * updates: mirrors.cn99.com base/7/x86_64/filelists_db | 6.9 MB 00:00:11 extras/7/x86_64/filelists_db | 369 kB 00:00:00 updates/7/x86_64/filelists_db | 636 kB 00:00:00 policycoreutils-python-2.5-22.el7.x86_64 : SELinux policy core python utilities 源 :base 匹配來源: 文件名 :/usr/sbin/semanage [root@localhost ~]# yum -y install policycoreutils-python-2.5-22.el7.x86_64
[root@localhost ~]# semanage port -l|grep ssh ssh_port_t tcp 22 [root@localhost ~]# semanage port -a -t ssh_port_t -p tcp 62231 [root@localhost ~]# semanage port -l|grep ssh ssh_port_t tcp 62231, 22
[root@localhost ~]# vi /etc/ssh/sshd_config [root@localhost ~]# systemctl restart sshd
若是使用的是默認的firewall防火牆,則 [root@localhost ~]# firewall-cmd --permanent--add-port=62231/tcp [root@localhost ~]# firewall-cmd --reload [root@localhost ~]# firewall-cmd --permanent--query-port=62231/tcp 我使用的是iptables防火牆 [root@localhost ~]# iptables -I INPUT -p tcp -m state --state NEW --dport 62231 -j ACCEPT [root@localhost ~]# service iptables save [root@localhost ~]# iptables -L -n --line-numbers
[root@localhost ~]# reboot
[root@dev-02 ~]# ssh -p62231 root@192.168.1.31