sshd_config配置文件内容解析

文件内容

[root@kylin-v10 sysctl.d]# cat /etc/ssh/sshd_config  |grep -v '#' |grep -v "^$"
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
SyslogFacility AUTH
PermitRootLogin yes
AuthorizedKeysFile      .ssh/authorized_keys
PasswordAuthentication yes
ChallengeResponseAuthentication no
GSSAPIAuthentication yes
GSSAPICleanupCredentials no
UsePAM yes
X11Forwarding no
PrintMotd no
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
Subsystem sftp /usr/libexec/openssh/sftp-server -l INFO -f AUTH
Protocol 2
LogLevel VERBOSE
PubkeyAuthentication yes
RSAAuthentication yes
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no
PermitEmptyPasswords no
PermitUserEnvironment no
Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com
ClientAliveCountMax 0
Banner /etc/issue.net
MACs hmac-sha2-512,hmac-sha2-512-etm@openssh.com,hmac-sha2-256,hmac-sha2-256-etm@openssh.com
StrictModes yes
AllowTcpForwarding no
AllowAgentForwarding no
GatewayPorts no
PermitTunnel no
KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256
HostbasedAcceptedKeytypes ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,rsa-sha2-256,rsa-sha2-512
GSSAPIKexAlgorithms gss-group14-sha256-,gss-group16-sha512-,gss-curve25519-sha256-
CASignatureAlgorithms ssh-ed25519,sk-ssh-ed25519@openssh.com,rsa-sha2-512,rsa-sha2-256
HostKeyAlgorithms ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,rsa-sha2-256,rsa-sha2-512
PubkeyAcceptedKeyTypes ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,rsa-sha2-256,rsa-sha2-512


内容解析

1. 基本配置

配置项说明
HostKey/etc/ssh/ssh_host_rsa_key
/etc/ssh/ssh_host_ed25519_key
指定SSH服务使用的密钥文件(RSA和Ed25519算法)。
SyslogFacilityAUTH日志通过syslog的AUTH设施记录。
LogLevelVERBOSE日志级别为详细模式(记录更多信息)。
Protocol2仅允许SSH协议版本2(更安全)。

2. 认证与权限控制

配置项说明
PermitRootLoginyes允许root用户登录(安全建议改为noprohibit-password)。
PasswordAuthenticationyes允许密码认证(安全建议改为no,仅用密钥认证)。
PubkeyAuthenticationyes启用公钥认证。
RSAAuthenticationyes启用RSA密钥认证(旧版兼容,已逐渐被Ed25519替代)。
PermitEmptyPasswordsno禁止空密码登录。
PermitUserEnvironmentno禁止用户通过~/.ssh/environment设置环境变量。
StrictModesyes检查用户家目录和密钥文件的权限(防止权限不当泄露)。

3. 加密与算法配置

配置项说明
Ciphersaes128-ctr,aes192-ctr,...允许的加密算法(禁用弱算法如CBC模式)。
MACshmac-sha2-512,...指定消息认证码算法(禁用MD5、SHA1等弱算法)。
KexAlgorithmscurve25519-sha256,...密钥交换算法(禁用Diffie-Hellman group1等旧算法)。
HostKeyAlgorithmsssh-ed25519,...服务器主机密钥算法(禁用SSH-RSA)。

4. 功能限制

配置项说明
AllowTcpForwardingno禁止端口转发(安全限制)。
AllowAgentForwardingno禁止SSH代理转发。
GatewayPortsno禁止远程主机连接本地转发端口。
PermitTunnelno禁止创建隧道(如VPN)。
X11Forwardingno禁用X11图形界面转发。

5. 其他配置

配置项说明
Banner/etc/issue.net登录前显示自定义警告信息(通常放法律声明)。
UsePAMyes启用PAM(Pluggable Authentication Modules)认证。
GSSAPIAuthenticationyes启用GSSAPI认证(用于Kerberos等企业环境)。
ClientAliveCountMax0连接无响应时立即断开(防僵尸会话)。

安全建议

  1. 禁用密码登录(改为仅密钥认证):
    PasswordAuthentication no
    
  2. 限制root登录
    PermitRootLogin no
    
  3. 更新算法:确保使用现代算法(如Ed25519、AES-GCM)。
  4. 重启SSH服务生效
    systemctl restart sshd
    

配置文件验证

检查语法是否正确:

sshd -t

若无输出则表示配置有效。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值