遠程訪問安全-SSH
如何才能讓ssh更加安全?
ssh安全性和配置最佳實踐:
* 將root賬戶僅限制為控制台訪問,不允許ssh登錄
# vim /etc/ssh/sshd_config
PermitRootLogin no
# systemctl restart ssh.service
* 配置TCP Wrappers ,對遠程主機進行訪問控制,修改/etc/hosts.deny拒絕所有遠程主機訪問sshd服務,然后修改/etc/hosts.allow僅允許特定主機/網絡段使用sshd服務
# vim /etc/hosts.deny
//sshd 為ssh服務 ALL 為所有地址
sshd: ALL
# vim /etc/hosts.allow
//僅允許192.168.1.x網段訪問
sshd: 192.168.1.
* 在工作站或筆記本電腦上,關閉SSH服務並卸載ssh服務器包,工作站或筆記本沒有做為服務器段來使用,所以把服務器段的ssh卸載,僅保留客戶端的ssh即可。
# systemctl stop ssh.service
# yum -y remove openssh-server
* 通過控制用戶帳號,限制其對ssh的訪問
# vim /etc/ssh/sshd_config
// 在該文件的最后添加以下兩行
AllowUsers admin xiaodong //允許的用戶
DenyUsers xiaohong xiaofang@192.168.5.10 //禁止xiaohong登錄,和禁止xiaofang使用192.168.5.10的ip地址登錄
# systemctl restart ssh.service //重啟ssh服務
* 強制使用SSH Protocol2(版本1不安全):
# vim /etc/ssh/sshd_config
Protocol 2
# systemctl restart ssh.service
* 不支持閑置會話,並配置idle Logout Timeout 間隔:
// 編輯以下兩行
# vim /etc/ssh/sshd_config
ClientAliveInterval 600 // 600為秒,即600秒后無動作就自動斷開連接
ClientAliveCountMax 3
# systemctl restart ssh.service // 重啟ssh服務
* 禁止使用空密碼登錄,設置最大嘗試登錄次數
// 編輯以下三行
# vim /etc/ssh/sshd_config
PermitEmptyPasswords no
PasswordAuthentication yes
MaxAuthTries 6 // 嘗試次數6次
# systemctl restart ssh.service
* 禁用基於主機的身份驗證
# vim /etc/ssh/sshd_config
HostbasedAuthentication no
# systemctl restart ssh.service
* 禁用用戶的 .rhosts 文件
# vim /etc/ssh/sshd_config
IgnoreRhosts yes
# systemctl restart ssh.service
* 限制ssh,將偵聽綁定到指定的可用網絡接口與端口
# vim /etc/ssh/sshd_config
ListenAddress 172.168.8.5
Port 56175 //可以修改ssh的端口
* 始終保持ssh補丁版本最新(可以設置到任務計划中)
# yum update openssh-server openssh openssh-clients -y