Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Linux SSH 服務進階配置:修改埠口、禁止 Root 登入、限制使用者存取

編輯:Linux 教學

修改 SSH 埠口

預設埠口 22。編輯 /etc/ssh/sshd_config:

#Port 22
Port 8888

重啟服務:service sshd restart

關閉 Root 遠端登入

編輯 /etc/ssh/sshd_config:

#PermitRootLogin yes
PermitRootLogin no

重啟服務(建議 reboot)。

禁止特定使用者遠端登入

使用 PAM 模組實現白名單機制:

  1. 編輯 /etc/pam.d/sshd,在 #%PAM-1.0 後加入:
    auth required pam_listfile.so item=user sense=allow file=/etc/ssh_users onerr=fail
  2. 允許使用者(如 abc)遠端登入:
    echo abc >> /etc/ssh_users
  3. 禁止使用者遠端登入:從 /etc/ssh_users 移除該使用者,或刪除檔案 rm -rf /etc/ssh_users。

總結

透過修改預設埠口、停用 Root 遠端登入、實施使用者白名單,可大幅提升 SSH 服務安全性,有效防範暴力破解與未授權存取。

Copyright © Windows教程網 All Rights Reserved