vi /etc/ssh/sshd_config 6 h7 T7 i$ m7 P8 E1 L3 ~' c
1 U- E1 a# c. o7 B6 L+ s( `1.靽格寥閮 port (舐典銵憭 port)
* ]; Q6 j0 r$ Z6 @/ ?" w; OPort <port>
+ L4 }1 m% q0 b( ^- ~& P! {+ J! \: K+ f0 Y% h
2.賜孵 ip (拍冽澆蝬脣/憭 IP 敶)3 A, \$ w7 ?# `- T4 g+ M3 ?
ListenAddress 192.168.1.10
* L, K# `' j# w: |! g2 n0 ]' F, |& u2 G3 a4 `" o ^
3.蝳甇 root 餃" r. m3 M0 C0 ]0 E7 n
PermitRootLogin no" b% `+ f. h2 N8 ^4 p
蝞∠敹隞亙鈭箏董餃伐 su root嚗拍 sudo 撌乩5 A- X2 l* j O; O+ R% z0 `: h
. E' w/ O' `4 o( Z, i9 }2 i4.蝳甇V蝙函征撖蝣潛餃; y0 S5 I; `) m4 C
PermitEmptyPasswords no. a+ [9 q. W* I/ @$ K1 H+ k
. [) O4 Q7 A4 Q m% n8 r. P( G) h5.閮望蝯孵撣唾蝢斤餃
0 }# A6 m! R9 ?" X iAllowUsers <user1> <user2> <user3>
/ V. u( ]3 C; O- z7 R" qAllowGroups <group>
, L5 u/ e" S5 t/ M7 C+ M. gDenyUsers *
9 E% V6 ]' Y5 X! b; vDenyGroups no-ssh+ `5 A0 p O& P! b+ d7 w3 o' b
寞撖阡嚗撠澆銝撣唾閮嚗憒 Allow 頝 Deny 閰梧蝯 Deny
! l2 I! y8 w/ ^" [1 _0 d
' e) c4 n7 `2 K% p3 \+ g" R6.撱a文蝣潛駁嚗撘瑁翰雿輻 RSA/DSA 撽霅2 H$ C. T1 ^; e' n. q) c. s9 ~: v
RSAAuthentication yes
5 q9 F8 f; ?; {4 G* {6 ?) ~PubkeyAuthentication yes
' |& c% @: @: Q+ }+ vAuthorizedKeysFile %h/.ssh/authorized_keys
1 G2 w& L9 E8 l2 W! ?7 K' P/ B2 D% IPasswordAuthentication no+ q- G% k/ m) d2 F& r
銝衣Ⅱ靽 user ~/.ssh 甈 700嚗撠閰 user public key 亙 ~/.ssh/authorized_keys 銝准Public key Y孵舀撠 ssh-keygen
- p3 ?% _* ]2 f4 b3 n# R8 u p. g
" q8 _! p2 J/ J' W3 G6 I- { j7.閮 SSHv26 U& N( e3 {4 H8 m, j. v
Protocol 2
. Z6 M1 a* ]! t( Q+ A' Z
) m& \, ]6 _5 M/ C6 Y1 ?( k8.嗥孵雿輻刻蝢斤銝餅雿餃亥綽鋆∩誑 somebody handsomebody 銝臭蝙典蝣潛餃亦箔
7 w% d0 q L% b+ I- WMatch User somebody,handsomebody) v5 }% ~6 h: L; b# N4 @
PasswordAuthentication no雿輻 TCP wrappers 嗡皞 IP" v; }$ x- Z# C t7 w' N2 z% P
# vim /etc/hosts.deny
9 [, {% P& d0 b G6 H# a* csshd: ALL, P, v( r1 |( i* K6 M
# vim /etc/hosts.allow: d7 g" r0 f6 \; H
sshd: 192.168.1 1.2.3.4 # 閮 192.168.1.* 1.2.3.4 蝺4 ~7 a7 [* g8 j) M8 n8 e0 g
, R- W. P/ o2 q$ j+ M( j( S; K
9.雿輻 iptables 嗡皞 IP! w8 F- q2 e& H: {9 m9 m3 i a
# iptables -A INPUT -p tcp -m state --state NEW --source 1.2.3.4 --dport 22 -j ACCEPT; }. p i0 y2 {9 j1 r
# iptables -A INPUT -p tcp --dport 22 -j DROP! }. I; _# T8 [/ x6 S+ M& z2 c
閮剖蝡喟嚗亙璈敺賭摮嚗閬脣 iptables 閮剖& N5 L. d7 G5 L* k4 R, [( ]
5 Q) ?% y) V5 w, k0 v3 J# K4 D10.摰
+ u$ |: B- K& v2 P/ v* s Z雿臭誑雿輻其iptables訾嗅訕SH伐霈嗅其孵蝭批臭誑伐嗡銝賡乓雿臭誑其Y隞颱靘摮銝凋蝙 /second/minute/hour /day
3 K0 F" W% B6 G1 M蝚砌靘摮嚗憒銝冽嗉撓乩航炊撖蝣潘摰銝找閮勗刻赤SSH嚗璅瘥冽嗅其批芾賢閰虫甈∠駁
! B$ _5 F6 M% M$ S, Q. Y # iptables -A INPUT -p tcp -m state --syn --state NEW --dport 22 -m limit --limit 1/minute --limit-burst 1 -j ACCEPT3 v" Y5 n# B9 ~4 @
# iptables -A INPUT -p tcp -m state --syn --state NEW --dport 22 -j DROP2 U" B9 Y! S/ O
蝚砌靘摮嚗閮剔蔭iptables芸閮曹蜓璈193.180.177.13亙訕SH嚗典閰虫甈∪仃駁詨嚗iptables閮梯府銝餅瘥閰虫甈∠駁
3 L% u3 _0 @$ H1 z* c3 A # 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 ACCEPT3 I) a1 ^' d& G1 F0 P- X9 e
# iptables -A INPUT -p tcp -s 193.180.177.13 -m state --syn --state NEW --dport 22 -j DROP
8 \/ _/ I$ S( k/ N* q9 _) Z; v! ~. H7 f% g9 t
11.瑼X亦賊瑼獢甈嚗銝摰典銝閮梁餃% P) I& o A) ^* Z( K
StrictModes yes1 r( o- m+ b/ {7 f) H5 [
鈭賊瑼獢甈閮剖交航炊嚗航賡摰冽折◢芥憒雿輻刻 ~/.ssh/authorized_keys 甈亦 666嚗航賡嗡鈭箏臭誑典董8 V- L% h' A' u3 n" i9 K. r
( Y( Z1 [, O! X6 m9 y9 Z5 M12.芾雿輻刻餃交憿舐內 banner (閰梯牧頝摰冽扳隞暻潮靽...? 憭扳臭誑函冗鈭斗孵頝憯鈭箏...= =a). w- D- I! d# G6 Y0 y
Banner /etc/ssh/banner # 隞餅摮瑼
3 G/ Q/ v* W: @+ G6 h# r* f5 R W4 @. Z$ [) [" i0 h) G9 N
13. su/sudo 4 G: e$ S1 \3 x+ S" c) v$ v7 n
# vi /etc/pam.d/su! E) j Q, ^" V- X$ }! ]% m- w
auth required /lib/security/$ISA/pam_wheel.so use_uid3 ?4 K( Q8 R4 S6 f: R# n) G$ i
# visudo
/ T. W3 D& g7 w5 G. n. U9 O %wheel ALL = (ALL) ALL
' K8 v2 m$ A" M9 t. u2 p# gpasswd -a user1 wheel/ E; Q& x& W1 M
8 V& [6 H9 Q; |6 h# u9 d2 t
14. ssh 雿輻刻
; K- n0 _- d4 v1 L- ?& B# O# vi /etc/pam.d/sshd
6 b% m4 ^. y. `1 H auth required pam_listfile.so item=user sense=allow file=/etc/ssh_users onerr=fail
' @3 j% A( f9 [8 a0 K# echo <username> >> /etc/ssh_users
6 f* q9 J, ]7 r15.脫迫SSH蝺暹(timeout),霈PuTTY SSH 銝港蝺4 z6 ?4 u( M6 w" F) y0 V' y
靽格/etc/ssh/sshd_config, o4 p( c2 K8 t+ i
#TCPKeepAlive yes; C+ H) u: m! K2 K6 Q0 P
#ClientAliveInterval 09 G- }2 q+ B8 K$ ?$ ?6 r
#ClientAliveCountMax 3
; u3 ~' [9 m" t0 E. v2 B 撠#踵==>摮瑼7 I8 F. A, z% g2 Q2 b
#service ssd restart ==>sshd
: o5 L4 J7 M" f$ ^3 B V$ M 乩靘靽格 Pietty 賂脣PuTTY 蝺閮剖:
# U! c( R' T& E5 f& i 豢Connection殷撠Seconds between keepalives [0 to turn off]喲甈雿頛詨交撟曄嚗喲銝null撠隞乩蝺
7 d( c2 D2 N8 ^" D9 p7 F- l G$ a% ?/ c+ E
|
|