vi /etc/ssh/sshd_config . A( P8 |7 u+ d" K
/ S$ h6 D, T3 [1.靽格寥閮 port (舐典銵憭 port)4 k+ [+ q3 Q8 D @1 j5 }
Port <port>$ [. L* h; Q( g: n8 O
! N2 N0 l' E5 R* d2 Y' @! g2.賜孵 ip (拍冽澆蝬脣/憭 IP 敶)
+ w( I5 M2 f# w* pListenAddress 192.168.1.10
$ B8 Y3 |, N' F1 ?5 P# r
: M5 {( m5 Y( f K* N7 S- @! S* g3.蝳甇 root 餃) D( O1 R# ]7 u6 k6 U9 ?* e5 V
PermitRootLogin no( s% b' ~8 ~& f2 Y
蝞∠敹隞亙鈭箏董餃伐 su root嚗拍 sudo 撌乩3 h4 L0 s* z* E/ B2 A% D
( k" c$ V/ X3 s: g" J$ C# @+ W4.蝳甇V蝙函征撖蝣潛餃+ v7 F2 i2 s* f4 i
PermitEmptyPasswords no- g0 a0 z( J7 D9 L
E3 o& ^' b2 O0 e
5.閮望蝯孵撣唾蝢斤餃
& T o% V- a }% L; ]AllowUsers <user1> <user2> <user3>" @) F* M3 u: s) U5 h3 e' P
AllowGroups <group>
+ s3 o" k2 z5 Y& W/ x$ FDenyUsers *
7 _2 D' Y! v. ^" G- b* ^# f) |DenyGroups no-ssh$ D7 T5 L+ F! A7 D/ z; ]$ ]# t
寞撖阡嚗撠澆銝撣唾閮嚗憒 Allow 頝 Deny 閰梧蝯 Deny
( s0 d% e, y9 y: d; W) g: L( l- b' i0 `) D& c. c
6.撱a文蝣潛駁嚗撘瑁翰雿輻 RSA/DSA 撽霅
7 k4 a4 r. N% O! }. \RSAAuthentication yes
; n, R* Y/ Q7 d q& q4 m" K/ xPubkeyAuthentication yes. \- ?" Q5 }+ E" ?
AuthorizedKeysFile %h/.ssh/authorized_keys9 z; U2 v8 C! z3 V
PasswordAuthentication no
0 u1 P! C8 B0 s; E銝衣Ⅱ靽 user ~/.ssh 甈 700嚗撠閰 user public key 亙 ~/.ssh/authorized_keys 銝准Public key Y孵舀撠 ssh-keygen. E7 S. I& b( F! T' g2 W
- @* \# q5 i; h3 Y% e7 n, q" j
7.閮 SSHv2. `+ |/ q! n7 Z
Protocol 2+ c" m) N! I6 h' `3 T2 n
( t$ j: }. S* u
8.嗥孵雿輻刻蝢斤銝餅雿餃亥綽鋆∩誑 somebody handsomebody 銝臭蝙典蝣潛餃亦箔1 Y1 k2 L& a; X/ R5 c
Match User somebody,handsomebody6 D' [4 u: ?) ?) Y3 ~7 K2 b+ L
PasswordAuthentication no雿輻 TCP wrappers 嗡皞 IP
, d$ _8 {6 u8 E3 ~# vim /etc/hosts.deny( |4 `! E9 I7 Q- j- K
sshd: ALL
! ^$ L7 n7 ~( d/ N! S- C# vim /etc/hosts.allow7 e1 ?2 p8 M d& e
sshd: 192.168.1 1.2.3.4 # 閮 192.168.1.* 1.2.3.4 蝺
. H! [/ ] v+ x- b( z& E& e, Y7 [3 s X
9.雿輻 iptables 嗡皞 IP$ R6 l0 ]. s" @0 u& v- n- Z
# iptables -A INPUT -p tcp -m state --state NEW --source 1.2.3.4 --dport 22 -j ACCEPT
% Y$ u1 v1 u) C5 ]4 m# iptables -A INPUT -p tcp --dport 22 -j DROP9 [; B+ |- ~% Y0 S* e
閮剖蝡喟嚗亙璈敺賭摮嚗閬脣 iptables 閮剖
* a3 U5 W" S* c+ a( F A4 P
; p7 k$ Z4 I8 z- T- H8 ~4 ?10.摰7 ?, ?- b8 o, P. P/ I1 J) O- ]; x% ~
雿臭誑雿輻其iptables訾嗅訕SH伐霈嗅其孵蝭批臭誑伐嗡銝賡乓雿臭誑其Y隞颱靘摮銝凋蝙 /second/minute/hour /day
8 r# d R% F2 ^蝚砌靘摮嚗憒銝冽嗉撓乩航炊撖蝣潘摰銝找閮勗刻赤SSH嚗璅瘥冽嗅其批芾賢閰虫甈∠駁6 y0 o+ o2 m M* {9 z, C2 c
# iptables -A INPUT -p tcp -m state --syn --state NEW --dport 22 -m limit --limit 1/minute --limit-burst 1 -j ACCEPT3 V. ^" z n+ m: J# d
# iptables -A INPUT -p tcp -m state --syn --state NEW --dport 22 -j DROP1 Q; ~/ t$ c% W
蝚砌靘摮嚗閮剔蔭iptables芸閮曹蜓璈193.180.177.13亙訕SH嚗典閰虫甈∪仃駁詨嚗iptables閮梯府銝餅瘥閰虫甈∠駁
b4 n) u1 b1 [1 g9 k* _ # 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 ACCEPT6 f* M! ~: H( f6 l" J
# iptables -A INPUT -p tcp -s 193.180.177.13 -m state --syn --state NEW --dport 22 -j DROP
$ h9 `6 \8 d/ X/ k0 K0 y7 [. r/ j6 ^/ h6 v" H
11.瑼X亦賊瑼獢甈嚗銝摰典銝閮梁餃
9 o: ]0 Q. y+ ]7 Y3 HStrictModes yes( ?1 d3 V9 d$ K: |- w# e) c* J
鈭賊瑼獢甈閮剖交航炊嚗航賡摰冽折◢芥憒雿輻刻 ~/.ssh/authorized_keys 甈亦 666嚗航賡嗡鈭箏臭誑典董( z. C: ^" N3 a4 X
2 c8 O' N$ w4 E+ w. T# U% L# O
12.芾雿輻刻餃交憿舐內 banner (閰梯牧頝摰冽扳隞暻潮靽...? 憭扳臭誑函冗鈭斗孵頝憯鈭箏...= =a). z: \, C! j ~% m* `/ d2 ]2 h
Banner /etc/ssh/banner # 隞餅摮瑼 B; F O% F# I2 \3 \; q/ }# [
+ ~9 P; ]9 [* y5 \! \& O- t, I
13. su/sudo
. e% S% \# U; S8 j- m& ~4 ]! P# vi /etc/pam.d/su
6 k( I: h; W/ ~4 U2 A' `6 m- J auth required /lib/security/$ISA/pam_wheel.so use_uid# H) M* t" V, c& Z. H, T1 a
# visudo
. l& _ D; S# T& t# i %wheel ALL = (ALL) ALL
7 m5 }% j3 E5 f% r& f) H# gpasswd -a user1 wheel j3 J: j3 E9 R* z1 O3 N
5 ~7 \: @7 c4 r/ F: e& K* s, w+ D
14. ssh 雿輻刻
4 `3 F7 x$ }* k- {' j# vi /etc/pam.d/sshd
7 ?! t* [4 l" q6 d auth required pam_listfile.so item=user sense=allow file=/etc/ssh_users onerr=fail
$ ^. V. L7 j' W# echo <username> >> /etc/ssh_users2 @$ [: d2 J& W4 X7 B
15.脫迫SSH蝺暹(timeout),霈PuTTY SSH 銝港蝺& r3 X m! R1 l
靽格/etc/ssh/sshd_config: q6 i" F8 f8 d+ A& }& z% g4 m7 o; [
#TCPKeepAlive yes* a l. Y, w0 b5 g
#ClientAliveInterval 0
7 ^( T1 e; q9 j, j8 l- s#ClientAliveCountMax 3
% R4 d# p7 p1 k8 I 撠#踵==>摮瑼% Z4 M6 ?3 [1 ?, i$ G
#service ssd restart ==>sshd
# |( g1 j/ S" _' k' ]7 |$ ^ 乩靘靽格 Pietty 賂脣PuTTY 蝺閮剖:+ _3 l* G9 s; e$ I" A* X H
豢Connection殷撠Seconds between keepalives [0 to turn off]喲甈雿頛詨交撟曄嚗喲銝null撠隞乩蝺
/ ~8 c% |: n: e/ C+ m( D8 w. ]; h- P/ S7 k7 I
|
|