Author Topic: เปลี่ยน ssh port ใน Centos 7.x 8.x ทำยังไงบ้าง  (Read 3773 times)

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
เปลี่ยน ssh port ใน Centos 7.x 8.x ทำยังไงบ้าง
« on: พฤศจิกายน 15, 2018, 07:52:32 AM »
เปลี่ยน ssh port ใน Centos 7.x ทำยังไงบ้าง

ถ้าทำการเปลี่ยนที่ configure /etc/ssh/sshd_config เฉยๆ จะไม่สามารถ start ssh ได้ครับ

sshd[4713]: error: Bind to port 2299 on 11.222.1.99 failed: Permission denied.

ใน centos 7.x และ RHES 7.x ต้องทำการปรับ configure ของ selinux + policy ด้วย
โดยลงตัว command
#yum install policycoreutils-python

ทำการเพิ่ม policy โดย
#semanage port -a -t ssh_port_t -p tcp 2299

แล้วทำการ restart ssh daemon 1 ครั้ง
#service sshd restart

#netstat -na | grep 2299

แต่ถ้ามีการใช้งาน firewall-cmd ด้วยก็
#firewall-cmd --add-port 2299/tcp --permanent

เท่านี้ก็เรียบร้อยแล้วครับผม : )  ;)
Support [at] Packetlove.com Team.
« Last Edit: กุมภาพันธ์ 27, 2020, 08:08:48 PM by golfreeze »

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: เปลี่ยน ssh port ใน Centos 7.x ทำยังไงบ้าง
« Reply #1 on: พฤศจิกายน 19, 2018, 12:31:23 PM »
#### ปิด port บน centos 7.x
firewall-cmd --zone=public --remove-port=61616/tcp
firewall-cmd --zone=public --remove-port=9200/tcp
firewall-cmd --zone=public --remove-port=9300/tcp
firewall-cmd --zone=public --remove-port=5601/tcp
firewall-cmd --reload

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: เปลี่ยน ssh port ใน Centos 7.x ทำยังไงบ้าง
« Reply #2 on: กุมภาพันธ์ 27, 2020, 08:08:35 PM »
====centos 8
yum install policycoreutils-python-utils.noarch

หรือ

yum install policycoreutils-python.x86_64
« Last Edit: กรกฎาคม 31, 2020, 07:54:01 PM by golfreeze »

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: เปลี่ยน ssh port ใน Centos 7.x 8.x ทำยังไงบ้าง
« Reply #3 on: เมษายน 05, 2020, 04:06:59 PM »
ถ้าเครื่องไหนใช้งาน csf (configServer and Firewall) ที่ลงมากับ redhat 8 / Debian 8.x
สามารถเข้าไปปรับ TCP_IN ให้ allow port ที่ต้องการได้ครับ

TCP_IN="sshxxx"

#systemctl restart csf

แล้วทำการเปลี่ยน port ssh ใน /etc/ssh/sshd_config

แล้วทำการ reload ssh 1 รอบ
#systemctl reload sshd

เท่านี้ก็หนีการโจมตี แบบ bruteforce ได้ละครับผม  ;)