CentOS 7 下/etc/ssh/sshd_config 文件详解

SSH由客户端和服务端的软件组成,在客户端可以使用的软件有SecureCRT、putty、Xshell等,而在服务器端运行的是一个sshd的服务,通过使用SSH,可以把所有传输的数据进行加密,而且也能够防止dns和IP欺骗,此外,SSH传输的数据是经过压缩的,可以加快传输速度,其服务器端的配置文件为/etc/ssh/sshd_config。以下为sshd_config学习记录。

[root@localhost ~]# cat /etc/ssh/sshd_config#       $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $# This is the sshd server system-wide configuration file.  See# sshd_config(5) for more information.    # 这是 sshd 服务器系统范围的配置文件。 有关更多信息,请参见sshd_config(5)。   # This sshd was compiled with PATH=/usr/local/bin:/usr/bin    # 这个 sshd 是用 PATH=/usr/local/bin:/usr/bin 编译的。# The strategy used for options in the default sshd_config shipped with# OpenSSH is to specify options with their default value where# possible, but leave them commented.  Uncommented options override the# default value.# 用于 OpenSSH 附带的默认sshd_config中的选项的策略是在可能的情况下使用默认值指定选项,但保留注释。 未注释的选项将覆盖默认值。# If you want to change the port on a SELinux system, you have to tell# SELinux about this change.# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER# 如果要更改 SELinux 系统上的端口,则必须将此更改告知 SELinux。# 1、关于 SSH Server 的整体设定,包含使用的 port 、ip地址#Port 22                    # SSH 预设使用 22 这个 port,也可以使用其他 port#AddressFamily any#ListenAddress 0.0.0.0     #ListenAddress ::          # 监听的主机适配卡!举个例子来说,如果您有两个 IP,              # 分别是 192.168.0.100 及 192.168.2.20 ,那么只想要开放 192.168.0.100 时,              # 就可以写如同下面的样式:ListenAddress 192.168.0.100                           # 只监听来自 192.168.0.100 这个 IP 的SSH联机,如果不使用设定的话,则预设所有接口均接受 SSH# 2. 说明主机的 Private Key 放置的档案,预设使用下面的档案即可!HostKey /etc/ssh/ssh_host_rsa_key            # SSH version 2 使用的 RSA 私钥#HostKey /etc/ssh/ssh_host_dsa_key           # SSH version 2 使用的 DSA 私钥HostKey /etc/ssh/ssh_host_ecdsa_key          #用ecdsa加密方式生成ssh密钥HostKey /etc/ssh/ssh_host_ed25519_key        #用ed25519加密方式生成ssh密钥# Ciphers and keying            #密码和密钥#RekeyLimit default none# 3. 关于登录文件的讯息数据放置与 daemon 的名称!# Logging#SyslogFacility AUTH                 # 当有人使用 SSH 登入系统的时候,SSH会记录资讯,这个信息要记录在什么 daemon name 底下?                   # 预设是以 AUTH 来设定的,即是 /var/log/secure 里面!                   # 其它可用的 daemon name 为:DAEMON,USER,AUTH,LOCAL0,LOCAL1,LOCAL2,LOCAL3,LOCAL4,LOCAL5,SyslogFacility AUTHPRIV#LogLevel INFO                       # 记录登录的等级!任何信息!# 4. 安全设定项目!重要!# Authentication:     # 认证:# 4.1 登入设定部分#LoginGraceTime 2mPermitRootLogin no    # PermitRootLogin参数指定root用户是否可以使用ssh登录。 建议设置为 no。#StrictModes yes      # 当使用者的 host key 改变之后,Server 就不接受联机,可以抵挡部分的木马程序!MaxAuthTries 4        # MaxAuthTries参数指定每个连接允许的最大验证尝试次数。 当登录失败次数达到设置的一半时,错误消息将被写入syslog文件详细记录登录失败。#MaxSessions 10       # 最大会话数#PubkeyAuthentication yes    # 公钥身份验证,默认yes。# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2    # 默认设置是同时选中两者 .ssh/authorized_keys 和 .ssh/authorized_keys2# but this is overridden so installations will only check .ssh/authorized_keys   # 但这被覆盖,因此安装只会检查 .ssh/authorized_keysAuthorizedKeysFile      .ssh/authorized_keys                                     # 授权密钥文件  .ssh/authorized_keys#AuthorizedPrincipalsFile none           # 授权主体文件 none#AuthorizedKeysCommand none              # 授权密钥命令 none#AuthorizedKeysCommandUser nobody        # 授权密钥命令用户 nobody# 4.2 认证部分# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts    # 为此,您还需要 /etc/ssh/ssh_known_hosts 中的主机密钥#HostbasedAuthentication no    # 基于主机的身份验证,HostbasedAuthentication参数指定身份验证是否允许。默认值为 no。# Change to yes if you don't trust ~/.ssh/known_hosts for          # 如果您不信任 ~/.ssh/known_hosts 的 Hostbased身份验证,请更改为 yes# HostbasedAuthentication#IgnoreUserKnownHosts no       # 忽略用户已知主机# Don't read the user's ~/.rhosts and ~/.shosts files             # 不要读取用户的 ~/.rhosts 和 ~/.shosts 文件#IgnoreRhosts yes              # 忽略主机# To disable tunneled clear text passwords, change to no here!    # 要禁用隧道明文密码,请在此处更改为否!PasswordAuthentication yes    # 密码身份验证,设置为yesPermitEmptyPasswords no       # 允许空密码,设置为no# Change to no to disable s/key passwords    # 更改为否以禁用 s/key 密码#ChallengeResponseAuthentication yes         # 质询响应身份验证ChallengeResponseAuthentication no# 4.3 与 Kerberos 有关的参数设定!没有 Kerberos 主机不用设定!# Kerberos options#KerberosAuthentication no#KerberosOrLocalPasswd yes#KerberosTicketCleanup yes#KerberosGetAFSToken no#KerberosUseKuserok yes# 与 GSSAPI 有关的参数设定,指定是否允许基于GSSAPI的用户认证,仅适用于SSH2,GSSAPI 是一套类似 Kerberos 5 的通用网络安全系统接口。# GSSAPI optionsGSSAPIAuthentication yes            # GSSAPI认证,指定是否允许基于GSSAPI的用户认证GSSAPICleanupCredentials no         # GSSAPI清理凭据,设置是否在用户退出登录是自动销毁用户的凭证缓存#GSSAPIStrictAcceptorCheck yes#GSSAPIKeyExchange no               # GSSAPI 密钥交换#GSSAPIEnablek5users no# Set this to 'yes' to enable PAM authentication, account processing,# and session processing. If this is enabled, PAM authentication will# be allowed through the ChallengeResponseAuthentication and# PasswordAuthentication.  Depending on your PAM configuration,# PAM authentication via ChallengeResponseAuthentication may bypass# the setting of "PermitRootLogin without-password".# 将其设置为“是”以启用 PAM 身份验证、帐户处理和会话处理。如果启用此功能,将允许通过质询响应身份验证和密码身份验证进行 PAM 身份验证。 # 根据您的 PAM 配置,通过 ChallengeResponseAuthentication 进行的 PAM 身份验证可能会绕过“PermitRootLogin without-password”的设置。# If you just want the PAM account and session checks to run without# PAM authentication, then enable this but set PasswordAuthentication# and ChallengeResponseAuthentication to 'no'.# WARNING: 'UsePAM no' is not supported in Red Hat Enterprise Linux and may cause several# problems.# 如果您只希望 PAM 帐户和会话检查在没有 PAM 身份验证的情况下运行,请启用此选项,#但将 PasswordAuthentication 和 ChallengeResponseAuthentication 设置为“no”。#警告:“UsePAM no”在 Red Hat Enterprise Linux 中不受支持,可能会导致多个问题。UsePAM yes    # 设置是否通过PAM验证#AllowAgentForwarding yes#AllowTcpForwarding yes    # 设置是否允许允许tcp端口转发,保护其他的tcp连接#GatewayPorts noX11Forwarding yes          # 设置是否允许X11转发#X11DisplayOffset 10#X11UseLocalhost yes#PermitTTY yes#PrintMotd yes        #PrintMotd 用来设置sshd是否在用户登录时显示“/etc/motd”中的信息,可以选在在“/etc/motd”中加入警告的信息#PrintLastLog yes     #PrintLastLog 是否显示上次登录信息#TCPKeepAlive yes     #TCPKeepAlive 是否持续连接,设置yes可以防止死连接                      #一般而言,如果设定这项目的话,那么 SSH Server 会传送 KeepAlive 的讯息给 Client 端,以确保两者的联机正常!                      #这种消息可以检测到死连接、连接不当关闭、客户端崩溃等异常。在这个情况下,任何一端死掉后, SSH 可以立刻知道,而不会有僵尸程序的发生!#UseLogin no    #UseLogin 设置是否在交互式会话的登录过程中使用。默认值是"no"。                # 如果开启此指令,那么X11Forwarding 将会被禁止,因为login不知道如何处理 xauth cookies 。                # 需要注意的是,在SSH底下本来就不接受 login 这个程序的登入,如果指UsePrivilegeSeparation ,那么它将在认证完成后被禁用。#UsePrivilegeSeparation sandbox#PermitUserEnvironment no#Compression delayedClientAliveInterval 300        # 客户端存活间隔,ClientAliveInterval变量设置时,在指定时间内没有活动的ssh会话将终止。ClientAliveCountMax 3          # 最大活动客户端计数,ClientAliveCountMax变量设置时,sshd将在每个ClientAliveInterval间隔发送客户端alive的消息。                                 sshd在未收到任何客户端回应前最多允许发送多少个"alive"消息,到达这个上限后ssh会话将被终止。                               # 例如,如果ClientAliveInterval设置为15,ClientAliveCountMax设置为3,那么无应答的客户端会在45秒后被强制断开。#ShowPatchLevel no#UseDNS yes                    # DNS解析,用ssh登录服务器,发现登录缓慢,可以设置为 no#PidFile /var/run/sshd.pid#MaxStartups 10:30:100#PermitTunnel no#ChrootDirectory none#VersionAddendum none# no default banner path#Banner none# Accept locale-related environment variables    # 接受与区域设置相关的环境变量AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGESAcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENTAcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGEAcceptEnv XMODIFIERS# AcceptEnv 指定客户端发送的哪些环境变量将会被传递到会话环境中。##注意:只有SSH-2协议支持环境变量的传递。指令的值是空格分隔的变量名列表(其中可以使用'*'和'?'作为通配符)。####也可以使用多个 AcceptEnv 达到同样的目的。需要注意的是,有些环境变量可能会被用于绕过禁止用户使用的环境变量。#####由于这个原因,该指令应当小心使用。默认是不传递任何环境变量。# override default of no subsystemsSubsystem       sftp    /usr/libexec/openssh/sftp-server# Example of overriding settings on a per-user basis#Match User anoncvs#       X11Forwarding no#       AllowTcpForwarding no#       PermitTTY no#       ForceCommand cvs server# 以下选项可用于限制哪些用户和组可以通过SSH访问系统。AllowUsers root user01        # AllowUsers变量为系统管理员提供允许特定用户通过ssh进入系统的选项。#AllowGroups       # AllowGroups变量为系统管理员提供允许特定用户组的用户通过ssh进入系统的选项。#DenyUsers          # DenyUsers变量为系统管理员提供拒绝特定用户通过ssh进入系统的选项。#DenyGroups        # DenyGroups变量为系统管理员提供拒绝特定用户组的用户通过ssh进入系统的选项。Ciphers aes256-ctr,aes192-ctr,aes128-ctr    # 此变量限制SSH在通信期间可以使用的密码类型。MACs hmac-sha2-512,hmac-sha2-256            # 此变量限制SSH在通信期间可以使用的MAC算法的类型。

参考连接:https://blog.51cto.com/lookingdream/1826618