centos7 在 selinux先 改ssh埠

2021-07-07 06:55:00 字數 869 閱讀 8899

今天新購一vps,裝上centos7,然後就開始折騰之路,先改ssh埠,但是改了ssh埠發現怎麼都連不上,然後google了下,發現是selinux在作怪,但是又不想關閉它,而在網上的資料大部分都是以往的。好了開始折騰之路:

1、安裝semanage

yum -y install policycoreutils-pythoy
2、然後新增埠到selinux(如1234)

注意在這裡可能出現錯誤:如果是vps的話記憶體太小,會直接退出,建議增加swap就可以解決。

semanage port -a

-t ssh_port_t -p tcp 1234

3 、 檢視埠是否開啟

semanage port -l | grep ssh
4、 新增防火牆埠,並開啟

cp /usr/lib/firewalld/services/ssh.xml /etc/firewalld/services/

vi /etc/firewalld/services/ssh.xml

#在fierwalld中開放ssh服務埠:

firewall-cmd --permanent --add-service=ssh

firewall-cmd --reload

5、 在sshd_config 新增埠

vi /etc/ssh/sshd_config#增加port

#重啟sshd

systemctl restart ssh
注意:在重啟完ssh後一定要重新連線ssh防止登陸不上去。

CentOS7關閉防火牆和SELinux

關閉防火牆 臨時關閉防火牆 systemctl stop firewalld 臨時開啟防火牆 systemctl start firewalld 防火牆開機關閉 systemctl disable firewalld 防火牆開機啟動 systemctl enable firewalld 檢視防火牆狀...

CentOS7關閉防火牆和SELinux

臨時關閉防火牆 systemctl stop firewalld臨時開啟防火牆 systemctl start firewalld防火牆開機關閉 systemctl disable firewalld防火牆開機啟動 systemctl enable firewalld檢視防火牆狀態 systemct...

centos7 關閉防火牆和selinux

centos 7.0預設使用的是firewall作為防火牆,使用iptables必須重新設定一下 1 直接關閉防火牆 systemctl stop firewalld.service 停止firewall systemctl disable firewalld.service 禁止firewall開...