[关闭]
@mrz1 2018-01-09T09:24:23.000000Z 字数 3592 阅读 3764

SSH远程登录配置文件sshd_config详解

服务


/etc/ssh/sshd_config
man sshd_config 帮助

  1. [root@centos7 ~]#cat /etc/ssh/sshd_config
  2. #Port 22 //这个是ssh服务的监听端口,在实际生产环境中一般都不用默认的22端口
  3. #AddressFamily any //any默认ipv4 ipv6
  4. #ListenAddress 0.0.0.0
  5. #ListenAddress ::
  6. ListenAddress用来设置sshd服务器绑定的IP地址;监听的主机适配卡,举个例子来说,如果您有两个 IP 分别是 192.168.0.11 192.168.2.20 那么只想要开放192.168.0.11时,就可以设置为:ListenAddress 192.168.0.11表示只监听来自 192.168.0.11 这个 IP SSH联机。如果不使用设定的话,则预设所有接口均接受 SSH
  7. HostKey /etc/ssh/ssh_host_rsa_key 使用的 RSA 私钥
  8. HostKey /etc/ssh/ssh_host_ecdsa_key
  9. HostKey /etc/ssh/ssh_host_ed25519_key
  10. # Logging
  11. #SyslogFacility AUTH
  12. SyslogFacility AUTHPRIV 日志
  13. #LogLevel INFO
  14. # Authentication:
  15. #LoginGraceTime 2m 宽限登录时间不输入密码两分钟自动退出
  16. #PermitRootLogin yes 改为no 是不让root连接(登录普通用户在切换到root可以)
  17. #StrictModes yes 检查.ssh/文件的所有者,权限等
  18. #MaxAuthTries 6 最大认证次数的一般6/2=3
  19. #MaxSessions 10 克隆会话最大连接
  20. #PubkeyAuthentication yes 支持公钥验证(一般开启公钥验证关闭用户登录)
  21. # The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
  22. # but this is overridden so installations will only check .ssh/authorized_keys
  23. AuthorizedKeysFile .ssh/authorized_keys
  24. #AuthorizedPrincipalsFile none
  25. #AuthorizedKeysCommand none
  26. #AuthorizedKeysCommandUser nobody
  27. # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
  28. #HostbasedAuthentication no
  29. # Change to yes if you don't trust ~/.ssh/known_hosts for
  30. # HostbasedAuthentication
  31. #IgnoreUserKnownHosts no
  32. # Don't read the user's ~/.rhosts and ~/.shosts files
  33. #IgnoreRhosts yes
  34. # To disable tunneled clear text passwords, change to no here!
  35. #PasswordAuthentication yes
  36. #PermitEmptyPasswords no (允许空口令吗) 拒绝用户登录(一般开启公钥验证关闭用户登录)
  37. PasswordAuthentication yes
  38. # Change to no to disable s/key passwords
  39. #ChallengeResponseAuthentication yes
  40. ChallengeResponseAuthentication no
  41. # Kerberos options
  42. #KerberosAuthentication no
  43. #KerberosOrLocalPasswd yes
  44. #KerberosTicketCleanup yes
  45. #KerberosGetAFSToken no
  46. #KerberosUseKuserok yes
  47. # GSSAPI options
  48. GSSAPIAuthentication yes//这里改为no 是让连接速度 加快
  49. GSSAPICleanupCredentials no
  50. #GSSAPIStrictAcceptorCheck yes
  51. #GSSAPIKeyExchange no
  52. #GSSAPIEnablek5users no
  53. # Set this to 'yes' to enable PAM authentication, account processing,
  54. # and session processing. If this is enabled, PAM authentication will
  55. # be allowed through the ChallengeResponseAuthentication and
  56. # PasswordAuthentication. Depending on your PAM configuration,
  57. # PAM authentication via ChallengeResponseAuthentication may bypass
  58. # the setting of "PermitRootLogin without-password".
  59. # If you just want the PAM account and session checks to run without
  60. # PAM authentication, then enable this but set PasswordAuthentication
  61. # and ChallengeResponseAuthentication to 'no'.
  62. # WARNING: 'UsePAM no' is not supported in Red Hat Enterprise Linux and may cause several
  63. # problems.
  64. UsePAM no
  65. #AllowAgentForwarding yes
  66. #AllowTcpForwarding yes
  67. #GatewayPorts no (网关)
  68. X11Forwarding yes
  69. #X11DisplayOffset 10
  70. #X11UseLocalhost yes
  71. #PermitTTY yes
  72. #PrintMotd yes
  73. #PrintLastLog yes
  74. #TCPKeepAlive yes
  75. #UseLogin no
  76. #UsePrivilegeSeparation sandbox
  77. #PermitUserEnvironment no
  78. #Compression delayed
  79. #ClientAliveInterval 30 (没操作的话30秒一到就断开连接)
  80. #ClientAliveCountMax 0(没操作的话30秒一到就断开连接)
  81. #ShowPatchLevel no
  82. #UseDNS yes //这里改为no 是让连接速度 加快
  83. #PidFile /var/run/sshd.pid //运行的服务编号
  84. #MaxStartups 10:30:100 //当连接数超过10会以30%的失败率拒绝用户登录(达到100,100%拒绝)
  85. #PermitTunnel no
  86. #ChrootDirectory none
  87. #VersionAddendum none
  88. # no default banner path
  89. #Banner none //ssh登录提示信息
  90. Banner /etc/ssh/banner.txt //ssh登录读取内容
  91. # Accept locale-related environment variables
  92. AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
  93. AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
  94. AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
  95. AcceptEnv XMODIFIERS
  96. AllowUsers wang //默认没这一行添加 只允许网用户登录(包括root)白名单
  97. DenyUsers 黑名单(优先级高)
  98. AllowGroups
  99. DenyGroups
  100. # override default of no subsystems
  101. Subsystem sftp /usr/libexec/openssh/sftp-server
  102. # Example of overriding settings on a per-user basis
  103. #Match User anoncvs
  104. # X11Forwarding no
  105. # AllowTcpForwarding no
  106. # PermitTTY no
  107. # ForceCommand cvs server

tail /var/log/secure 查看日志

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注