在SSH服務(wù)端配置中,首要任務(wù)是修改默認(rèn)端口。通過將/etc/ssh/sshd_config
中的Port 22
更改為非標(biāo)準(zhǔn)端口(例如8888),可顯著降低自動(dòng)化掃描攻擊風(fēng)險(xiǎn)。建議配合以下強(qiáng)化設(shè)置:
UseDNS no # 禁用DNS反向解析 MaxAuthTries 3 # 限制單次登錄嘗試次數(shù) PermitRootLogin no # 禁止root直接登錄 PasswordAuthentication no # 強(qiáng)制密鑰認(rèn)證
密鑰認(rèn)證配置建議采用ED25519算法生成密鑰對(duì):ssh-keygen -t ed25519 -C "your@email"
,并將公鑰通過ssh-copy-id -i ~/.ssh/key.pub user@host -p 端口號(hào)
部署到目標(biāo)服務(wù)器。
通過客戶端配置文件~/.ssh/config
實(shí)現(xiàn)快速連接:
Host webserver HostName 192.168.1.100 Port 8888 User admin IdentityFile ~/.ssh/web_ed25519 Compression yes # 啟用數(shù)據(jù)壓縮 ServerAliveInterval 60 # 保持連接活躍
常用高效命令組合:
ssh -L 3306:localhost:3306 webserver
ssh webserver "sudo systemctl restart nginx"
rsync -avzP -e 'ssh -p 8888' /local/path user@host:/remote/path
使用Ansible進(jìn)行批量配置管理,創(chuàng)建ssh_harden.yml
劇本:
hosts: all tasks: name: Update sshd_config lineinfile: path: /etc/ssh/sshd_config regexp: "^{{ item.regex }}$ line: "{{ item.line }} with_items: { regex: '^#Port 22', line: 'Port 8888' } { regex: '^UseDNS', line: 'UseDNS no' } notify: restart sshd
建議配合日志監(jiān)控工具,實(shí)時(shí)分析/var/log/auth.log
中的異常登錄嘗試,并設(shè)置fail2ban自動(dòng)封鎖惡意IP。
通過端口變更、密鑰認(rèn)證和服務(wù)參數(shù)調(diào)優(yōu)的三層防護(hù)體系,結(jié)合客戶端配置優(yōu)化與自動(dòng)化管理工具,可構(gòu)建企業(yè)級(jí)SSH安全防護(hù)架構(gòu)。定期審計(jì)配置文件和監(jiān)控登錄日志,能有效預(yù)防暴力破解和中間人攻擊,確保建站主機(jī)的遠(yuǎn)程管理安全。
2025-03-11
廣州蘇營貿(mào)易有限公司專注海外推廣十年,是谷歌推廣.Facebook廣告核心全球合作伙伴,我們精英化的技術(shù)團(tuán)隊(duì)為企業(yè)提供谷歌海外推廣+外貿(mào)網(wǎng)站建設(shè)+網(wǎng)站維護(hù)運(yùn)營+Google SEO優(yōu)化+社交營銷為您提供一站式海外營銷服務(wù)。
We and selected third parties use cookies or similar technologies for technical purposes and, with your consent, for other purposes as specified in the cookie policy.
You can consent to the use of such technologies by closing this notice, by interacting with any link or button outside of this notice or by continuing to browse otherwise.