vi /etc/ssh/sshd_config
( g1 @4 N* U& w3 ~8 h+ m, p
% l0 _1 g* [9 K1 C' R1 o& k1.靽格寥閮 port (舐典銵憭 port)
0 r0 c: M/ Q5 D" m: X4 ?& @Port <port>
; m+ ?" G& k6 T) U5 o Z6 z* Q5 n& r ?9 y5 k& I
2.賜孵 ip (拍冽澆蝬脣/憭 IP 敶)
0 @+ W- h3 @% @" a) T2 LListenAddress 192.168.1.10
9 I* h$ i) p8 t- B2 n- H* F* ?" N6 J T% B: T
3.蝳甇 root 餃
5 g, R$ m2 y7 h8 p. g+ e1 @PermitRootLogin no
4 C: |3 p h) j蝞∠敹隞亙鈭箏董餃伐 su root嚗拍 sudo 撌乩% b- F' a- ` m+ ]* V' X0 M
$ r Q! K4 w1 F8 O z3 A4.蝳甇V蝙函征撖蝣潛餃0 W! z; E) T* q7 x! v
PermitEmptyPasswords no3 ]0 }4 H3 _+ Z' ~* d c
# t: |% V; a; Q3 U5.閮望蝯孵撣唾蝢斤餃
% s8 u! M3 G4 f1 XAllowUsers <user1> <user2> <user3>
% y- Z7 x6 ` D) dAllowGroups <group>. r, h; t6 ?6 E _) [: n* ]
DenyUsers */ i3 @: L6 K" s% m- x$ D
DenyGroups no-ssh& f+ y3 R0 k/ d: ]
寞撖阡嚗撠澆銝撣唾閮嚗憒 Allow 頝 Deny 閰梧蝯 Deny
% L! p% T* F( d) {: I
$ Y R C- ?; `% H/ o$ y+ ^( v6.撱a文蝣潛駁嚗撘瑁翰雿輻 RSA/DSA 撽霅
8 h$ T- f0 ^7 f& H( KRSAAuthentication yes- m0 I: g2 C* z, W3 }3 O5 _
PubkeyAuthentication yes
% [& w, y6 [' _2 ]$ uAuthorizedKeysFile %h/.ssh/authorized_keys4 o' f- ?8 g( W: J& R7 r
PasswordAuthentication no/ Y# P( i& U, n7 Q+ O$ ^- z
銝衣Ⅱ靽 user ~/.ssh 甈 700嚗撠閰 user public key 亙 ~/.ssh/authorized_keys 銝准Public key Y孵舀撠 ssh-keygen
) q6 S( \- v8 x+ r& E, V! w: R
) X! n& j. k+ v N, h& a7.閮 SSHv2
; u2 u1 [, P/ i: j. S- A. |Protocol 2
: B, G# P' T7 r" } t5 G0 p; E1 ?' w# R, R$ `: E& j
8.嗥孵雿輻刻蝢斤銝餅雿餃亥綽鋆∩誑 somebody handsomebody 銝臭蝙典蝣潛餃亦箔
/ R5 {! n! u7 p2 K/ G4 \Match User somebody,handsomebody4 g2 _8 `# x: h
PasswordAuthentication no雿輻 TCP wrappers 嗡皞 IP7 e" \3 B- ]& J6 I( W: K
# vim /etc/hosts.deny( t5 W+ J5 A5 R
sshd: ALL
& z. I: ^) ~0 |' p' B, u4 ?4 y# vim /etc/hosts.allow
3 Z/ B7 K* _; M3 |9 _sshd: 192.168.1 1.2.3.4 # 閮 192.168.1.* 1.2.3.4 蝺
% u$ j9 ?; k9 ^* _. p
! C5 T% k0 d ], `* U3 J3 |9.雿輻 iptables 嗡皞 IP/ m u8 @! i- U& V/ H n
# iptables -A INPUT -p tcp -m state --state NEW --source 1.2.3.4 --dport 22 -j ACCEPT
3 ~! e; C0 ]4 Y' X# iptables -A INPUT -p tcp --dport 22 -j DROP3 C, m2 e% z6 b( v2 j
閮剖蝡喟嚗亙璈敺賭摮嚗閬脣 iptables 閮剖/ l, U" T* U( `$ v- z- i
# T5 j1 T: k9 y- M4 S/ U10.摰
+ ? G. J, q( b& U8 N- k雿臭誑雿輻其iptables訾嗅訕SH伐霈嗅其孵蝭批臭誑伐嗡銝賡乓雿臭誑其Y隞颱靘摮銝凋蝙 /second/minute/hour /day + a" J# I2 B8 o
蝚砌靘摮嚗憒銝冽嗉撓乩航炊撖蝣潘摰銝找閮勗刻赤SSH嚗璅瘥冽嗅其批芾賢閰虫甈∠駁
C3 R( ?1 J7 |& o$ Y8 R& } # iptables -A INPUT -p tcp -m state --syn --state NEW --dport 22 -m limit --limit 1/minute --limit-burst 1 -j ACCEPT
8 j9 A' u8 M9 V1 Z% C+ G # iptables -A INPUT -p tcp -m state --syn --state NEW --dport 22 -j DROP
6 s$ w/ i! y) Y) B7 ^% l$ G" f蝚砌靘摮嚗閮剔蔭iptables芸閮曹蜓璈193.180.177.13亙訕SH嚗典閰虫甈∪仃駁詨嚗iptables閮梯府銝餅瘥閰虫甈∠駁
$ Z% C1 P# i* w0 r% l: _ # 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" ]# I/ L3 s2 A3 X7 u: @: f" i
# iptables -A INPUT -p tcp -s 193.180.177.13 -m state --syn --state NEW --dport 22 -j DROP
) J. ?; e; w* ^1 ?) O- q2 y+ V) {' T8 v# D" G, V
11.瑼X亦賊瑼獢甈嚗銝摰典銝閮梁餃
- B9 Q5 d3 @$ ^StrictModes yes: _; v8 d5 n) f8 p. d j+ I
鈭賊瑼獢甈閮剖交航炊嚗航賡摰冽折◢芥憒雿輻刻 ~/.ssh/authorized_keys 甈亦 666嚗航賡嗡鈭箏臭誑典董
" I- s/ d( P2 S- y, r
- M1 Y1 f/ S) T( Z12.芾雿輻刻餃交憿舐內 banner (閰梯牧頝摰冽扳隞暻潮靽...? 憭扳臭誑函冗鈭斗孵頝憯鈭箏...= =a); l3 g: e- k9 e1 U, t
Banner /etc/ssh/banner # 隞餅摮瑼0 e4 U9 q! E1 N9 v
5 x* o; P6 j8 l$ U0 t( N& E( {13. su/sudo & }% f2 w! @ Q4 ?
# vi /etc/pam.d/su$ G, c0 e% g$ h6 X Z& ]3 y/ F' S
auth required /lib/security/$ISA/pam_wheel.so use_uid
# ^/ c, z3 D8 V" E% t; Z# visudo3 \' k( I3 k! _: e" o% h2 d
%wheel ALL = (ALL) ALL5 v! Y) L5 T, q# f! v6 h" u
# gpasswd -a user1 wheel
+ f, c' @) J; Z8 o5 W; u# q
0 d% S% Z) A; Z. Q( S' c14. ssh 雿輻刻1 A: `9 B' f, d2 t
# vi /etc/pam.d/sshd
$ Y+ Z% b" I1 k4 g- i1 J6 b4 c7 l% b auth required pam_listfile.so item=user sense=allow file=/etc/ssh_users onerr=fail
# k6 c$ m C5 v* K0 i2 G' `1 w# echo <username> >> /etc/ssh_users' i& p1 \+ K& [! s. x8 F V
15.脫迫SSH蝺暹(timeout),霈PuTTY SSH 銝港蝺* J5 ^. C5 ^$ ?
靽格/etc/ssh/sshd_config
. W3 s4 _$ @- ?: ^" a1 l4 @#TCPKeepAlive yes1 O) z& s& P. Y2 P6 W9 W+ A
#ClientAliveInterval 0# B/ Q* p; x# K z+ S" ? a
#ClientAliveCountMax 3
; v* g; P l+ \+ p. N" N% S 撠#踵==>摮瑼
! g7 L) r2 @4 Z2 d) S: z, _#service ssd restart ==>sshd& S* f d2 M' F0 U1 i. |
乩靘靽格 Pietty 賂脣PuTTY 蝺閮剖:7 H4 }* X; d0 _
豢Connection殷撠Seconds between keepalives [0 to turn off]喲甈雿頛詨交撟曄嚗喲銝null撠隞乩蝺
" N M, t8 ~4 `, [: t ]: p
1 ?- F4 x: D! j( c |
|