sshd_config配置说明(顺序来自CentOS)

推荐使用man sshd_config指令获取配置文件详细说明

Port 22                           
AddressFamily any
ListenAddress 0.0.0.0
ListenAddress ::
Protocol 2
/*
Port:sshd服务端口,预设22,也可以开放多个端口
AddressFamily:使用地址族,any(默认)、inet(仅IPv4)、inet6(仅IPv6)
ListenAddress:设置监听的地址
Protocol:SSH协议版本
*/
# HostKey for protocol version 1
HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
/*
主机私钥存放位置
*/
KeyRegenerationInterval 1h
ServerKeyBits 1024
/*
对于SSH-1协议中秘钥的过期时间和大小
*/
# Logging
SyslogFacility AUTH
SyslogFacility AUTHPRIV
LogLevel INFO
/*
SyslogFacility:日志系统选择
LogLevel:日志等级选择
*/
# Authentication:
LoginGraceTime 2m
PermitRootLogin yes
StrictModes yes
MaxAuthTries 6
MaxSessions 10
/*
LoginGraceTime:限制认证时限
PermitRootLogin:允许ROOT账户登录
StrictModes:检查用户主目录和相关的配置文件
MaxAuthTries:最大认证次数
MaxSessions:最大保持连接数
*/
RSAAuthentication yes
PubkeyAuthentication yes

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile .ssh/authorized_keys
/*
RSAAuthentication:SSH-1公钥认证
PubkeyAuthentication:SSH-2公钥认证
AuthorizedKeysFile:授权秘钥文件
*/
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
/*
RhostsRSAAuthentication:SSH-1强可信主机
HostbasedAuthentication:SSH-2强可信主机
IgnoreUserKnownHosts:认证过程中忽略用户的 ~/.ssh/known_hosts 文件
IgnoreRhosts:认证过程中忽略 .rhosts 和 .shosts 文件
*/
# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication yes
PermitEmptyPasswords no
/*
PasswordAuthentication:使用密码认证
PermitEmptyPasswords:允许密码为空账户登录
*/
# Change to no to disable s/key passwords
ChallengeResponseAuthentication yes
/*
ChallengeResponseAuthentication:是否允许质疑-应答(challenge-response)认证
*/
# Kerberos options
KerberosAuthentication no
KerberosOrLocalPasswd yes
KerberosTicketCleanup yes
KerberosGetAFSToken no
/*
KerberosAuthentication:是否使用Kerberos认证
KerberosOrLocalPasswd:如果 Kerberos 密码认证失败,那么该密码还将要通过其它的认证机制
KerberosTicketCleanup:是否在用户退出登录后自动销毁用户的 ticket
KerberosGetAFSToken:尝试获取一个 AFS token
*/
# GSSAPI options
GSSAPIAuthentication yes
GSSAPICleanupCredentials no
GSSAPIStrictAcceptorCheck yes
/*
GSSAPIAuthentication:是否允许使用基于 GSSAPI 的用户认证
GSSAPICleanupCredentials:是否在用户退出登录后自动销毁用户凭证缓存
GSSAPIStrictAcceptorCheck:是否严格检查GSSAPI的用户认证
*/
# 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'.
# WARNING: 'UsePAM no' is not supported in Red Hat Enterprise Linux and may cause several
# problems.
UsePAM yes
/*
UsePAM:是否使用PAM认证登录
*/
AllowAgentForwarding yes
AllowTcpForwarding yes
GatewayPorts no
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost yes
PermitTTY yes
PrintMotd yes
PrintLastLog yes
TCPKeepAlive yes
UseLogin no
UsePrivilegeSeparation sandbox      # Default for new installations.
PermitUserEnvironment no
Compression delayed
ClientAliveInterval 0
ClientAliveCountMax 3
ShowPatchLevel no
UseDNS yes
PidFile /var/run/sshd.pid
MaxStartups 10:30:100
PermitTunnel no
ChrootDirectory none
VersionAddendum none
/*
AllowAgentForwarding:是否允许转发ssh-agent
AllowTcpForwarding:是否允许TCP转发
GatewayPorts:是否允许远程主机连接本地的转发端口
X11Forwarding:是否允许进行 X11 转发
X11DisplayOffset:指定X11 转发的第一个可用的显示区(display)数字
X11UseLocalhost:是否应当将X11转发服务器绑定到本地loopback地址
PermitTTY:是否允许pty分配
PrintMotd:是否在每一次交互式登录时打印 /etc/motd 文件的内容
PrintLastLog:是否在每一次交互式登录时打印最后一位用户的登录时间
TCPKeepAlive:是否向客户端发送 TCP keepalive 消息
UseLogin:是否在交互式会话的登录过程中使用 login
UsePrivilegeSeparation:是否让 sshd 通过创建非特权子进程处理接入请求的方法来进行权限分离
PermitUserEnvironment:是否允许 sshd处理environment
Compression:是否对通信数据进行加密
ClientAliveInterval:设置一个以秒记的时长,向客户端发送一个”alive”消息,并等候应答
ClientAliveCountMax:sshd 在未收到任何客户端回应前最多允许发送多少个”alive”消息
ShowPatchLevel:是否显示ssh的补丁信息
UseDNS:是否应该对远程主机名进行反向解析
PidFile:pid文件位置
MaxStartups: 指定并发未认证的最大数量节点到SSH守护进程
PermitTunnel:是否允许 tun 设备转发
ChrootDirectory:指定chroot认证的路径名
VersionAddendum:连接时指定附加文本
*/
# no default banner path
Banner none
/*
Banner:将这个指令指定的文件中的内容在用户进行认证前显示给远程用户
*/
# 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
/*
AcceptEnv:指定客户端发送的哪些环境变量将会被传递到会话环境中
*/
# override default of no subsystems
Subsystem sftp  /usr/libexec/openssh/sftp-server
/*
Subsystem:配置一个外部子系统
*/
NOTE

1、 以上的所有说明配置命令均已去掉‘#’(注释符号),请勿直接copy使用
2、 在修改sshd_config文件时,正确的姿势应该是在原配置文件中找到相关配置添加‘#’注释,再在文件末尾添加配置命令及选项
3、以上内容并不完全来自于自己翻译,有部分摘自网络内容,如有侵权行为,请告知E-mail:gaohanxiang@126.com,本人会第一时间删除

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,711评论 5 468
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,932评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,770评论 0 330
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,799评论 1 271
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,697评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,069评论 1 276
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,535评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,200评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,353评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,290评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,331评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,020评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,610评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,694评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,927评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,330评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,904评论 2 341

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,563评论 18 139
  • linux资料总章2.1 1.0写的不好抱歉 但是2.0已经改了很多 但是错误还是无法避免 以后资料会慢慢更新 大...
    数据革命阅读 12,127评论 2 34
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,713评论 6 342
  • 结构化数据:能够用数据或统一的结构加以表示的信息,如数字、符号。在项目中,保存和管理这些的数据一般为关系数据...
    godhong阅读 1,614评论 0 1
  • 柳江,我第一次听闻这个古镇名字,还是通过电视得知,很多年前。吊脚楼,黄角树,还有那条河,以及镜头里那一群踏...
    應緣茶仁阅读 288评论 3 5