vi /etc/ssh/sshd_config ) \* ^, a1 v |4 w( a
4 \$ y F- @# j4 R; R! q
1.靽格寥閮 port (舐典銵憭 port)
: m! c' [% V. Z) z6 {; c) gPort <port>
4 @/ T6 m# K% _% u+ p/ ?: }0 Y, Z! Z& C; @. g& L2 M
2.賜孵 ip (拍冽澆蝬脣/憭 IP 敶)0 V* z( N( ?9 Q& w( q
ListenAddress 192.168.1.10' N% A: _ [* v" a$ l5 l6 n( [
+ y1 K; N8 t, i0 |, o! G2 s+ K
3.蝳甇 root 餃4 J3 r7 _4 l N5 S4 |% F2 n
PermitRootLogin no# y3 D& X6 J3 z: x0 W3 Y
蝞∠敹隞亙鈭箏董餃伐 su root嚗拍 sudo 撌乩6 U- f: u# _5 t3 M, r% E4 u
" j0 h9 B; y1 t3 l# S, ?
4.蝳甇V蝙函征撖蝣潛餃7 I9 ?' H( I/ W/ K: J
PermitEmptyPasswords no$ B% `. q/ V. N
+ f5 ^% |! u1 y$ Z( s+ f3 e
5.閮望蝯孵撣唾蝢斤餃+ F5 }' K& O9 u1 `
AllowUsers <user1> <user2> <user3>
0 G, |/ q4 P( `: T- e; V: {9 {& qAllowGroups <group> q/ R% r6 Q2 f, m, ^
DenyUsers *
& H8 |+ u b) Z; ODenyGroups no-ssh* W0 M9 i5 Q: i
寞撖阡嚗撠澆銝撣唾閮嚗憒 Allow 頝 Deny 閰梧蝯 Deny
( E' L1 N# U5 ^/ Y, }% H' C
2 _" V6 C6 f, F0 k2 [3 `3 Z" o6.撱a文蝣潛駁嚗撘瑁翰雿輻 RSA/DSA 撽霅
6 w0 q3 K2 [8 d8 e1 U0 h/ LRSAAuthentication yes
0 |* T0 w5 ^ u, o- G3 Y, Z9 oPubkeyAuthentication yes
; H4 o) ?3 z! A* k# ^AuthorizedKeysFile %h/.ssh/authorized_keys
7 w% e3 |- |$ h' U3 jPasswordAuthentication no
9 s# M' z8 V8 f銝衣Ⅱ靽 user ~/.ssh 甈 700嚗撠閰 user public key 亙 ~/.ssh/authorized_keys 銝准Public key Y孵舀撠 ssh-keygen
% l- I7 I) f1 K" S& X* I7 V6 f7 J, [
9 x2 V5 S0 j3 L C/ }" C7 G7.閮 SSHv2
6 ?) Q5 |$ y2 C. iProtocol 2
) ^) A+ u ?9 ?6 G) m6 | z# s1 O5 L3 B, y% B! A
8.嗥孵雿輻刻蝢斤銝餅雿餃亥綽鋆∩誑 somebody handsomebody 銝臭蝙典蝣潛餃亦箔0 D: a% E) x/ q8 j$ o6 M7 B6 a
Match User somebody,handsomebody; W9 L' F, `9 f) j
PasswordAuthentication no雿輻 TCP wrappers 嗡皞 IP
9 ?& |' k. b1 G |' n% Y# vim /etc/hosts.deny N3 X4 y b* x+ ?) Y7 c) E7 s
sshd: ALL
, l( q1 `" V% e) f; ^! |/ Y# vim /etc/hosts.allow5 W7 @4 c. X- r0 C' ^! j
sshd: 192.168.1 1.2.3.4 # 閮 192.168.1.* 1.2.3.4 蝺 z% I; u$ a; r
T, s6 b- K( E- W9.雿輻 iptables 嗡皞 IP
' E7 R3 W; D4 K. P# iptables -A INPUT -p tcp -m state --state NEW --source 1.2.3.4 --dport 22 -j ACCEPT# _9 p: r1 ~! a+ b7 o* K
# iptables -A INPUT -p tcp --dport 22 -j DROP t' ^( X* D# J' K" k! ^( j
閮剖蝡喟嚗亙璈敺賭摮嚗閬脣 iptables 閮剖$ k- m- k; T) A! H
4 g# x+ V5 ]: ]5 \( u
10.摰* _3 b% \: r. T/ v2 m+ L
雿臭誑雿輻其iptables訾嗅訕SH伐霈嗅其孵蝭批臭誑伐嗡銝賡乓雿臭誑其Y隞颱靘摮銝凋蝙 /second/minute/hour /day
/ H1 J: m m2 s. i3 f2 K3 V0 g蝚砌靘摮嚗憒銝冽嗉撓乩航炊撖蝣潘摰銝找閮勗刻赤SSH嚗璅瘥冽嗅其批芾賢閰虫甈∠駁$ ]& o/ W0 x2 M, x& p7 Q) y/ f
# iptables -A INPUT -p tcp -m state --syn --state NEW --dport 22 -m limit --limit 1/minute --limit-burst 1 -j ACCEPT
: t, h y' K1 D2 U # iptables -A INPUT -p tcp -m state --syn --state NEW --dport 22 -j DROP5 V7 C; U( m2 @& W- K6 ]
蝚砌靘摮嚗閮剔蔭iptables芸閮曹蜓璈193.180.177.13亙訕SH嚗典閰虫甈∪仃駁詨嚗iptables閮梯府銝餅瘥閰虫甈∠駁
! O2 v) m. x% Z+ y3 U # iptables -A INPUT -p tcp -s 193.180.177.13 -m state --syn --state NEW --dport 22 -m limit --limit 1/minute --limit-burst 1 -j ACCEPT
6 U. n2 h' U1 M1 d/ G6 f! y6 R # iptables -A INPUT -p tcp -s 193.180.177.13 -m state --syn --state NEW --dport 22 -j DROP
2 ~* w# l$ Z$ i2 O, O) |
" j& i- {7 G$ H/ w7 g! v. Q11.瑼X亦賊瑼獢甈嚗銝摰典銝閮梁餃
" o6 ]) }. D2 ?9 X2 |, |StrictModes yes8 t& T5 \% c( \' X4 H$ B. K- p3 f
鈭賊瑼獢甈閮剖交航炊嚗航賡摰冽折◢芥憒雿輻刻 ~/.ssh/authorized_keys 甈亦 666嚗航賡嗡鈭箏臭誑典董
: X: R3 q' M7 U- ~4 c3 v5 D& |3 m
12.芾雿輻刻餃交憿舐內 banner (閰梯牧頝摰冽扳隞暻潮靽...? 憭扳臭誑函冗鈭斗孵頝憯鈭箏...= =a)
3 @2 ]4 ?: s8 i S4 S" V2 m4 @- N+ dBanner /etc/ssh/banner # 隞餅摮瑼
& ]- l0 `+ _9 n' X! N
$ Q7 u1 d! {) c5 B/ h% @) L$ y13. su/sudo
$ {+ ]. i# k J/ g! v. G( ] L# vi /etc/pam.d/su1 |' K5 c& Z' s( p
auth required /lib/security/$ISA/pam_wheel.so use_uid
6 z/ ]) R' W: q! {# visudo D: a: L" Y+ N P7 b3 M6 u
%wheel ALL = (ALL) ALL
2 @/ M) Y, b5 G' F) ^# gpasswd -a user1 wheel
4 R0 I: K$ S; h& W9 d; y
" Q3 ^& r7 f" W2 ?! P% n0 h# {; X7 ~14. ssh 雿輻刻* ?. f" k% }# o. f* s/ ^6 u; k
# vi /etc/pam.d/sshd
! j, o9 H: F% W& `! U# [! o auth required pam_listfile.so item=user sense=allow file=/etc/ssh_users onerr=fail
) f/ v3 l; Q0 ]' L# echo <username> >> /etc/ssh_users) c1 f# ]4 H, b# `* ^2 G- P9 o
15.脫迫SSH蝺暹(timeout),霈PuTTY SSH 銝港蝺) A3 \2 m# x8 E' p, u( F8 m
靽格/etc/ssh/sshd_config' b9 `, U" m, n1 P7 J
#TCPKeepAlive yes4 l; R) s+ _+ ?6 {
#ClientAliveInterval 0
& p7 q# q) [( d' e* Z#ClientAliveCountMax 37 w0 ~0 p2 j9 M7 s- G( ~
撠#踵==>摮瑼
! l- A+ j8 z/ n, K#service ssd restart ==>sshd) g/ X7 i$ P; Q3 S: k+ O& q# a' N, }
乩靘靽格 Pietty 賂脣PuTTY 蝺閮剖:
; L2 o$ _" p" N; T 豢Connection殷撠Seconds between keepalives [0 to turn off]喲甈雿頛詨交撟曄嚗喲銝null撠隞乩蝺& ~7 g0 H+ Z6 B# f
9 k. M4 X: v1 G9 j2 o. J
|
|