vi /etc/ssh/sshd_config
9 z9 c# a- a+ J$ c. V# q) M
! \- J/ E3 M& \: ?# Y# Z; e' Y1.靽格寥閮 port (舐典銵憭 port)3 Z9 m, [7 N0 I1 ~5 O# ]
Port <port>
1 h* ?/ C/ ~8 `# P% L
! |% y! T! p1 F4 i# I2.賜孵 ip (拍冽澆蝬脣/憭 IP 敶)
3 R+ m! N6 k0 ^. L. _, bListenAddress 192.168.1.10. e" R! N9 z. o7 ~6 Q
4 B, b+ g7 O9 Q5 A- H6 N. |, J3.蝳甇 root 餃
]/ X; w6 ?! a" nPermitRootLogin no
- _5 @/ o! i: h c* ]* P蝞∠敹隞亙鈭箏董餃伐 su root嚗拍 sudo 撌乩
) R; b: V) @% A, k8 g! B
3 w+ }- G4 k0 q) m5 M7 V6 |5 p4.蝳甇V蝙函征撖蝣潛餃
$ t& F7 I3 k$ f( x' n; s nPermitEmptyPasswords no
2 A8 B4 ^) P& q5 b
1 Q( o t$ {, K! x8 w( Y% }/ Q5.閮望蝯孵撣唾蝢斤餃$ _6 c; q/ J" d( m2 N+ {3 b7 S
AllowUsers <user1> <user2> <user3>
- T$ ]* @3 t+ s5 V4 c5 }: ?& Y' RAllowGroups <group>( O5 r/ W: K: K+ O# a6 d
DenyUsers *, }$ S: n- I, S. M- {: f
DenyGroups no-ssh6 O4 L ~! o; o% J% V0 L2 M
寞撖阡嚗撠澆銝撣唾閮嚗憒 Allow 頝 Deny 閰梧蝯 Deny
! k' k7 f, w9 w& ~4 e2 q" r3 h+ y4 d) b, O2 t! ^
6.撱a文蝣潛駁嚗撘瑁翰雿輻 RSA/DSA 撽霅8 [6 n/ V% ?; F4 G
RSAAuthentication yes
9 D( o# S4 ?7 r# K9 T% DPubkeyAuthentication yes
4 R$ J3 t: O% M. R6 w1 M$ z+ ^5 W& T* L. tAuthorizedKeysFile %h/.ssh/authorized_keys* J* m/ U& U# R, e
PasswordAuthentication no
5 ~2 O# [7 F0 ~0 K) S銝衣Ⅱ靽 user ~/.ssh 甈 700嚗撠閰 user public key 亙 ~/.ssh/authorized_keys 銝准Public key Y孵舀撠 ssh-keygen
0 e" J$ B# V) K0 u; |# y O% R+ ?4 B0 ?; X
7.閮 SSHv2
& K1 _3 `9 J6 }6 S/ wProtocol 2
% v5 z/ Q3 ~+ p) n; l' N4 F, `. T
7 n# c2 M' C; ~' X) W: A3 O+ M" _8.嗥孵雿輻刻蝢斤銝餅雿餃亥綽鋆∩誑 somebody handsomebody 銝臭蝙典蝣潛餃亦箔2 @6 C8 X, c: b7 T4 z2 \# a3 G8 \
Match User somebody,handsomebody; h: l' H9 g4 k0 n
PasswordAuthentication no雿輻 TCP wrappers 嗡皞 IP2 Y# X# R: J5 ~9 j
# vim /etc/hosts.deny3 S! O e- S& E2 C
sshd: ALL
2 D+ g$ U# u) I/ |# vim /etc/hosts.allow
8 B) k h4 D7 y Csshd: 192.168.1 1.2.3.4 # 閮 192.168.1.* 1.2.3.4 蝺! `7 z5 j! a6 W0 L8 o
+ t( Q2 j' b% j: D' a- P. x. N) O/ R
9.雿輻 iptables 嗡皞 IP
8 `( g# a, D, G+ \# iptables -A INPUT -p tcp -m state --state NEW --source 1.2.3.4 --dport 22 -j ACCEPT, b) N5 V) g/ Q2 K
# iptables -A INPUT -p tcp --dport 22 -j DROP
* N- y( x* S8 A; \: A2 p8 N閮剖蝡喟嚗亙璈敺賭摮嚗閬脣 iptables 閮剖/ F% i y: V+ J# ]8 H" D. P6 m
2 o3 _' X+ t* Z! s; c
10.摰- Q+ ]2 v. O4 S: @! l
雿臭誑雿輻其iptables訾嗅訕SH伐霈嗅其孵蝭批臭誑伐嗡銝賡乓雿臭誑其Y隞颱靘摮銝凋蝙 /second/minute/hour /day
( R( P' C! M+ a' _, Y* L蝚砌靘摮嚗憒銝冽嗉撓乩航炊撖蝣潘摰銝找閮勗刻赤SSH嚗璅瘥冽嗅其批芾賢閰虫甈∠駁
g0 d3 b3 Q$ q% Z # iptables -A INPUT -p tcp -m state --syn --state NEW --dport 22 -m limit --limit 1/minute --limit-burst 1 -j ACCEPT# A* Z, j# R3 w$ ^4 G6 Y
# iptables -A INPUT -p tcp -m state --syn --state NEW --dport 22 -j DROP. C/ H% @+ }; t3 H
蝚砌靘摮嚗閮剔蔭iptables芸閮曹蜓璈193.180.177.13亙訕SH嚗典閰虫甈∪仃駁詨嚗iptables閮梯府銝餅瘥閰虫甈∠駁. }& Z% m% Q, d- v2 Z% T
# 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) ]7 v3 R4 {+ Z! z5 u
# iptables -A INPUT -p tcp -s 193.180.177.13 -m state --syn --state NEW --dport 22 -j DROP4 p2 x6 _) o# ~5 D
* a4 u& ? h9 e* x- n2 q11.瑼X亦賊瑼獢甈嚗銝摰典銝閮梁餃
* S2 q/ [2 O- e# v8 M" N0 iStrictModes yes# P+ y- p' T7 b6 { |
鈭賊瑼獢甈閮剖交航炊嚗航賡摰冽折◢芥憒雿輻刻 ~/.ssh/authorized_keys 甈亦 666嚗航賡嗡鈭箏臭誑典董
* S9 a$ |0 J9 |) C. P9 R* H# V1 k: ~1 m
12.芾雿輻刻餃交憿舐內 banner (閰梯牧頝摰冽扳隞暻潮靽...? 憭扳臭誑函冗鈭斗孵頝憯鈭箏...= =a)& o& u/ d8 V$ p9 E
Banner /etc/ssh/banner # 隞餅摮瑼: P. _' t' Q1 q3 V J7 ~
, y! {4 O% h( |* Q8 ^/ Y; H13. su/sudo
$ p4 K6 D; A: R5 ^: Q# vi /etc/pam.d/su' T; n' N l) o5 x* f% e6 u- O% k
auth required /lib/security/$ISA/pam_wheel.so use_uid
4 D+ F: t: o& V* I# visudo
3 t/ M$ k* Z- R P9 b %wheel ALL = (ALL) ALL
* O! P0 V% I$ x Z) ?# gpasswd -a user1 wheel
6 a/ y D q/ d; u7 Z( ?2 X# |
9 S% t! f' {. ~" k8 s& i t$ q14. ssh 雿輻刻- |8 S; [; _: o l D: G8 v) U0 M
# vi /etc/pam.d/sshd
4 A/ E2 @/ e8 A. s& A& F auth required pam_listfile.so item=user sense=allow file=/etc/ssh_users onerr=fail
1 e, G6 k6 Z* m# echo <username> >> /etc/ssh_users2 M0 Y& b' J; i: R
15.脫迫SSH蝺暹(timeout),霈PuTTY SSH 銝港蝺
/ ]. S4 q# r9 r! m3 d5 j9 w7 e 靽格/etc/ssh/sshd_config
" c% m/ h; ~+ ^! @8 F) e* a% ^. m1 t#TCPKeepAlive yes: N X. O/ L* Q4 h
#ClientAliveInterval 0
* G* R0 k* F& D A. c! V#ClientAliveCountMax 31 e% S8 T7 T8 G1 s. @2 ?4 |' J
撠#踵==>摮瑼2 b# r. m& Y* q4 A6 Z( ?
#service ssd restart ==>sshd; i' i3 [8 w% F9 L
乩靘靽格 Pietty 賂脣PuTTY 蝺閮剖:
8 R2 T5 ]) D6 Q 豢Connection殷撠Seconds between keepalives [0 to turn off]喲甈雿頛詨交撟曄嚗喲銝null撠隞乩蝺
$ j- \3 [2 s- w3 ~ s& ^1 w+ L# j2 P
|
|