啟用兩個 Dropbear 實例:
22
)允許密碼登入,僅開放給內部網路。2222
)只允許金鑰登入,開放給外部網路。設定 Dropbear 實例:
# 允許密碼登入(內部用)(可能會跟預設的有重複)
uci add dropbear dropbear
uci set dropbear.@dropbear[-1].Port='22'
uci set dropbear.@dropbear[-1].PasswordAuth='on'
uci set dropbear.@dropbear[-1].RootPasswordAuth='on'
uci set dropbear.@dropbear[0].Interface='lan'
# 禁止密碼登入(外部用)
uci add dropbear dropbear
uci set dropbear.@dropbear[-1].Port='2222'
uci set dropbear.@dropbear[-1].PasswordAuth='on'
uci set dropbear.@dropbear[-1].RootPasswordAuth='off'
uci set dropbear.@dropbear[1].Interface='wan'
uci commit dropbear
/etc/init.d/dropbear restart
🔐 Dropbear 支援的設定選項
Dropbear 的 UCI 設定中有兩個相關選項:
`PasswordAuth`:是否允許密碼登入(針對所有使用者)
`RootPasswordAuth`:是否允許 root 使用密碼登入
#正確長這樣 有重複的要刪掉
root@OpenWrt:~# cat /etc/config/dropbear
config dropbear 'main'
option enable '1'
option PasswordAuth 'on'
option RootPasswordAuth 'on'
option Port '22'
option Interface 'lan'
config dropbear
option Port '2222'
option PasswordAuth 'on'
option RootPasswordAuth 'off'
option Interface 'wan'
root@OpenWrt:~#
設定防火牆規則:
22
埠給內部網段(例如 192.168.1.0/24
)。2222
埠給外部網路。# 內部網路允許連接 22 埠
uci add firewall rule
uci set firewall.@rule[-1].name='Allow-SSH-Internal'
uci set firewall.@rule[-1].src='lan'
uci set firewall.@rule[-1].dest_port='22'
uci set firewall.@rule[-1].proto='tcp'
uci set firewall.@rule[-1].target='ACCEPT'
# 外部網路允許連接 2222 埠
uci add firewall rule
uci set firewall.@rule[-1].name='Allow-SSH-External'
uci set firewall.@rule[-1].src='wan'
uci set firewall.@rule[-1].dest_port='2222'
uci set firewall.@rule[-1].proto='tcp'
uci set firewall.@rule[-1].target='ACCEPT'
uci commit firewall
/etc/init.d/firewall restart
網路來源 | SSH 埠 | 使用者 | 密碼登入 | 金鑰登入 |
---|---|---|---|---|
內部網路 | 22 | root / 一般使用者 | ✅ 允許 | ✅ 允許 |
外部網路 | 2222 | 一般使用者 | ✅ 允許 | ✅ 允許 |
外部網路 | 2222 | root | ❌ 禁止 | ✅ 允許 |