(转)sshd_config配置 详解

转自: sshd_config配置 详解  
Java代码   收藏代码
  1. 1. 关于 SSH Server 的整体设定,包含使用的 port 啦,以及使用的密码演算方式  
  2. Port 22          # SSH 预设使用 22 这个 port,您也可以使用多的 port !  
  3.               # 亦即重复使用 port 这个设定项目即可!  
  4. Protocol 2,1        # 选择的 SSH 协议版本,可以是 1 也可以是 2 ,  
  5.               # 如果要同时支持两者,就必须要使用 2,1 这个分隔了!  
  6. #ListenAddress 0.0.0.0   # 监听的主机适配卡!举个例子来说,如果您有两个 IP,  
  7.               # 分别是 192.168.0.100 及 192.168.2.20 ,那么只想要  
  8.               # 开放 192.168.0.100 时,就可以写如同下面的样式:  
  9. ListenAddress 192.168.0.100          # 只监听来自 192.168.0.100 这个 IP 的SSH联机。  
  10.                    # 如果不使用设定的话,则预设所有接口均接受 SSH  
  11. PidFile /var/run/sshd.pid      # 可以放置 SSHD 这个 PID 的档案!左列为默认值  
  12. LoginGraceTime 600     # 当使用者连上 SSH server 之后,会出现输入密码的画面,  
  13.               # 在该画面中,在多久时间内没有成功连上 SSH server ,  
  14.               # 就断线!时间为秒!  
  15. Compression yes      # 是否可以使用压缩指令?当然可以啰!  
  16.    
  17. 2. 说明主机的 Private Key 放置的档案,预设使用下面的档案即可!  
  18. HostKey /etc/ssh/ssh_host_key    # SSH version 1 使用的私钥  
  19. HostKey /etc/ssh/ssh_host_rsa_key  # SSH version 2 使用的 RSA 私钥  
  20. HostKey /etc/ssh/ssh_host_dsa_key  # SSH version 2 使用的 DSA 私钥  
  21.   
  22. 2.1 关于 version 1 的一些设定!  
  23. KeyRegenerationInterval 3600     # 由前面联机的说明可以知道, version 1 会使用   
  24.                    # server 的 Public Key ,那么如果这个 Public   
  25.                    # Key 被偷的话,岂不完蛋?所以需要每隔一段时间  
  26.                    # 来重新建立一次!这里的时间为秒!  
  27. ServerKeyBits 768           # 没错!这个就是 Server key 的长度!  
  28. 3. 关于登录文件的讯息数据放置与 daemon 的名称!  
  29. SyslogFacility AUTH         # 当有人使用 SSH 登入系统的时候,SSH会记录资  
  30.                    # 讯,这个信息要记录在什么 daemon name 底下?  
  31.                    # 预设是以 AUTH 来设定的,即是 /var/log/secure  
  32.                    # 里面!什么?忘记了!回到 Linux 基础去翻一下  
  33.                    # 其它可用的 daemon name 为:DAEMON,USER,AUTH,  
  34.                    # LOCAL0,LOCAL1,LOCAL2,LOCAL3,LOCAL4,LOCAL5,  
  35. LogLevel INFO            # 登录记录的等级!嘿嘿!任何讯息!  
  36.                    # 同样的,忘记了就回去参考!  
  37. 4. 安全设定项目!极重要!  
  38. 4.1 登入设定部分  
  39. PermitRootLogin no     # 是否允许 root 登入!预设是允许的,但是建议设定成 no!  
  40. UserLogin no        # 在 SSH 底下本来就不接受 login 这个程序的登入!  
  41. StrictModes yes      # 当使用者的 host key 改变之后,Server 就不接受联机,  
  42.               # 可以抵挡部分的木马程序!  
  43. #RSAAuthentication yes   # 是否使用纯的 RSA 认证!?仅针对 version 1 !  
  44. PubkeyAuthentication yes  # 是否允许 Public Key ?当然允许啦!只有 version 2  
  45. AuthorizedKeysFile      .ssh/authorized_keys  
  46.               # 上面这个在设定若要使用不需要密码登入的账号时,那么那个  
  47.               # 账号的存放档案所在档名!  
  48. 4.2 认证部分  
  49. RhostsAuthentication no  # 本机系统不止使用 .rhosts ,因为仅使用 .rhosts 太  
  50.               # 不安全了,所以这里一定要设定为 no !  
  51. IgnoreRhosts yes      # 是否取消使用 ~/.ssh/.rhosts 来做为认证!当然是!  
  52. RhostsRSAAuthentication no # 这个选项是专门给 version 1 用的,使用 rhosts 档案在  
  53.               # /etc/hosts.equiv配合 RSA 演算方式来进行认证!不要使用  
  54. HostbasedAuthentication no # 这个项目与上面的项目类似,不过是给 version 2 使用的!  
  55. IgnoreUserKnownHosts no  # 是否忽略家目录内的 ~/.ssh/known_hosts 这个档案所记录  
  56.               # 的主机内容?当然不要忽略,所以这里就是 no 啦!  
  57. PasswordAuthentication yes # 密码验证当然是需要的!所以这里写 yes 啰!  
  58. PermitEmptyPasswords no  # 若上面那一项如果设定为 yes 的话,这一项就最好设定  
  59.               # 为 no ,这个项目在是否允许以空的密码登入!当然不许!  
  60. ChallengeResponseAuthentication yes  # 挑战任何的密码认证!所以,任何 login.conf   
  61.                    # 规定的认证方式,均可适用!  
  62. #PAMAuthenticationViaKbdInt yes      # 是否启用其它的 PAM 模块!启用这个模块将会  
  63.                    # 导致 PasswordAuthentication 设定失效!  
  64.    
  65. 4.3 与 Kerberos 有关的参数设定!因为我们没有 Kerberos 主机,所以底下不用设定!  
  66. #KerberosAuthentication no  
  67. #KerberosOrLocalPasswd yes  
  68. #KerberosTicketCleanup yes  
  69. #KerberosTgtPassing no  
  70.    
  71. 4.4 底下是有关在 X-Window 底下使用的相关设定!  
  72. X11Forwarding yes  
  73. #X11DisplayOffset 10  
  74. #X11UseLocalhost yes  
  75. 4.5 登入后的项目:  
  76. PrintMotd no              # 登入后是否显示出一些信息呢?例如上次登入的时间、地点等  
  77.              # 等,预设是 yes ,但是,如果为了安全,可以考虑改为 no !  
  78. PrintLastLog yes     # 显示上次登入的信息!可以啊!预设也是 yes !  
  79. KeepAlive yes       # 一般而言,如果设定这项目的话,那么 SSH Server 会传送  
  80.              # KeepAlive 的讯息给 Client 端,以确保两者的联机正常!  
  81.              # 在这个情况下,任何一端死掉后, SSH 可以立刻知道!而不会  
  82.              # 有僵尸程序的发生!  
  83. UsePrivilegeSeparation yes # 使用者的权限设定项目!就设定为 yes 吧!  
  84. MaxStartups 10      # 同时允许几个尚未登入的联机画面?当我们连上 SSH ,  
  85.              # 但是尚未输入密码时,这个时候就是我们所谓的联机画面啦!  
  86.              # 在这个联机画面中,为了保护主机,所以需要设定最大值,  
  87.              # 预设最多十个联机画面,而已经建立联机的不计算在这十个当中  
  88. 4.6 关于使用者抵挡的设定项目:  
  89. DenyUsers *        # 设定受抵挡的使用者名称,如果是全部的使用者,那就是全部  
  90.              # 挡吧!若是部分使用者,可以将该账号填入!例如下列!  
  91. DenyUsers test  
  92. DenyGroups test      # 与 DenyUsers 相同!仅抵挡几个群组而已!  
  93. 5. 关于 SFTP 服务的设定项目!  
  94. Subsystem       sftp    /usr/lib/ssh/sftp-server  

  
基本上,在您的系统中, 『除非有必要,否则请不要更改 /etc/ssh/sshd_config 这个档案的设定值!』 因为预设的情况下通常都是最严密的 SSH 保护了,因此,可以不需要更动他!上面的说明仅是在让大家了解每个细项的一些基本内容而已! 
  
另外,如果您修改过上面这个档案(/etc/ssh/sshd_config),那么就必需要重新启动一次 sshd 这个 daemon 才行!亦即是:/etc/rc.d/init.d/sshd restart(service sshd restart) 

man sshd_config:查看随机帮组文档 
sshd_config 中文手册  
Html代码   收藏代码
  1. #   $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 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:/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 change a  
  11. # default value.  
  12.   
  13. #Port 22  
  14. #AddressFamily any  
  15. #ListenAddress 0.0.0.0  
  16. #ListenAddress ::  
  17.   
  18. # Disable legacy (protocol version 1) support in the server for new  
  19. # installations. In future the default will change to require explicit  
  20. # activation of protocol 1  
  21. Protocol 2  
  22.   
  23. # HostKey for protocol version 1  
  24. #HostKey /etc/ssh/ssh_host_key  
  25. # HostKeys for protocol version 2  
  26. #HostKey /etc/ssh/ssh_host_rsa_key  
  27. #HostKey /etc/ssh/ssh_host_dsa_key  
  28.   
  29. # Lifetime and size of ephemeral version 1 server key  
  30. #KeyRegenerationInterval 1h  
  31. #ServerKeyBits 1024  
  32.   
  33. # Logging  
  34. # obsoletes QuietMode and FascistLogging  
  35. #SyslogFacility AUTH  
  36. SyslogFacility AUTHPRIV  
  37. #LogLevel INFO  
  38.   
  39. # Authentication:  
  40.   
  41. #LoginGraceTime 2m  
  42. #PermitRootLogin yes  
  43. #StrictModes yes  
  44. #MaxAuthTries 6  
  45. #MaxSessions 10  
  46.   
  47. #RSAAuthentication yes  
  48. #PubkeyAuthentication yes  
  49. #AuthorizedKeysFile .ssh/authorized_keys  
  50. #AuthorizedKeysCommand none  
  51. #AuthorizedKeysCommandRunAs nobody  
  52.   
  53. # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts  
  54. #RhostsRSAAuthentication no  
  55. # similar for protocol version 2  
  56. #HostbasedAuthentication no  
  57. # Change to yes if you don't trust ~/.ssh/known_hosts for  
  58. # RhostsRSAAuthentication and HostbasedAuthentication  
  59. #IgnoreUserKnownHosts no  
  60. # Don't read the user's ~/.rhosts and ~/.shosts files  
  61. #IgnoreRhosts yes  
  62.   
  63. # To disable tunneled clear text passwords, change to no here!  
  64. #PasswordAuthentication yes  
  65. #PermitEmptyPasswords no  
  66. PasswordAuthentication yes  
  67.   
  68. # Change to no to disable s/key passwords  
  69. #ChallengeResponseAuthentication yes  
  70. ChallengeResponseAuthentication no  
  71.   
  72. # Kerberos options  
  73. #KerberosAuthentication no  
  74. #KerberosOrLocalPasswd yes  
  75. #KerberosTicketCleanup yes  
  76. #KerberosGetAFSToken no  
  77.   
  78. # GSSAPI options  
  79. #GSSAPIAuthentication no  
  80. GSSAPIAuthentication yes  
  81. #GSSAPICleanupCredentials yes  
  82. GSSAPICleanupCredentials yes  
  83. #GSSAPIStrictAcceptorCheck yes  
  84. #GSSAPIKeyExchange no  
  85.   
  86. # Set this to 'yes' to enable PAM authentication, account processing,   
  87. # and session processing. If this is enabled, PAM authentication will   
  88. # be allowed through the ChallengeResponseAuthentication and  
  89. # PasswordAuthentication.  Depending on your PAM configuration,  
  90. # PAM authentication via ChallengeResponseAuthentication may bypass  
  91. # the setting of "PermitRootLogin without-password".  
  92. # If you just want the PAM account and session checks to run without  
  93. # PAM authentication, then enable this but set PasswordAuthentication  
  94. # and ChallengeResponseAuthentication to 'no'.  
  95. #UsePAM no  
  96. UsePAM yes  
  97.   
  98. # Accept locale-related environment variables  
  99. AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES  
  100. AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT  
  101. AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE  
  102. AcceptEnv XMODIFIERS  
  103.   
  104. #AllowAgentForwarding yes  
  105. #AllowTcpForwarding yes  
  106. #GatewayPorts no  
  107. #X11Forwarding no  
  108. X11Forwarding yes  
  109. #X11DisplayOffset 10  
  110. #X11UseLocalhost yes  
  111. #PrintMotd yes  
  112. #PrintLastLog yes  
  113. #TCPKeepAlive yes  
  114. #UseLogin no  
  115. #UsePrivilegeSeparation yes  
  116. #PermitUserEnvironment no  
  117. #Compression delayed  
  118. #ClientAliveInterval 0  
  119. #ClientAliveCountMax 3  
  120. #ShowPatchLevel no  
  121. #UseDNS yes  
  122. #PidFile /var/run/sshd.pid  
  123. #MaxStartups 10  
  124. #PermitTunnel no  
  125. #ChrootDirectory none  
  126.   
  127. # no default banner path  
  128. #Banner none  
  129.   
  130. # override default of no subsystems  
  131. Subsystem   sftp    /usr/libexec/openssh/sftp-server  
  132.   
  133. # Example of overriding settings on a per-user basis  
  134. #Match User anoncvs  
  135. #   X11Forwarding no  
  136. #   AllowTcpForwarding no  
  137. #   ForceCommand cvs server  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值