vi /etc/ssh/sshd_config
0 U. t" \8 G1 z2 L9 L
% \- e1 Q/ |, k7 Z) i/ ]8 k1.靽格寥閮 port (舐典銵憭 port)
, [" C/ L. L+ w- z6 mPort <port>
I' u0 G, Q. u/ B+ ^
. E; }) H# O( l3 b, T2.賜孵 ip (拍冽澆蝬脣/憭 IP 敶)3 L4 I/ ?5 t. g1 p7 U4 L$ Q$ f, |
ListenAddress 192.168.1.101 J8 O5 |2 ?# s6 Z- r% b5 |
N0 a: n! ?" q
3.蝳甇 root 餃+ Q6 A! B7 U0 y5 A2 g$ y- s
PermitRootLogin no
" \' g' _- m, u) E! m o1 g0 u9 t) a蝞∠敹隞亙鈭箏董餃伐 su root嚗拍 sudo 撌乩" ]: Z A/ d4 `7 T; g0 i
( i% ^) O# |# q' S9 G3 p, v6 n& l: f
4.蝳甇V蝙函征撖蝣潛餃) ~- ]4 Z5 b+ j- `4 e5 G
PermitEmptyPasswords no7 i# ]+ K# H' M
3 ~ H8 ? ]9 h i1 d9 j5.閮望蝯孵撣唾蝢斤餃4 k# Z. h" X, w/ @3 ^; C) J
AllowUsers <user1> <user2> <user3>
; V9 w# q$ b3 }: C8 @7 r8 {, I& Q& oAllowGroups <group>. Q% Q+ n6 [4 F/ F1 s4 n
DenyUsers *6 M7 J+ Y# k% n) d2 A8 }
DenyGroups no-ssh& L1 s4 |0 O' N# z" Y
寞撖阡嚗撠澆銝撣唾閮嚗憒 Allow 頝 Deny 閰梧蝯 Deny " E. q A, v. a
( v/ B* `: k. G, H
6.撱a文蝣潛駁嚗撘瑁翰雿輻 RSA/DSA 撽霅
" z; D3 L' J1 Q+ Z% }, q0 |RSAAuthentication yes
1 V7 f. Y5 \* O" pPubkeyAuthentication yes7 Y9 e6 ?$ R+ A3 \3 ?
AuthorizedKeysFile %h/.ssh/authorized_keys
8 V( y* o! x3 {! C8 l* F8 Z/ ~' f1 h4 xPasswordAuthentication no" R6 R, `6 D2 _
銝衣Ⅱ靽 user ~/.ssh 甈 700嚗撠閰 user public key 亙 ~/.ssh/authorized_keys 銝准Public key Y孵舀撠 ssh-keygen% O3 \, d( u4 R6 t
& x5 X0 S( [! H4 b$ `8 \
7.閮 SSHv27 i) i) B, E- u$ n8 K
Protocol 26 `% J2 D/ c/ b( X7 H. G* G
# H( f$ v3 f3 Y( I. A2 I, }8 R6 i8.嗥孵雿輻刻蝢斤銝餅雿餃亥綽鋆∩誑 somebody handsomebody 銝臭蝙典蝣潛餃亦箔, D! P9 _0 ~" ~+ Z% M7 V+ M3 ]6 \, ]
Match User somebody,handsomebody; P3 g& E8 k( c( V+ q
PasswordAuthentication no雿輻 TCP wrappers 嗡皞 IP8 l( _& |* M( E
# vim /etc/hosts.deny
- |' u! j# _' ~; R6 m4 Z: O# Hsshd: ALL2 ~6 Y+ ?6 ~( c6 t Y% y! J+ a$ L$ _7 F
# vim /etc/hosts.allow
5 z- {% E# ?$ u' [2 u" a& C# }/ Lsshd: 192.168.1 1.2.3.4 # 閮 192.168.1.* 1.2.3.4 蝺6 q- o' ]8 l/ z! P, A/ ?+ Z
2 ^. _9 f0 F; u/ F: ~1 Y& k) E$ D" i
9.雿輻 iptables 嗡皞 IP0 k/ ^9 m* ^3 B! f
# iptables -A INPUT -p tcp -m state --state NEW --source 1.2.3.4 --dport 22 -j ACCEPT$ i) v- L% E( V! ]( `* a. t
# iptables -A INPUT -p tcp --dport 22 -j DROP
+ J" @1 {# y, V閮剖蝡喟嚗亙璈敺賭摮嚗閬脣 iptables 閮剖
6 b. ]" S3 c) S D7 e" T$ v5 ], n+ i. v
10.摰
4 q- {* C1 k! r雿臭誑雿輻其iptables訾嗅訕SH伐霈嗅其孵蝭批臭誑伐嗡銝賡乓雿臭誑其Y隞颱靘摮銝凋蝙 /second/minute/hour /day
$ G3 J: S. K1 F# s, M" T9 s蝚砌靘摮嚗憒銝冽嗉撓乩航炊撖蝣潘摰銝找閮勗刻赤SSH嚗璅瘥冽嗅其批芾賢閰虫甈∠駁
2 k6 N6 G! b$ i& r # iptables -A INPUT -p tcp -m state --syn --state NEW --dport 22 -m limit --limit 1/minute --limit-burst 1 -j ACCEPT
$ `5 l& W$ }3 m2 a/ R9 u0 X # iptables -A INPUT -p tcp -m state --syn --state NEW --dport 22 -j DROP0 r0 S& n1 |1 n8 Y1 A$ N
蝚砌靘摮嚗閮剔蔭iptables芸閮曹蜓璈193.180.177.13亙訕SH嚗典閰虫甈∪仃駁詨嚗iptables閮梯府銝餅瘥閰虫甈∠駁, \7 F' G* [3 n& j$ ^ b
# 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- Y' X7 \' N3 G( `
# iptables -A INPUT -p tcp -s 193.180.177.13 -m state --syn --state NEW --dport 22 -j DROP
4 a+ c$ Q* ^) z" |" J. H& h: x: ]4 M3 Q, I' o) ^: w' A
11.瑼X亦賊瑼獢甈嚗銝摰典銝閮梁餃' s; m- u7 T9 A' {4 J8 U) N$ K% }
StrictModes yes1 |# z( D( z9 }8 Q
鈭賊瑼獢甈閮剖交航炊嚗航賡摰冽折◢芥憒雿輻刻 ~/.ssh/authorized_keys 甈亦 666嚗航賡嗡鈭箏臭誑典董
/ q! n! q& ~3 h: }9 N+ _. t. v0 G/ L; O% f; Z- W" }4 A! K
12.芾雿輻刻餃交憿舐內 banner (閰梯牧頝摰冽扳隞暻潮靽...? 憭扳臭誑函冗鈭斗孵頝憯鈭箏...= =a)) Z4 T2 p: R( j! b( k1 Q
Banner /etc/ssh/banner # 隞餅摮瑼$ C, y/ D9 c( f0 T/ N- G; c- |
+ @9 n, I0 @) U# p1 W13. su/sudo
2 Y' w" {( Z) i! i: c/ D5 e# vi /etc/pam.d/su
4 G$ n3 Q$ }- X0 T0 G auth required /lib/security/$ISA/pam_wheel.so use_uid
* r: x# ]9 l* W4 ?# visudo3 I @1 T6 r& q$ s* [: w5 p
%wheel ALL = (ALL) ALL
* {" v3 G1 a) ?4 O9 A0 l. t# gpasswd -a user1 wheel
" _! m5 p5 Z& y7 ^ G; j# z a* B
2 z7 ?% ^! b! N. A1 S14. ssh 雿輻刻
- ?, Z& L; }1 P1 e2 _# vi /etc/pam.d/sshd
: y# x+ d* n! E5 r0 m: \3 C. D+ { auth required pam_listfile.so item=user sense=allow file=/etc/ssh_users onerr=fail
$ }5 d, Z1 o* w0 F' J3 A# echo <username> >> /etc/ssh_users
* z( I3 ]. z0 x0 T s( b# U15.脫迫SSH蝺暹(timeout),霈PuTTY SSH 銝港蝺
o3 G8 h9 f1 V6 l5 J/ _6 j8 f' _ 靽格/etc/ssh/sshd_config
3 t! S0 [' q1 F$ m#TCPKeepAlive yes
& S( I) Y' a+ M9 n! x. }4 [#ClientAliveInterval 00 B3 E, Q/ J/ }: M: \( m. h5 C6 ?
#ClientAliveCountMax 3% l5 U" q4 x/ P6 F. s/ p
撠#踵==>摮瑼9 |9 r/ b4 T' u- z' ?+ `
#service ssd restart ==>sshd
% E" s6 H! T* ^6 j% e 乩靘靽格 Pietty 賂脣PuTTY 蝺閮剖:' K- l! t; I9 g
豢Connection殷撠Seconds between keepalives [0 to turn off]喲甈雿頛詨交撟曄嚗喲銝null撠隞乩蝺& ]. o9 ~$ o# E- t) Y7 D& t3 E2 O
& Q3 P4 L# J# t) F D; X5 ?, [
|
|