[SSH] Sửa lỗi "error: Bind to port xxx on 0.0.0.0 failed: Permission denied." trên CentOS 7

Nếu bạn đang configure port cho SSH, sau đó restart lại sshd mà gặp báo lỗi kiểu như thế này
Job for ssh.service failed because the control process exited with error code. See "systemctl status ssh.service" and "journalctl -xe" for details. Thì hãy chạy lệnh journalctl -xe để xem báo lỗi cụ thể là gì nhé. Giả sử ta đang configure port number là 9999, lúc này báo lỗi sẽ có dạng

Dec 04 22:25:16 localhost sshd[25003]: error: Bind to port 9999 on 0.0.0.0 failed: Permission denied.
Dec 04 22:25:16 localhost sshd[25003]: error: Bind to port 9999 on :: failed: Permission denied.
Dec 04 22:25:16 localhost sshd[25003]: fatal: Cannot bind any address.
Dec 04 22:25:16 localhost systemd[1]: sshd.service: main process exited, code=exited, status=255/n/a
Dec 04 22:25:16 localhost systemd[1]: Failed to start OpenSSH server daemon.
-- Subject: Unit sshd.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit sshd.service has failed.
--
-- The result is failed.


Lỗi này do SSH muốn listen ở port 9999, nhưng thằng SELinux chặn không cho phép. Đơn giản, hãy khai báo SELinux là tui muốn mở port 9999.

Đầu tiên hãy cài semanage - SELinux Policy Management tool bằng lệnh yum install policycoreutils-python

Sau đó ta khai báo port với SELinux bằng lệnh semanage port -a -t ssh_port_t -p tcp 9999. Bạn chỉ cần thay đổi port number để khai báo port tương ứng nhé

Restart lại SSH thôi 👍

Nhận xét

Bài đăng phổ biến từ blog này

Xe buýt và rau muống

Phòng chống dịch "Óc Chó"

Học làm thơ cho ngày đặc biệt