整理一份 sshd_config 說(shuō)明
[root@shenfeng ssh]# ssh -V
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
路徑:/etc/ssh/sshd_config
配置后需要重啟服務(wù)
完整配置如下:
1 # $OpenBSD: sshd_config,v 1.93 2014/01/10 05:59:19 djm Exp $
2
3 # This is the sshd server system-wide configuration file. See
4 # sshd_config(5) for more information.
5
6 # This sshd was compiled with PATH=/usr/local/bin:/usr/bin
7
8 # The strategy used for options in the default sshd_config shipped with
9 # OpenSSH is to specify options with their default value where
10 # possible, but leave them commented. Uncommented options override the
11 # default value.
12
ssh 默認(rèn)使用 Port 22,也可以使用多個(gè) Port,如果需要使用多個(gè) Port 另起一行 Port 443
即可,然后重啟 sshd
13 # If you want to change the port on a SELinux system, you have to tell
14 # SELinux about this change.
15 # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
16 #
17 #Port 22
監(jiān)聽(tīng) ip
eg:有兩個(gè) IP,分別是 192.168.1.123 及 192.168.2.123,假設(shè)只想要讓 192.168.1.123 可以監(jiān)聽(tīng) sshd ,ListenAddress 192.168.1.100
默認(rèn)值是監(jiān)聽(tīng)所有接口的 ssh 請(qǐng)求
18 #ListenAddress 0.0.0.0
19 #ListenAddress ::
20
ssh 的協(xié)議版本,如果需要支持舊版: Protocol 2,1
21 # The default requires explicit activation of protocol 1
22 #Protocol 2
23
私鑰存放的位置
24 # HostKey for protocol version 1
25 #HostKey /etc/ssh/ssh_host_key
26 # HostKeys for protocol version 2
27 HostKey /etc/ssh/ssh_host_rsa_key
28 #HostKey /etc/ssh/ssh_host_dsa_key
29 HostKey /etc/ssh/ssh_host_ecdsa_key
30 HostKey /etc/ssh/ssh_host_ed25519_key
31
在SSH-1協(xié)議下,短命的服務(wù)器密鑰將以此指令設(shè)置的時(shí)間為周期(秒),不斷重新生成
這個(gè)機(jī)制可以盡量減小密鑰丟失或者黑客攻擊造成的損失
設(shè)為 0 表示永不重新生成,默認(rèn)為 3600(秒)
32 # Lifetime and size of ephemeral version 1 server key
33 #KeyRegenerationInterval 1h
指定臨時(shí)服務(wù)器密鑰的長(zhǎng)度,僅用于SSH-1
34 #ServerKeyBits 1024
35
36 # Ciphers and keying
37 #RekeyLimit default none
38
登錄記錄的等級(jí)
39 # Logging
40 # obsoletes QuietMode and FascistLogging
41 #LogLevel INFO
42
當(dāng)使用者連接到 ssh server 后 會(huì)提示輸入密碼,在這個(gè)時(shí)候,在設(shè)置值內(nèi)沒(méi)有成功連上 ssh server 時(shí)候就會(huì)自動(dòng)斷線,如果沒(méi)有單位 默認(rèn)為 s
43 # Authentication:
44
45 #LoginGraceTime 2m
是否讓 sshd 去檢查 用戶家目錄 或 相關(guān)檔案 的權(quán)限
如果使用者將某些重要檔案的權(quán)限設(shè)錯(cuò) 可能會(huì)導(dǎo)致一些問(wèn)題
eg:使用者的~.ssh/
權(quán)限設(shè)錯(cuò)時(shí) 某些特殊情況下會(huì)不許用戶登入
46 #StrictModes yes
指定每個(gè)連接最大允許的認(rèn)證次數(shù),默認(rèn)值是 6
如果失敗認(rèn)證的次數(shù)超過(guò)這個(gè)數(shù)值的一半,連接將被強(qiáng)制斷開(kāi),且會(huì)生成額外的失敗日志消息
47 #MaxAuthTries 6
限制同時(shí)登錄的數(shù)量
48 #MaxSessions 10
49
是否允許使用純 RSA 公鑰認(rèn)證,僅用于SSH-1
50 #RSAAuthentication yes
是否允許用戶自行使用成對(duì)的密鑰進(jìn)行登入系統(tǒng)行為 僅針對(duì) version 2
自制的公鑰數(shù)據(jù)就放置于用戶家目錄下的 .ssh/authorized_keys
51 #PubkeyAuthentication yes
52
53 # The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
54 # but this is overridden so installations will only check .ssh/authorized_keys
55 AuthorizedKeysFile .ssh/authorized_keys
56
57 #AuthorizedPrincipalsFile none
58
是否允許authorized_keys中使用command項(xiàng)
59 #AuthorizedKeysCommand none
限制能夠在authorized_keys中使用command項(xiàng)的用戶
60 #AuthorizedKeysCommandUser nobody
61
這個(gè)選項(xiàng)是專(zhuān)門(mén)給 version 1 用的 使用 rhosts 檔案在 /etc/hosts.equiv
配合 RSA 演算方式來(lái)進(jìn)行認(rèn)證
no
62 # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
63 #RhostsRSAAuthentication no
是否允許 host_based 驗(yàn)證,no
64 # similar for protocol version 2
65 #HostbasedAuthentication no
是否忽略家目錄內(nèi)的 ~/.ssh/known_hosts 這個(gè)檔案所記錄的主機(jī)內(nèi)容
no
66 # Change to yes if you don't trust ~/.ssh/known_hosts for
67 # RhostsRSAAuthentication and HostbasedAuthentication
68 #IgnoreUserKnownHosts no
是否取消使用 ~/.ssh/.rhosts 來(lái)做為認(rèn)證 yes
69 # Don't read the user's ~/.rhosts and ~/.shosts files
70 #IgnoreRhosts yes
71
是否允許空密碼登錄 no
72 # To disable tunneled clear text passwords, change to no here!
73 #PermitEmptyPasswords no
74
允許任何的密碼認(rèn)證,所以,任何 login.conf 規(guī)定的認(rèn)證方式,均可適用
但目前通常使用 PAM 模塊幫忙管理認(rèn)證,因此這個(gè)選項(xiàng)可以設(shè)定為 no
75 # Change to no to disable s/key passwords
76 #ChallengeResponseAuthentication yes
77 ChallengeResponseAuthentication no
78
Kerberos 是一種計(jì)算機(jī)網(wǎng)絡(luò)授權(quán)協(xié)議,用來(lái)在非安全網(wǎng)絡(luò)中,對(duì)個(gè)人通信以安全的手段進(jìn)行身份認(rèn)證。這個(gè)詞又指麻省理工學(xué)院為這個(gè)協(xié)議開(kāi)發(fā)的一套計(jì)算機(jī)軟件。軟件設(shè)計(jì)上采用客戶端/服務(wù)器結(jié)構(gòu),并且能夠進(jìn)行相互認(rèn)證,即客戶端和服務(wù)器端均可對(duì)對(duì)方進(jìn)行身份認(rèn)證。可以用于防止竊聽(tīng)、防止重放攻擊、保護(hù)數(shù)據(jù)完整性等場(chǎng)合,是一種應(yīng)用對(duì)稱密鑰體制進(jìn)行密鑰管理的系統(tǒng)。Kerberos的擴(kuò)展產(chǎn)品也使用公開(kāi)密鑰加密方法進(jìn)行認(rèn)證。
要使用Kerberos認(rèn)證,服務(wù)器需要一個(gè)可以校驗(yàn) KDC identity 的 Kerberos servtab
(三頭地獄犬)
79 # Kerberos options
80 #KerberosAuthentication no # 是否允許使用基于 Kerberos的用戶認(rèn)證
81 #KerberosOrLocalPasswd yes # 如果 Kerberos 密碼認(rèn)證失敗,那么該密碼還將要通過(guò)其它的認(rèn)證機(jī)制(比如 /etc/passwd)
82 #KerberosTicketCleanup yes # 是否在用戶退出登錄后自動(dòng)銷(xiāo)毀用戶的 ticket
83 #KerberosGetAFSToken no # 如果使用了 AFS 并且該用戶有一個(gè) Kerberos 5 TGT,那么開(kāi)啟該指令后,將會(huì)在訪問(wèn)用戶的家目錄前嘗試獲取一個(gè) AFS token
84 #KerberosUseKuserok yes
85
86 # GSSAPI options
87 GSSAPIAuthentication yes # 是否允許使用基于 GSSAPI 的用戶認(rèn)證。默認(rèn)值為”no”。僅用于SSH-2。
88 GSSAPICleanupCredentials no # 是否在用戶退出登錄后自動(dòng)銷(xiāo)毀用戶憑證緩存
89 #GSSAPIStrictAcceptorCheck yes # 是否對(duì)接收到的用戶憑證嚴(yán)格校驗(yàn)
90 #GSSAPIKeyExchange no # 是否開(kāi)啟密鑰交換
91 #GSSAPIEnablek5users no
92
利用 PAM 管理使用者認(rèn)證,可以記錄與管理等
UsePAM yes
&& ChallengeResponseAuthentication no
93 # Set this to 'yes' to enable PAM authentication, account processing,
94 # and session processing. If this is enabled, PAM authentication will
95 # be allowed through the ChallengeResponseAuthentication and
96 # PAM authentication via ChallengeResponseAuthentication may bypass
97 # If you just want the PAM account and session checks to run without
98 # and ChallengeResponseAuthentication to 'no'.
99 # WARNING: 'UsePAM no' is not supported in Red Hat Enterprise Linux and may cause several
100 # problems.
101 UsePAM yes
102
103 #AllowAgentForwarding yes
104 #AllowTcpForwarding yes # 允許TCP轉(zhuǎn)發(fā)
105 #GatewayPorts no # 轉(zhuǎn)發(fā)路徑端口
X11Forwarding 項(xiàng)目 可以讓窗口的數(shù)據(jù)透過(guò) ssh 通道來(lái)傳送
106 X11Forwarding yes # 是否開(kāi)啟X11轉(zhuǎn)發(fā)
107 #X11DisplayOffset 10 # 設(shè)置轉(zhuǎn)發(fā)的可顯示區(qū)數(shù)字為10
108 #X11UseLocalhost yes # 是否將X11的轉(zhuǎn)發(fā)服務(wù)器地址保存到loopback地址
109 #PermitTTY yes
登入后是否顯示出一些信息 預(yù)設(shè)是 yes
eg:上次登入的時(shí)間、地點(diǎn)等等
即輸出 /etc/motd
這個(gè)檔案的內(nèi)容
出于安全考慮 可改為 no
110 #PrintMotd yes
顯示上次登入的時(shí)間
111 #PrintLastLog yes
當(dāng)成功登入后,服務(wù)器會(huì)一直傳送 TCP 封包給客戶端以判斷對(duì)方是否一直存在聯(lián)機(jī)。
不過(guò),如果聯(lián)機(jī)時(shí)中間的路由器暫時(shí)停止服務(wù)幾秒鐘,也會(huì)讓聯(lián)機(jī)中斷
在這種情況下,任何一端死掉后,SSH可以立刻知道,而不會(huì)有僵尸程序的發(fā)生
但如果你的網(wǎng)絡(luò)或路由器常常不穩(wěn)定,那么可以設(shè)定為 no
112 #TCPKeepAlive yes
是否在交互式登錄時(shí)啟用login
113 #UseLogin no
是否讓 sshd 通過(guò)創(chuàng)建非特權(quán)子進(jìn)程處理接入請(qǐng)求的方法來(lái)進(jìn)行權(quán)限分離 默認(rèn)值是 yes
認(rèn)證成功后,將以該認(rèn)證用戶的身份創(chuàng)建另一個(gè)子進(jìn)程。
這樣做的目的是為了防止通過(guò)有缺陷的子進(jìn)程提升權(quán)限,從而使系統(tǒng)更加安全
eg:sshd 啟動(dòng)在 port 22 ,因此啟動(dòng)的程序是屬于 root 的身份。那么當(dāng) student 登入后,這個(gè)設(shè)定值會(huì)讓 sshd 產(chǎn)生一個(gè)屬于 sutdent 的 sshd 程序來(lái)使用,對(duì)系統(tǒng)較安全
114 UsePrivilegeSeparation sandbox # Default for new installations.
115 #PermitUserEnvironment no
指定何時(shí)開(kāi)始使用壓縮數(shù)據(jù)模式進(jìn)行傳輸,選項(xiàng) yes
no
delayed(登錄后將數(shù)據(jù)壓縮)
116 #Compression delayed
117 #ClientAliveInterval 0 # 設(shè)置空閑登錄的最大時(shí)長(zhǎng)
118 #ClientAliveCountMax 3 # 在沒(méi)收到任何數(shù)據(jù)的時(shí)候,最多向3個(gè)客戶端進(jìn)行keepalive檢測(cè)
顯示補(bǔ)丁級(jí)別
119 #ShowPatchLevel no
放置 sshd 這個(gè) PID 的檔案,默認(rèn)值
120 #PidFile /var/run/sshd.pid
同時(shí)允許幾個(gè)尚未登入的聯(lián)機(jī)畫(huà)面
當(dāng)連上 SSH 但是尚未輸入密碼時(shí) 這個(gè)時(shí)候就是 聯(lián)機(jī)畫(huà)面
在這個(gè)聯(lián)機(jī)畫(huà)面中,為了保護(hù)主機(jī),所以需要設(shè)定最大值,預(yù)設(shè)最多十個(gè)聯(lián)機(jī)畫(huà)面,而已經(jīng)建立聯(lián)機(jī)的不計(jì)算在這十個(gè)當(dāng)中
121 #MaxStartups 10:30:100
允許tun設(shè)備轉(zhuǎn)發(fā)
122 #PermitTunnel no
是否允許切換目錄
123 #ChrootDirectory none
配置附加版本
124 #VersionAddendum none
125
不設(shè)置歡迎詞
126 # no default banner path
127 #Banner none
128
接受本地相關(guān)的環(huán)境變量類(lèi)型
指定客戶端發(fā)送的哪些環(huán)境變量將會(huì)被傳遞到會(huì)話環(huán)境中
129 # Accept locale-related environment variables
130 AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
131 AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
132 AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
133 AcceptEnv XMODIFIERS
134
是否開(kāi)啟sftp服務(wù)
135 # override default of no subsystems
136 Subsystem sftp /usr/libexec/openssh/sftp-server
137
限制只允許某個(gè)用戶登錄
138 # Example of overriding settings on a per-user basis
139 #Match User anoncvs
是否開(kāi)啟X11轉(zhuǎn)發(fā)
140 # X11Forwarding no
允許TCP轉(zhuǎn)發(fā)
141 # AllowTcpForwarding no
142 # PermitTTY no
限制命令
143 # ForceCommand cvs server
一般來(lái)說(shuō),為了要判斷客戶端來(lái)源是正常合法的,會(huì)使用 DNS 去反查客戶端的主機(jī)名
不過(guò)如果是在內(nèi)網(wǎng)互連,設(shè)定為 no 會(huì)讓聯(lián)機(jī)達(dá)成速度更快
144 UseDNS no
145 AddressFamily inet
登入設(shè)定,是否允許 root 用戶登錄以任何認(rèn)證方式登錄
yes
# 允許 root用戶 以任何認(rèn)證方式登錄(用戶名密碼認(rèn)證,公鑰認(rèn)證)
no
# 不允許 root用戶 以任何認(rèn)證方式登錄
without-password
# 只允許 root用戶 public key 認(rèn)證方式登錄
146 PermitRootLogin yes
Linux Daemon(守護(hù)進(jìn)程)是運(yùn)行在后臺(tái)的一種特殊進(jìn)程。它獨(dú)立于控制終端并且周期性地執(zhí)行某種任務(wù)或等待處理某些發(fā)生的事件。它不需要用戶輸入就能運(yùn)行而且提供某種服務(wù),不是對(duì)整個(gè)系統(tǒng)就是對(duì)某個(gè)用戶程序提供服務(wù)。Linux系統(tǒng)的大多數(shù)服務(wù)器就是通過(guò)守護(hù)進(jìn)程實(shí)現(xiàn)的。常見(jiàn)的守護(hù)進(jìn)程包括系統(tǒng)日志進(jìn)程syslogd、 web服務(wù)器httpd、郵件服務(wù)器sendmail和數(shù)據(jù)庫(kù)服務(wù)器mysqld等。
守護(hù)進(jìn)程一般在系統(tǒng)啟動(dòng)時(shí)開(kāi)始運(yùn)行,除非強(qiáng)行終止,否則直到系統(tǒng)關(guān)機(jī)都保持運(yùn)行。守護(hù)進(jìn)程經(jīng)常以超級(jí)用戶(root)權(quán)限運(yùn)行,因?yàn)樗鼈円褂锰厥獾亩丝冢?-1024)或訪問(wèn)某些特殊的資源。
一個(gè)守護(hù)進(jìn)程的父進(jìn)程是init進(jìn)程,因?yàn)樗嬲母高M(jìn)程在fork出子進(jìn)程后就先于子進(jìn)程exit退出了,所以它是一個(gè)由init繼承的孤兒進(jìn)程。守護(hù)進(jìn)程是非交互式程序,沒(méi)有控制終端,所以任何輸出,無(wú)論是向標(biāo)準(zhǔn)輸出設(shè)備stdout還是標(biāo)準(zhǔn)出錯(cuò)設(shè)備stderr的輸出都需要特殊處理。
守護(hù)進(jìn)程的名稱通常以d結(jié)尾,比如sshd、xinetd、crond等
有關(guān)登錄的文件信息 和 daemon
當(dāng)使用 SSH 登入系統(tǒng)的時(shí)候,SSH 會(huì)記錄信息
預(yù)設(shè)是以 AUTH 來(lái)設(shè)定的,即是 /var/log/secure
147 SyslogFacility AUTHPRIV
是否可以使用密碼登錄
148 PasswordAuthentication yes
不定期更新 不合適的地方 還請(qǐng)指點(diǎn)~ 感激不盡