تغییر پورت ssh در سیستم عامل جدید آلمالینوکس 9.5 پرینت

  • آلما لینوکس, almalinux, SELinux, AlmaLinux 9, AlmaLinux OS, تغییر پورت ssh
  • 0

در این آموزش بسیار کاربردی و مهم به سراغ تغییر پورت در سیستم عامل جدید آلمالینوکس آخرین نسخه 9.5 می رویم

دستورات این سیستم عامل بسیار به سیستم عامل سنت او اس شباهت دارد و جایگزین بسیار خوبی برای سیستم های هاستینگ می باشد

در ابتدا باید پورت SSH را در فایروال باز کنیم

سپس این پورت را در SELINUX باز کنیم

و در نهایت در فایل SSHd پورت را تغییر بدهیم

دقت کنید اگر SELINUX فعال باشد که معمولا به صورت پیش فرض فعال است ، باید اونجا هم حتما اضافه بشود

1.) Edit the /etc/ssh/sshd_config file with your preferred text editor.
nano /etc/ssh/sshd_config

2.) Find the line that has "#port 22" and un-comment the line, then change 22 to the port you wish to use.
Change:
#port 22
To:
port 8340

Save the file. (With nano editor, press CTRL + X then Y to overwrite.)

3.) Restart the ssh service:
CentOS/Fedora/RHEL:
systemctl restart sshd or service sshd restart
Ubuntu/Debian:
systemctl restart ssh or service ssh restart

4.) If you use iptables or the standard Linux firewall, add a rule to allow traffic to the new SSH port. (If your firewall is empty, no need.)
Ubuntu/Debian:
ufw allow 8340
CentOS/Fedora:
firewall-cmd --permanent --zone=public --add-port=8340/tcp
firewall-cmd --reload
or
iptables -A INPUT -i eth0 -p tcp --dport 8340 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 8340 -m state --state ESTABLISHED -j ACCEPT

در مراحل بالا کاری به selinux نداشتیم و تنظیمات را در فایل های زیر باید انجام دهید

Step 5: Now check the labeled port for SSH service in SELinux policy

semanage port -l | grep ssh
 

SSH port labeled in SELinux policy

SSH port labeled in SELinux policy

Step 6: Now add another port lable in selinux policy for SSh service. This will enable you to run your SSH service in either 22 or 5353 port number.

semanage port -a -p tcp -t ssh_port_t 5353
 

Step 7: Now restart the SSH service by using systemctl command as below

systemctl restart sshd
 

Service restarted successfully after enabeling the port in selinux policy

Service restarted successfully after enabeling the port in selinux policy

Step 8: To crosscheck the listening port of SSH, after follow the above steps, you can check this using netstat command.

netstat -tunlp | grep ssh
 

Port changed successfully when selinux policy is enabled

Port changed successfully when selinux policy is enabled

 


آیا این پاسخ به شما کمک کرد؟

« برگشت