zoukankan      html  css  js  c++  java
  • ssh配置含义解释

    ssh包括客户端配置(ssh_config)和服务端配置(sshd_config)

    一、客户端配置ssh_config,客户端软件有SecureCRT、putty、Xshell

    “#”表示注释,虽然表示不起作用,但有时说明此为系统默认的初始化设置

    #    $OpenBSD: ssh_config,v 1.25 2009/02/17 01:28:32 djm Exp $
    
    # This is the ssh client system-wide configuration file.  See
    # ssh_config(5) for more information.  This file provides defaults for
    # users, and the values can be changed in per-user configuration files
    # or on the command line.
    
    # Configuration data is parsed as follows:
    #  1. command line options
    #  2. user-specific file
    #  3. system-wide file
    # Any configuration value is only changed the first time it is set.
    # Thus, host-specific definitions should be at the beginning of the
    # configuration file, and defaults at the end.
    
    # Site-wide defaults for some commonly used options.  For a comprehensive
    # list of available options, their meanings and defaults, please see the
    # ssh_config(5) man page.
    
    "Host"只对匹配后面字串的计算机有效,“*”表示所有的计算机。从该项格式前置一些可以看出,这是一个类似于全局的选项,表示下面缩进的选项都适用于该设置,可以指定某计算机替换*号使下面选项只针对该算机器生效。
    # Host *
    设置连接是否经过验证代理(如果存在)转发给远程计算机
    # ForwardAgent no
    置X11连接是否被自动重定向到安全的通道和显示集(DISPLAY set)
    # ForwardX11 no
    设置是否使用用RSA算法的基于rhosts的安全验证
    #
    RhostsRSAAuthentication no
    设置是否使用RSA算法进行安全验证 # RSAAuthentication yes
    设置是否使用口令验证
    # PasswordAuthentication yes # HostbasedAuthentication no # GSSAPIAuthentication no # GSSAPIDelegateCredentials no # GSSAPIKeyExchange no # GSSAPITrustDNS no
    批处理模式,一般设为"no";如果设为"yes",交互式输入口令的提示将被禁止,这个选项对脚本文件和批处理任务十分有用
    # BatchMode no
    设置ssh是否查看连接到服务器的主机的IP地址以防止DNS欺骗。建议设置为"yes"。
    # CheckHostIP yes # AddressFamily any # ConnectTimeout 0
    如果设为"yes",ssh将不会自动把计算机的密匙加入"$HOME/.ssh/known_hosts"文件,且一旦计算机的密匙发生了变化,就拒绝连接
    # StrictHostKeyChecking ask
    设置读取用户的RSA安全验证标识
    # IdentityFile ~/.ssh/identity # IdentityFile ~/.ssh/id_rsa # IdentityFile ~/.ssh/id_dsa
    设置连接到远程主机的端口,ssh默认端口为22
    # Port 22 # Protocol 2,1
    设置加密用的密钥,blowfish可以自己随意设置
    # Cipher 3des # Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc # MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160
    设置escape字符
    # EscapeChar ~ # Tunnel no # TunnelDevice any:any # PermitLocalCommand no # VisualHostKey no Host * GSSAPIAuthentication yes # If this option is set to yes then remote X11 clients will have full access # to the original X11 display. As virtually no X11 client supports the untrusted # mode correctly we set this to yes. ForwardX11Trusted yes # Send locale-related environment variables SendEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES SendEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT SendEnv LC_IDENTIFICATION LC_ALL LANGUAGE SendEnv XMODIFIERS

    二、服务端配置sshd_config

    #    $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $
    
    # This is the sshd server system-wide configuration file.  See
    # sshd_config(5) for more information.
    
    # This sshd was compiled with PATH=/usr/local/bin:/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 change a
    # default value.
    #############1. 关于 SSH Server 的整体设定##############
    设置sshd监听的端口号,了安全起见,建议更改默认的22端口为5位以上陌生端口 #Port 22 #AddressFamily any
    设置sshd服务器绑定的IP地址,默认所有ip
    #ListenAddress 0.0.0.0 #ListenAddress :: # Disable legacy (protocol version 1) support in the server for new # installations. In future the default will change to require explicit # activation of protocol 1
    ssh1和ssh2,ssh1是不安全的
    Protocol 2 #############2. 说明主机的 Private Key 放置的档案########## # HostKey for protocol version 1
    设置ssh1密匙文件位置
    #HostKey /etc/ssh/ssh_host_key # HostKeys for protocol version 2
    设置ssh2密钥文件位置 #
    HostKey /etc/ssh/ssh_host_rsa_key #HostKey /etc/ssh/ssh_host_dsa_key # Lifetime and size of ephemeral version 1 server key
    设置在多少秒之后自动重新生成服务器的密匙(如果使用密匙)。重新生成密匙是为了防止用盗用的密匙解密被截获的信息
    #KeyRegenerationInterval 1h
    定义服务器密匙的位数
    #ServerKeyBits 1024 # Logging # obsoletes QuietMode and FascistLogging
    设置在记录来自sshd的消息的时候,是否给出“facility code”
    #SyslogFacility AUTH SyslogFacility AUTHPRIV
    设置记录sshd日志消息的层次。INFO是一个好的选择。查看sshd的man帮助页,获取更多的信息
    #LogLevel INFO #################3.安全认证方面的设定################
    #############3.1、有关安全登录的设定###############
    限制用户必须在指定的时限内认证成功,0 表示无限制。默认值是 120 秒 # Authentication: 设置如果用户不能成功登录,在切断连接之前服务器需要等待的时间(以秒为单位) #LoginGraceTime 2m
    设置是否允许root通过ssh登录。这个选项从安全角度来讲应设成"no"
    #PermitRootLogin yes
    设置ssh在接收登录请求之前是否检查用户家目录和rhosts文件的权限和所有权。这通常是必要的,因为新手经常会把自己的目录和文件设成任何人都有写权限
    #StrictModes yes
    设置客户端登录失败允许次数
    #MaxAuthTries 6
    设置允许客户端同时连接的个数
    #MaxSessions 10 用来设置是否开启RSA密钥验证,只针对SSH1 #RSAAuthentication yes
    用来设置是否开启公钥验证,如果使用公钥验证的方式登录时,则设置为yes
    #PubkeyAuthentication yes
    用来设置公钥验证文件的路径,与PubkeyAuthentication配合使用,默认值是".ssh/authorized_keys"
    #AuthorizedKeysFile .ssh/authorized_keys #AuthorizedKeysCommand none #AuthorizedKeysCommandRunAs nobody
    #############3.2、安全验证的设定############### # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
    设置是否允许用rhosts或“/etc/hosts.equiv”加上RSA进行安全验证
    是否使用强可信主机认证(通过检查远程主机名和关联的用户名进行认证)。仅用于SSH-1。这是通过在RSA认证成功后再检查 ~/.rhosts 或 /etc/hosts.equiv 进行认证的。出于安全考虑,建议使用默认值"no"。
    #RhostsRSAAuthentication no # similar for protocol version 2
    这个指令与 RhostsRSAAuthentication 类似,但是仅可以用于SSH-2。
    #HostbasedAuthentication no # Change to yes if you don't trust ~/.ssh/known_hosts for # RhostsRSAAuthentication and HostbasedAuthentication
    设置ssh daemon是否在进行RhostsRSAAuthentication安全验证的时候忽略用户的"$HOME/.ssh/known_hosts”
    #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
    设置是否允许用口令为空的帐号登录
    #PermitEmptyPasswords no PasswordAuthentication yes # Change to no to disable s/key passwords #ChallengeResponseAuthentication yes
    是否允许质疑-应答(challenge-response)认证
    ChallengeResponseAuthentication no ########3.3、与 Kerberos 有关的参数设定,指定是否允许基于Kerberos的用户认证######## # Kerberos options
    是否要求用户为PasswdAuthentication提供的密码必须通过Kerberos KDC认证,要使用Kerberos认证,服务器必须提供一个可以校验KDC identity的Kerberos servtab。默认值为no
    #KerberosAuthentication no
    如果Kerberos密码认证失败,那么该密码还将要通过其他的的认证机制,如/etc/passwd
    #KerberosOrLocalPasswd yes
    设置是否在用户退出登录是自动销毁用户的ticket
    #KerberosTicketCleanup yes
    如果使用AFS并且该用户有一个Kerberos 5 TGT,那么开启该指令后,将会在访问用户的家目录前尝试获取一个AFS token,并尝试传送 AFS token 给 Server 端,默认为no
    #KerberosGetAFSToken no #KerberosUseKuserok yes
    ####3.4、与 GSSAPI 有关的参数设定,指定是否允许基于GSSAPI的用户认证,仅适用于SSH2####
    GSSAPI 是一套类似 Kerberos 5 的通用网络安全系统接口。如果你拥有一套 GSSAPI库,就可以通过 tcp 连接直接建立 cvs 连接,由 GSSAPI 进行安全鉴别 # GSSAPI options
    指定是否允许基于GSSAPI的用户认证,默认为no
    #GSSAPIAuthentication no #GSSAPIAuthentication yes
    设置是否在用户退出登录是自动销毁用户的凭证缓存
    #GSSAPICleanupCredentials yes GSSAPICleanupCredentials yes #GSSAPIStrictAcceptorCheck yes #GSSAPIKeyExchange 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". # 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'.
    设置是否通过PAM验证
    #UsePAM no UsePAM yes AcceptEnv 指定客户端发送的哪些环境变量将会被传递到会话环境中。[注意]只有SSH-2协议支持环境变量的传递。指令的值是空格分隔的变量名列表(其中可以使用'*'和'?'作为通配符)。
    也可以使用多个 AcceptEnv 达到同样的目的。需要注意的是,有些环境变量可能会被用于绕过禁止用户使用的环境变量。由于这个原因,该指令应当小心使用。默认是不传递任何环境变量
    # Accept locale-related environment variables AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE AcceptEnv XMODIFIERS #AllowAgentForwarding yes
    设置是否允许允许tcp端口转发,保护其他的tcp连接
    #AllowTcpForwarding yes
    设置是否允许远程客户端使用本地主机的端口转发功能,出于安全考虑,建议禁止
    #GatewayPorts no
    #############3.5、X-Window下使用的相关设定###############
    设置是否允许X11转发
    #X11Forwarding no X11Forwarding yes
    指定X11 转发的第一个可用的显示区(display)数字。默认值是 10 。可以用于防止 sshd 占用了真实的 X11 服务器显示区,从而发生混淆
    #X11DisplayOffset 10 #X11UseLocalhost yes
    设置sshd是否在用户登录的时候显示“/etc/motd”中的信息

    #################3.6、登入后的相关设定#################
    用来设置sshd是否在用户登录时显示“/etc/motd”中的信息,可以选在在“/etc/motd”中加入警告的信息
    #PrintMotd yes
    是否显示上次登录信息
    #PrintLastLog yes
    是否持续连接,设置yes可以防止死连接,一般而言,如果设定这项的话,那么 SSH Server 会传送 KeepAlive 的讯息给 Client 端,以确保两者的联机正常!
    这种消息可以检测到死连接、连接不当关闭、客户端崩溃等异常。在这个情况下,任何一端死掉后, SSH 可以立刻知道,而不会有僵尸程序的发生!
    #TCPKeepAlive yes
    设置是否在交互式会话的登录过程中使用。默认值是"no",如果开启此指令,那么X11Forwarding 将会被禁止,因为login不知道如何处理 xauth cookies 。
    需要注意的是,在SSH底下本来就不接受 login 这个程序的登入,如果指UsePrivilegeSeparation ,那么它将在认证完成后被禁用
    #UseLogin no
    设置使用者的权限
    #UsePrivilegeSeparation yes #PermitUserEnvironment no #Compression delayed #ClientAliveInterval 0 #ClientAliveCountMax 3 #ShowPatchLevel no
    通常情况下我们在连接 OpenSSH服务器的时候假如 UseDNS选项是打开的话,服务器会先根据客户端的 IP地址进行 DNS PTR反向查询出客户端的主机名,然后根据查询出的客户端主机名进行DNS正向A记录查询,
    并验证是否与原始 IP地址一致,通过此种措施来防止客户端欺骗。平时我们都是动态 IP不会有PTR记录,所以打开此选项也没有太多作用。我们可以通过关闭此功能来提高连接 OpenSSH 服务器的速度
    UseDNS no #PidFile /var/run/sshd.pid
    设置同时允许几个尚未登入的联机,当用户连上ssh但并未输入密码即为所谓的联机,在这个联机中,为了保护主机,所以需要设置最大值,预设为10个,而已经建立联机的不计算入内,
    所以一般5个即可,这个设置可以防止恶意对服务器进行连接
    #MaxStartups 10:30:100 #PermitTunnel no #ChrootDirectory none

    ############3.7、开放禁止用户设定############

    当只有AllowUsers选项时,是白名单机制,只有允许的用户可以登录;当同时存在AllowUsers和DenyUsers时,是黑名单机制,只要用户不在黑名单里,都是可以登录的;两个选项都没有时,任何用户都可以登录

    #AllowUsers<用户名1> <用户名2> <用户名3> ...
    ##指定允许通过远程访问的用户,多个用户以空格隔开

    #AllowGroups<组名1> <组名2> <组名3> ...
    ##指定允许通过远程访问的组,多个组以空格隔开。当多个用户需要通过ssh登录系统时,可将所有用户加入一个组中。

    #DenyUsers<用户名1> <用户名2> <用户名3> ...
    ##指定禁止通过远程访问的用户,多个用户以空格隔开

    #DenyGroups<组名1> <组名2> <组名3> ...
    ##指定禁止通过远程访问的组,多个组以空格隔开。


    # no default banner path

    设置登录时提示信息,首先编辑一个文件,如bannertest.txt,文件内容自行定义。然后打开/etc/ssh/sshd_config文件并查找下面这样的行:#Banner /some/path将#号去掉,然后将bannertest.txt文件的全路径替换/some/path,然后保存,重启ssh服务。当客户端登录时,就会看到bannertest.txt文件中的提示信息
     #Banner none

    # override default of no subsystems
    Subsystem    sftp    /usr/libexec/openssh/sftp-server
    
    # Example of overriding settings on a per-user basis
    #Match User anoncvs
    #    X11Forwarding no
    #    AllowTcpForwarding no
    #    ForceCommand cvs server

    三、相关命令行

    service ssh status
    ssh: unrecognized service
    # service sshd status
    openssh-daemon (pid  13237) is running...
    # /etc/init.d/sshd status
    openssh-daemon (pid  13237) is running...
    # /etc/init.d/sshd -h
    Usage: /etc/init.d/sshd {start|stop|restart|reload|force-reload|condrestart|try-restart|status}
    # service sshd -h
    Usage: service < option > | --status-all | [ service_name [ command | --full-restart ] ]
    # service sshd st
    Usage: /etc/init.d/sshd {start|stop|restart|reload|force-reload|condrestart|try-restart|status}

    那么要先生成两个密钥:

    #ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key

    #ssh-keygen -t dsa -f /etc/ssh/ssh_host_rsa_key

    执行命令后都会让输入密码,直接敲回车设置为空即可

    参考:

    1、http://blog.csdn.net/field_yang/article/details/51568861

  • 相关阅读:
    JS中的call()和apply()方法
    jQuery的deferred对象详解
    浅谈postMessage多页面监听事件
    js 的try catch
    浅谈JavaScript DOM编程艺术读后感和一点总结
    人人都看得懂的正则表达式教程
    JavaScript面向对象精要
    配置Tomcat配置路径
    IOS, Android, Java Web Rest : RSA 加密和解密问题
    说说secondarynamenode作用和配置
  • 原文地址:https://www.cnblogs.com/shengulong/p/7567322.html
Copyright © 2011-2022 走看看